Skip to content

Lint all Python files with ruff#2138

Open
bboe wants to merge 25 commits into
mainfrom
lint-all-python-files
Open

Lint all Python files with ruff#2138
bboe wants to merge 25 commits into
mainfrom
lint-all-python-files

Conversation

@bboe

@bboe bboe commented Jun 10, 2026

Copy link
Copy Markdown
Member

Switches ruff's include to the idiomatic ["*.py"] so the entire repository is linted — previously only praw/ source was (via a malformed praw/**.py glob), leaving tests, tools/, docs/, and pre_push.py unlinted.

Why

include = ["praw/**.py"] scoped ruff to package source only; tests/tooling were never linted. Bare *.py is ruff's own default idiom and relies on the default exclude (build/dist/.tox/.venv/…) + gitignore to skip artifacts.

Changes

  • [tool.ruff] include["*.py"]
  • Drop the redundant files: ^(praw/.*.py)$ filter on the ruff pre-commit hook
  • Curated per-file-ignores for non-library code (tests, tools/, docs/examples/, pre_push.py, docs/conf.py). The package source is already clean and unaffected. The dominant test violation was PLR6301 (no-self-use), a preview rule that fires on every class-based pytest method — relaxed rather than churning the suite into staticmethods.
  • Safe ruff autofixes applied to newly-covered files (open()Path().open(), dict.fromkeys, etc. — all behavior-preserving)

Verification

ruff check . clean; full test suite green (1002 passed, 1 skipped).

bboe added 24 commits June 10, 2026 16:20
Replace the source-only `include` (`praw/**.py`, a malformed glob) with the
ruff-idiomatic `["*.py"]` so tests, examples, maintenance scripts, and docs are
linted too, relying on ruff's default `exclude` and gitignore handling to keep
build artifacts out. Drop the redundant `files:` filter on the ruff pre-commit
hook so the hook and `ruff check .` lint the same set.

Non-library code (tests, `tools/`, `docs/examples/`, `pre_push.py`, the Sphinx
config) is not held to the package source's docstring/annotation/style
strictness, so each group gets a curated per-file-ignore — most notably tests,
where the dominant violation was PLR6301 (no-self-use) firing on every pytest
method. Apply ruff's safe autofixes to the newly-covered files.
- Fix the mis-anchored `name-tests-test` `files` regex (the `|` split it into
  two half-anchored alternatives); use `^tests/(integration|unit)/.*\.py$`.
- Run docstrfmt with `require_serial` for parity with prawcore.
- Enforce `--fail-under=100` in the coverage tox env.
Adopt ruff's formatter (already used by prawcore/asyncprawcore) so Python code
formatting is enforced. Reformat the codebase under `line-length = 120`; all
changes are cosmetic and behavior-preserving, and ruff-format, docstrfmt, and
auto-walrus are mutually stable.
Replace the explicit `select` list with `select = ["ALL"]` so the linter is
opt-out rather than opt-in, matching prawcore/asyncprawcore. Because
`preview = true`, ALL also pulls in preview rules; ignore the ones that don't fit
praw's conventions: copyright headers (CPY001), pydoclint-style return/yield/
raise documentation (DOC201/DOC402/DOC501), the formatter conflicts (COM812,
ISC001), the complexity metric (C901), and the FURB101/PERF micro-optimizations
(left as follow-ups). Safe autofixes applied a few simplifications (e.g.
`x if x else ""` -> `x or ""`).
Fix the PERF/FURB101 violations that were ignored as follow-ups when select=
["ALL"] was adopted, and drop those rules from the ignore list: use list.extend/
dict.update/dict comprehensions (PERF401/PERF403), iterate dict values directly
(PERF102), and read files via Path.read_text/read_bytes (FURB101). Only the
genuinely-permanent ignores remain (C901 complexity, PERF203 per-iteration
try/except).
hatchling does not derive the package description from the module docstring, so
the built distributions shipped with an empty Summary. Declare it statically.
Bump the pinned ruff pre-commit hook to v0.15.17 and raise the development tool
version floors (ruff, pyright, pytest, coverage, vcrpy, tox-uv) to their latest
releases, refreshing uv.lock to match.
MANIFEST.in is a setuptools-only mechanism; the hatchling build backend ignores
it entirely (it was even being shipped into the sdist as ordinary content). The
sdist contents are unchanged by its removal.
Prevents the untracked agent-config directory from leaking into a sdist built
from a dirty working tree.
Add the @abstract exclusion so [tool.coverage.report] matches the other projects.
Use Read the Docs' canonical configuration filename, matching prawcore and
async-prawcore.
Switch the mixed-line-ending hook from --fix=no (check only) to --fix=lf so it
actively normalizes all text files to LF.
Use a single shared ignore list (the union of the previous per-project entries)
so all four projects ignore the same set of editor, tooling, and build
artifacts.
Add [tool.pytest.ini_options] with testpaths = "tests" so a bare pytest run only
collects from the tests directory, matching the other projects.
Add [tool.tomlsort] sort_table_keys = true so the toml-sort hook sorts the keys
within every table, not just the tables themselves. The files were already
key-sorted, so this only makes the enforcement explicit and keeps it consistent
going forward; order-sensitive arrays (tox commands, ignore lists) are left
untouched.
Enable [tool.tomlsort] sort_inline_tables so the author and maintainer
inline-table keys are sorted.
- Delete the vestigial pre_push.py (superseded by tox) and the unused profile_tests.sh, and point the CONTRIBUTING docs at `uv run tox`.

- Normalize dependency version specifier spacing in pyproject.toml.

- Refresh uv.lock.
prawcore is making Requestor's parameters keyword-only; pass them by
name so the call keeps working.
prawcore is making authorize_url's parameters keyword-only; pass them by
name so the call keeps working.
@bboe bboe force-pushed the lint-all-python-files branch from 9f62e67 to 84ceed3 Compare June 12, 2026 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant