{"id":5168,"library":"cython-lint","title":"Cython Lint","description":"cython-lint is a powerful static analysis tool and pre-commit hook designed to lint Cython files. It extends the capabilities typically found in Python linters like flake8 to the Cython language, helping developers maintain code quality and catch common pitfalls. The current version is 0.19.0, with a release cadence of several minor versions per year.","status":"active","version":"0.19.0","language":"en","source_language":"en","source_url":"https://github.com/MarcoGorelli/cython-lint","tags":["linting","cython","static analysis","code quality","pre-commit"],"install":[{"cmd":"pip install cython-lint","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required for parsing Cython `.pyx` files to perform linting checks.","package":"Cython","optional":false},{"reason":"Integrated for Python style (PEP 8) checks within Cython files, enabled by default.","package":"pycodestyle","optional":false}],"imports":[{"note":"cython-lint is designed for command-line use; a stable, public Python API for direct programmatic linting of arbitrary code is not widely documented or intended for general use.","symbol":"cython_lint","correct":"Usage is primarily via the command-line interface or as a pre-commit hook."}],"quickstart":{"code":"echo \"def foo():\\n    x = 1 # unused variable\\n    if (1,): pass # always true tuple condition\\n    l = []\\n    l.append(1)\" > my_module.pyx\ncython-lint my_module.pyx\n","lang":"bash","description":"To quickly lint a Cython file from the command line, create a `.pyx` file and run `cython-lint` against it. This example demonstrates detection of an unused variable and an 'always true' tuple condition."},"warnings":[{"fix":"Remove the unused variable, function, or import, or prefix unused variables with an underscore (e.g., `_x`) to signal intentional non-use.","message":"cython-lint flags unused variables and imports. Messages like ''variable defined but unused'' or ''imported but unused'' indicate code that can be cleaned up, similar to Python linters.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Use immutable default values (e.g., `None`) and initialize mutable objects inside the function body (e.g., `arg = [] if arg is None else arg`).","message":"Dangerous mutable default values in function arguments are flagged (e.g., `def func(arg=[]):`). This common Python footgun extends to Cython functions.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Use the `--no-pycodestyle` command-line flag or configure `no-pycodestyle = true` in `.cython-lint.toml` or `pyproject.toml` to disable `pycodestyle` checks.","message":"By default, cython-lint includes `pycodestyle` checks, which may report Python-specific style issues. If these are not desired, they can be disabled.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure your environment uses Python 3.10 or a newer compatible version.","message":"cython-lint requires Python 3.10 or newer. Attempting to install or run on older Python versions will result in an installation or runtime error.","severity":"breaking","affected_versions":"All versions >= 0.1.0"},{"fix":"Prefer absolute imports over relative imports. If necessary, enable the `--ban-relative-imports` flag to prevent them, or refactor your module structure.","message":"Relative imports can lead to complex module resolution issues in Python and Cython. `cython-lint` introduced a `--ban-relative-imports` flag in v0.17.0 to help enforce absolute imports.","severity":"gotcha","affected_versions":"v0.17.0 and later"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}