cython-lint
Everything flake8 used to do (by accident), plus much more.
A tool and pre-commit hook to lint Cython files.
Used by
Here's some major projects using cython-lint - is yours missing? Feel free to open a pull request!
- arrow-adbc
- ansible-pylibssh
- arrow
- CuPy
- dpctl
- frozenlist
- mkl_fft
- mkl-service
- NumPy
- open library
- pandas
- pymatgen
- PyRFC
- RAPIDS cuspatial
- RAPIDS cudf
- RAPIDS Memory Manager
- sagemath/sage
- scikit-image
- scikit-learn
- scipy
- spaCy
- yarl
- yt
Installation
$ pip install cython-lint
Usage as a pre-commit hook
See pre-commit for instructions
Sample .pre-commit-config.yaml:
- repo: https://github.com/MarcoGorelli/cython-lint
rev: v0.22.0
hooks:
- id: cython-lint
- id: double-quote-cython-strings
Command-line example
$ cython-lint my_file_1.pyx my_file_2.pyx
my_file_1.pyx:54:5: 'get_conversion_factor' imported but unused
my_file_2.pyx:1112:38: 'mod' defined but unused (try prefixing with underscore?)
my_file_3.pyx:4:9: dangerous default value!
my_file_3.pyx:5:9: comma after base type in definition
Configuration
The following configuration options are available:
- exclude lines by including a
# no-cython-lintcomment (analogous to# noqainflake8);
as well as the following command-line arguments:
--max-line-lengthto control the maximum line length used by pycodestyle;--no-pycodestyleif you don't want the pycodestyle checks;--ban-relative-importsif you want to ban relative imports;--ignoreif you want to ignore some specific pycodestyle checks;--filesto pass a Regex pattern with which to match files to include;--excludeto pass a Regex pattern with which to match files to exclude.
Configuration can be set project-wide in a .cython-lint.toml or pyproject.toml file
at the root of the project. Here's an example:
[tool.cython-lint]
max-line-length = 88
ignore = ['E503', 'E504']
exclude = 'my_project/excluded_cython_file.pyx'
Which checks are implemented?
- assert statement with tuple condition (always true...)
- comma after base type definition (e.g.
cdef ndarray, arr) - comparison between constants
- dangerous default value
- dict key repeated
- dict key variable repeated
- f-string without placeholders
- if-statement with tuple condition (always true...)
- late-binding closures https://docs.python-guide.org/writing/gotchas/#late-binding-closures
- loop control variable 'i' not used within the loop body (if this is intended, start the name with an underscore)
- outer loop variable name overwritten by inner loop variable name
- pointless string statement
pycodestylenitpicks (which you can turn off with--no-pycodestyle)- repeated element in set
.strip,.rstrip, or.lstripused with repeated characters- unnecessary list index lookup
- unnecessary import alias
- variable defined but unused
- variable imported but unused
- unnecessary
list/set/dict+ generator (just use a comprehension)
In addition, the following automated fixers are implemented:
- double-quote-cython-strings (replace single quotes with double quotes, like the
blackformatter does)
More to come! Requests welcome!
Metadata
Release files for cython-lint 0.22.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| cython_lint-0.22.0.tar.gz | 32.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cython_lint-0.22.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 49.4 kB
Release files / cython_lint-0.22.0.tar.gz
| Download URL | cython_lint-0.22.0.tar.gz |
|---|---|
| Size | 32.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ec1f536fbd9d420de48700c36942603bf1918d38b9136ea2ae905443f1e8ea10
|
|
BLAKE2b-256 checksum How to use checksums |
31d5893dc09b9512861789902d1eb05644e3267c422225beede3ff2a6be44e93
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 7, 2026.
Transparency logRelease files / cython_lint-0.22.0-py3-none-any.whl
| Download URL | cython_lint-0.22.0-py3-none-any.whl |
|---|---|
| Size | 16.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b9cf60e92cccc33d14bc7b00be3c50c85136f8f2b0a7f5345f876c17ed3f0f16
|
|
BLAKE2b-256 checksum How to use checksums |
a4a1b9998246e5b48549d0967b471dd204b01eb2b2818165b85e01de3c6bc340
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 7, 2026.
Transparency log