cython-lint

Lint Cython files

55 个版本 Python >=3.10
安装
pip install cython-lint
poetry add cython-lint
pipenv install cython-lint
conda install cython-lint
描述

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.20.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-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
  • 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!

版本列表
0.20.0 2026-06-18
0.19.0 2026-02-01
0.18.1 2025-10-19
0.18.0 2025-10-14
0.17.0 2025-10-03
0.16.7 2025-07-04
0.16.6 2024-11-10
0.16.5 2024-11-10
0.16.4 2024-11-10
0.16.3 2024-11-10
0.16.2 2024-04-15
0.16.1 2024-04-15
0.16.0 2023-11-26
0.15.0 2023-04-03
0.14.2 2023-04-02
0.14.0 2023-03-15
0.13.0 2023-03-07
0.12.5 2023-02-27
0.12.4 2023-02-05
0.12.3 2023-02-04
0.12.2 2023-02-03
0.12.1 2023-02-03
0.12.0 2023-02-02
0.11.1 2023-01-30
0.11.0 2023-01-29
0.10.1 2022-12-24
0.10.0 2022-12-19
0.9.1 2022-11-24
0.9.0 2022-11-24
0.8.1 2022-11-17
0.8.0 2022-11-17
0.7.2 2022-11-11
0.7.0 2022-11-10
0.6.4 2022-11-09
0.6.3 2022-11-09
0.6.2 2022-11-09
0.6.1 2022-11-09
0.6.0 2022-11-09
0.5.1 2022-11-08
0.4.0 2022-11-06
0.3.1 2022-11-05
0.3.0 2022-11-04
0.2.1 2022-10-31
0.2.0 2022-10-30
0.1.10 2022-10-12
0.1.9 2022-10-12
0.1.8 2022-09-28
0.1.7 2022-09-24
0.1.6 2022-09-12
0.1.5 2022-09-11
0.1.4 2022-09-03
0.1.3 2022-08-29
0.1.2 2022-08-28
0.1.1 2022-08-28
0.1.0 2022-08-28