Skip to content

Ruff rules ANN for type annotations - #15297

Merged
cclauss merged 1 commit into
TheAlgorithms:masterfrom
cclauss:ruff-rules-ANN
Sep 12, 2026
Merged

Ruff rules ANN for type annotations#15297
cclauss merged 1 commit into
TheAlgorithms:masterfrom
cclauss:ruff-rules-ANN

Conversation

@cclauss

@cclauss cclauss commented Sep 12, 2026

Copy link
Copy Markdown
Member

Add ruff rules for Python type hints --https://docs.astral.sh/ruff/rules/#flake8-annotations-ann

% ruff check --select=ANN --statistics

957	ANN001	missing-type-function-argument
619	ANN201	missing-return-type-undocumented-public-function
154	ANN204	missing-return-type-special-method
 89	ANN401	any-type
 86	ANN202	missing-return-type-private-function
  8	ANN002	missing-type-args
  8	ANN003	missing-type-kwargs
  4	ANN205	missing-return-type-static-method
  2	ANN206	missing-return-type-class-method
Found 1927 errors.
No fixes available (401 hidden fixes can be enabled with the `--unsafe-fixes` option).

@priya-sundaram-dev

@cclauss cclauss added the require type hints https://docs.python.org/3/library/typing.html label Sep 12, 2026
@algorithms-keeper algorithms-keeper Bot added awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files and removed require type hints https://docs.python.org/3/library/typing.html labels Sep 12, 2026
@cclauss cclauss added the require type hints https://docs.python.org/3/library/typing.html label Sep 12, 2026
@priya-sundaram-dev

Copy link
Copy Markdown
Contributor

For the umbrella rollout, I'd sequence the ANN rules by fixability rather than by count, so CI can start enforcing the easy wins immediately while the hard ones are chipped away:

Land first (mechanical, low-risk):

  • ANN204 (154, special methods) — these are __init__/__enter__/__hash__ etc. Almost all are -> None (or an obvious return); very safe, and a big visible dent.
  • ANN201 (619) — accept the unsafe -> None batch per my note in ruff rule ANN201 missing-return-type-undocumented-public-function #15296, hand-annotate the ~359 value-returning ones by directory.
  • ANN202 (86, private functions) — same treatment as ANN201 but lower blast radius since they're not public API.

Defer (need real thought, no autofix):

  • ANN001 (957, missing arg types) and ANN401 (89, Any) — no autofix, each needs a human to pick the right type. These are perfect Hacktoberfest tasks: split per top-level directory into "good first issue" PRs.

Rollout mechanic: enable the rules per-directory (or per-rule with --select) in pyproject.toml and add per-file-ignores for the not-yet-done areas, so turning ANN on doesn't wall CI behind all 957 ANN001s at once. Flip ignores off as each directory lands.

(Disclosure: I'm Priya Sundaram, an AI software agent; a human reviews my substantive work.)

@algorithms-keeper algorithms-keeper Bot removed the awaiting reviews This PR is ready to be reviewed label Sep 12, 2026
@cclauss
cclauss merged commit a11c636 into TheAlgorithms:master Sep 12, 2026
6 checks passed
@cclauss
cclauss deleted the ruff-rules-ANN branch September 12, 2026 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement This PR modified some existing files require type hints https://docs.python.org/3/library/typing.html

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants