Skip to main content

pynudger

opennudge Python linter (naming conventions and other automated checks)

Features 🚀 Quick start 📚 Documentation 🤝 Contribute 👍 Adopters 📜 Legal


Features

pynudger is an opinionated linter for Python projects, focused on naming conventions and making your code "more Pythonic".

  • Length rules: Too long class/function names are flagged.
  • Setters/getters: Discourages usage of setters/getters, encourages properties instead.
  • No helpers/utils/commons: Incentivizes more descriptive and semantically coherent names for functionalities.

Table of contents

Quick start

Installation

[!TIP] You can use your favorite package manager like uv, hatch or pdm instead of pip.

> pip install pynudger

Usage

To check against the rules run the following from the command line:

> pynudger check

You can pass additional arguments to pynudger check, like files to check (by default all Python files in the current directory):

> pynudger check path/to/file.py another_file.py

Advanced

Configuration

You can configure pynudger in pyproject.toml (or .pynudger.toml in the root of your project, just remove the [tool.pynudger] section), for example:

[tool.pynudger]
# include rules by their code
include_codes = [1, 2, 5] # default: all rules included
# exclude rules by their code (takes precedence over include)
exclude_codes = [4, 5, 6] # default: no rules excluded
# whether to exit after first error or all errors
end_mode = "first" # default: "all"

[!TIP] Rule-specific configuration can be found in the section below.

Run as a pre-commit hook

pynudger can be used as a pre-commit hook, to add as a plugin:

repos:
-   repo: "https://github.com/open-nudge/pynudger"
    rev: ...  # select the tag or revision you want, or run `pre-commit autoupdate`
    hooks:
    -   id: "pynudger"

Disable in code

You can disable pynudger on a line-by-line basis (you have to specify exact code), e.g.:

def set_my_too_long_function_name():  # noqa: PYNUDGER0, PYNUDGER16
    pass

or a line span:

# noqa-start: PYNUDGER0, PYNUDGER16
def set_my_too_long_function_name():
    pass

def set_another_long_function():
    pass
# noqa-end: PYNUDGER0, PYNUDGER16

def set_will_error_out_this_time():
    pass

It is also possible to disable all checks in a file by placing the following somewhere in the file (preferably at the top):

# noqa-file: PYNUDGER0, PYNUDGER16

[!NOTE] If you are running pynudger with ruff you should add lint.external = ["PYNUDGER"] to [tool.ruff] section in pyproject.toml to avoid removing # noqa: PYNUDGER comments.

Rules

[!TIP] Run pynudger rules to see the list of available rules.

pynudger provides the following rules:

Name Description
PYNUDGER0 Avoid using setters in class names. Use properties instead.
PYNUDGER1 Avoid using setters in function names. Use properties instead.
PYNUDGER2 Avoid using setters in file names. Define file name without it.
PYNUDGER3 Avoid using getters in class names. Use properties instead.
PYNUDGER4 Avoid using getters in function names. Use properties instead.
PYNUDGER5 Avoid using getters in file names. Define file name without it.
PYNUDGER6 Avoid using utils in class names. Name the class appropriately.
PYNUDGER7 Avoid using utils in function names. Name the function appropriately.
PYNUDGER8 Avoid defining utils modules. Move functionality to appropriate modules.
PYNUDGER9 Avoid using helpers in class names. Name the class appropriately.
PYNUDGER10 Avoid using helpers in function names. Name the function appropriately.
PYNUDGER11 Avoid defining utils modules. Move functionality to appropriate modules.
PYNUDGER12 Avoid using common in class names. Name the class appropriately.
PYNUDGER13 Avoid using common in function names. Name the function appropriately.
PYNUDGER14 Avoid defining common modules. Move functionality to appropriate modules.
PYNUDGER15 Avoid long class names. Specify intent by nesting modules/packages.
PYNUDGER16 Avoid long function names. Specify intent by nesting modules/packages.
PYNUDGER17 Avoid long path names. Specify intent by nesting modules/packages.
PYNUDGER18 Avoid restricted state management keywords: del, global, nonlocal.
PYNUDGER19 Avoid restricted iteration keywords: break, continue.
PYNUDGER20 Avoid restricted compatibility functionality: object, basestring, unicode, long.
PYNUDGER21 Avoid restricted utility/interactive functions: breakpoint, help, id.
PYNUDGER22 Avoid restricted explicit casting functionality: typing.cast, cast, bool, float, int, str.
PYNUDGER23 Avoid restricted insecure builtin functions: exec, eval, compile.
PYNUDGER24 Avoid restricted explicit iteration: iter, aiter, anext, next.
PYNUDGER25 Avoid restricted attribute manipulation: delattr, getattr, hasattr, setattr, globals, locals, vars, dir.
PYNUDGER26 Avoid restricted explicit dunder access: attributes starting with __.
PYNUDGER27 Avoid returning empty strings. Return None to indicate lack of value.
PYNUDGER28 Avoid more than assert statements in pytest tests. Keep each test focused.
PYNUDGER29 Avoid modules with more than total lines. Split code into focused modules.
PYNUDGER30 Avoid modules with more than code lines. Split code into focused modules.
PYNUDGER31 Avoid undocumented function parameters. Add an Args: docstring section.
PYNUDGER32 Avoid undocumented generator yields. Add a Yields: docstring section.
PYNUDGER33 Avoid undocumented return values. Add a Returns: docstring section.

