falconry / falconry/falcon

Migrate to "pure Python" Cython mode where applicable

Open
#2,189 3 comments 0 reactions 0 assignees View on GitHub
maintenance
Dominant language
Python
Stars
9.8k
Forks
1k
Avg merge
5d 13h
Merged PRs (30d)
7

Description

As of Cython 3.0+, it is possible to write most of the [Cython code as pure Python](https://cython.readthedocs.io/en/latest/src/tutorial/pure.html), leveraging decorators and type annotations to convey the desired C compilation behaviour.

This would require `cython` at runtime, but we can shim only the annotations in order to avoid a hard dependency. @CaselIT has already implemented a prototype in this vein for SQLAlchemy.

We might want to keep `.pyx` for some tight-knit C character loops used for parsing parameters, but, for instance, multipart stream reader is mostly about typing with `Py_ssize_t`, and calling internal helpers in C, so we should be able to easily rewrite it in such mixed mode.

The main benefit is obviously that we don't need to maintain two different codebases for the same thing. Also, even if we keep dual implementations, we would be able to easily test implementation in pure Python unit tests, tracking coverage.

Contributor guide

Open the contributing guide

Research direction

Start by inventorying the existing .pyx modules and reviewing the multipart stream reader, while identifying the tight parsing loops that should remain in .pyx. Consult Cython's pure-Python mode documentation and the SQLAlchemy prototype for the annotation shim approach. Done means applicable Cython code has one maintainable implementation and can be exercised by pure-Python unit tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.