Skip to main content

Build Status Coverage pre-commit.ci status

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!

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.21.1
    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-lint comment (analogous to # noqa in flake8);

as well as the following command-line arguments:

  • --max-line-length to control the maximum line length used by pycodestyle;
  • --no-pycodestyle if you don't want the pycodestyle checks;
  • --ban-relative-imports if you want to ban relative imports;
  • --ignore if you want to ignore some specific pycodestyle checks;
  • --files to pass a Regex pattern with which to match files to include;
  • --exclude to 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
  • pycodestyle nitpicks (which you can turn off with --no-pycodestyle)
  • repeated element in set
  • .strip, .rstrip, or .lstrip used 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 black formatter does)

More to come! Requests welcome!

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cython_lint-0.21.1.tar.gz (30.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cython_lint-0.21.1-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file cython_lint-0.21.1.tar.gz.

File metadata

  • Download URL: cython_lint-0.21.1.tar.gz
  • Upload date:
  • Size: 30.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for cython_lint-0.21.1.tar.gz
Algorithm Hash digest
SHA256 bfacc75ce47b6631fd3c7a570b6918cea37e679c71407c9e1249e3a949f9100f
MD5 5945e4857185d583b7aa42ea6f14ae43
BLAKE2b-256 321a29aa1e57639bb54a45803e85fbb7f8603e2f490dfb4568cdebf04a70929e

See more details on using hashes here.

Provenance

The following attestation bundles were made for cython_lint-0.21.1.tar.gz:

Publisher: publish_to_pypi.yml on MarcoGorelli/cython-lint

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cython_lint-0.21.1-py3-none-any.whl.

File metadata

  • Download URL: cython_lint-0.21.1-py3-none-any.whl
  • Upload date:
  • Size: 15.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for cython_lint-0.21.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8a161e6f81e6477d74ce3fa63c564ce4c63104e001ababb98ad6b053cd1d5152
MD5 134f06c51e38f6aef3afd29df7b40c3f
BLAKE2b-256 6aa89b45ca296632584a450ae2f7d37ec9d1268846451df6e5587905dd8d02a8

See more details on using hashes here.

Provenance

The following attestation bundles were made for cython_lint-0.21.1-py3-none-any.whl:

Publisher: publish_to_pypi.yml on MarcoGorelli/cython-lint

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.21.1 This release

2 files

0.21.0

2 files

0.20.0

2 files

0.19.0

2 files

0.18.1

2 files

0.18.0

2 files

0.17.0

2 files

0.16.7

2 files

0.16.6

2 files

0.16.5

2 files

0.16.4

2 files

0.16.3

2 files

0.16.2

2 files

0.16.1

2 files

0.16.0

2 files

0.15.0

2 files

0.14.2

2 files

0.14.0

2 files

0.13.0

2 files

0.12.5

2 files

0.12.4

2 files

0.12.3

2 files

0.12.2

2 files

0.12.1

2 files

0.12.0

2 files

0.11.1

2 files

0.11.0

2 files

0.10.1

2 files

0.10.0

2 files

0.9.1

2 files

0.9.0

2 files

0.8.1

2 files

0.8.0

2 files

0.7.2

2 files

0.7.0

2 files

0.6.4

2 files

0.6.3

2 files

0.6.2

2 files

0.6.1

2 files

0.6.0

2 files

0.5.1

2 files

0.4.0

2 files

0.3.1

2 files

0.3.0

2 files

0.2.1

2 files

0.2.0

2 files

0.1.10

2 files

0.1.9

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page