with the following configurable options (in pyproject.toml or .pynudger.toml):

Option Description Affected rules Default
pascal_length Maximum allowed length of PascalCase names PYNUDGER15 3
snake_length Maximum allowed length of snake_case names PYNUDGER16, PYNUDGER17 3
pascal_excludes List of words to exclude from PascalCase length check PYNUDGER15 []
snake_excludes List of words to exclude from snake_case length check PYNUDGER16, PYNUDGER17 []
maximum_test_asserts Maximum number of assert statements in pytest tests PYNUDGER28 1
max_module_lines Maximum number of any lines in a Python module PYNUDGER29 600
max_module_code_lines Maximum number of code lines in a Python module PYNUDGER30 200
dir_ignores List of (sub)directories to be excluded in case no files are provided ALL ["__pypackages__", ".venv", ".git", "__pycache__"]
extend_dir_ignores Additional (sub)directories to ignore, extending the default ignores ALL []

Contribute

We welcome your contributions! Start here:

Legal

  • This project is licensed under the Apache 2.0 License - see the LICENSE file for details.
  • This project is copyrighted by open-nudge - the appropriate copyright notice is included in each file.

Download files

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

Source Distribution

pynudger-0.8.0.tar.gz (24.0 kB view details)

Uploaded Source

Built Distribution

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

pynudger-0.8.0-py3-none-any.whl (24.1 kB view details)

Uploaded Python 3

File details

Details for the file pynudger-0.8.0.tar.gz.

File metadata

  • Download URL: pynudger-0.8.0.tar.gz
  • Upload date:
  • Size: 24.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pynudger-0.8.0.tar.gz
Algorithm Hash digest
SHA256 7129518eff0cfcdcda20b5a65b2e83d86ab025072dfb234f0f8dbc4fa481d658
MD5 542dfe08c896bad171afddddfa0a4949
BLAKE2b-256 296da9c31429798d750d6cd5596307e89355d23c3a24a95b7bec63257e098ecc

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynudger-0.8.0.tar.gz:

Publisher: release.yml on open-nudge/pynudger

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

File details

Details for the file pynudger-0.8.0-py3-none-any.whl.

File metadata

  • Download URL: pynudger-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 24.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pynudger-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3970fb81cd0eaa39e3b6591324b9ff855ff9023adca7ed37b08e6da3ce7de7d6
MD5 b6342a5b9d6ed7c34ae1f5fe7241fcc4
BLAKE2b-256 00a4585bb5e42aa0fb6e2771eb82be3f08b479d21a0bcdc116392e8fb428a954

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynudger-0.8.0-py3-none-any.whl:

Publisher: release.yml on open-nudge/pynudger

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.8.0 This release

2 files

0.4.1

2 files

0.3.0

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page