Skip to content

Enable ruff docstring rules (D) - #3907

Draft
anth-volk wants to merge 19 commits into
masterfrom
ruff-docstrings
Draft

anth-volk wants to merge 19 commits into
masterfrom
ruff-docstrings

Conversation

@anth-volk

Copy link
Copy Markdown
Collaborator

Fixes #3906

Summary

Phase 1 step 1.8, group 4: docstrings. Stacked on #3905.

  • Docstrings: select gains D and ignores D203 and D213, keeping D211 (no blank line before a class docstring) and D212 (summary on the first line). All 1,336 findings at the base are fixed: about 1,000 docstrings added or reworded across 229 Python files, committed by area (runtime cache and libraries, rules tool and scripts, data layer, v2 services, FastAPI routes and models, Flask routes and utilities, v1 services). Existing docstrings were reworded to say what the code actually does; one test docstring said 404 where the code returns 400.
  • Code is unchanged apart from docstrings. An AST comparison with the base, ignoring docstrings, pass and ..., finds one other change, which is equivalent. In full:
    • 27 classes whose body was only pass now have a docstring instead, because PIE790 flags pass after a docstring.
    • Protocol stubs keep ... after their new docstring.
    • The disabled cache backend's get() drops its redundant return None instead of suppressing RET501.
  • Suppressions: no noqa: D… anywhere. The two validator proof fixtures for api.v2.validators-transformations-no-db get one-line docstrings rather than a per-file ignore.
  • Published schema text changes (agreed): Pydantic copies a class docstring into the model's JSON-schema description, and FastAPI copies a route docstring into the operation description. Compared with the base, with description keys removed:
    • Structure is identical: the same paths, operations, properties, types and required lists in all 234 model schemas, the FastAPI OpenAPI (every native router enabled) and the /v2/openapi.json preview.
    • Published OpenAPI: 57 component descriptions added, written for API consumers. No field or operation descriptions changed.
    • Model schemas: 128 models gained or changed their own description (127 new; EconomicImpactResult reworded).
    • Legacy spec: byte-identical. No checked-in schema snapshot needed regenerating.
  • Shared rules tool: scripts/rules is byte-identical with sim again (tool sha256 db83d5ad2aa4); sim adopts this PR's wording in Enable ruff docstring rules (D) policyengine-sim-api#779.
  • Registry: api.quality.ruff-lint now lists D.

Testing

  • pytest tests/unit tests/contract, to_refactor and the dedupe integration test (the make test set): 2,411 passed.
  • mypy (configured scope) is clean. ruff check and ruff format --check (0.15.12) are clean repo-wide.
  • Quality guards, the rules guard and the rules tool unittest pass.

🤖 Generated with Claude Code

@anth-volk
anth-volk added this pull request to stack #3888 October 13, 2026 13:29
@codecov

codecov Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 22.68041% with 75 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.35%. Comparing base (71dba65) to head (29cbf71).

Files with missing lines Patch % Lines
policyengine_api/fastapi_routes/dependencies.py 8.62% 53 Missing ⚠️
policyengine_api/runtime_cache/core.py 50.00% 14 Missing ⚠️
policyengine_api/services/v2/associations/types.py 0.00% 2 Missing ⚠️
policyengine_api/libs/user_auth.py 50.00% 1 Missing ⚠️
policyengine_api/services/household_mirroring.py 0.00% 1 Missing ⚠️
policyengine_api/services/policy_mirroring.py 0.00% 1 Missing ⚠️
policyengine_api/services/user_policy_mirroring.py 0.00% 1 Missing ⚠️
...olicyengine_api/services/v2/user_accounts/types.py 50.00% 1 Missing ⚠️
policyengine_api/worker_spm.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master    #3907       +/-   ##
===========================================
+ Coverage   47.62%   85.35%   +37.73%     
===========================================
  Files         239      255       +16     
  Lines       13425    14762     +1337     
  Branches     2318     2524      +206     
===========================================
+ Hits         6393    12600     +6207     
+ Misses       6395     1411     -4984     
- Partials      637      751      +114     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@anth-volk
anth-volk removed this pull request from stack #3888 October 13, 2026 19:26
@anth-volk
anth-volk added this pull request to stack #3917 October 13, 2026 19:26
@anth-volk
anth-volk force-pushed the ruff-docstrings branch 3 times, most recently from f9c71e0 to c14b631 Compare October 14, 2026 18:08
@anth-volk
anth-volk force-pushed the ruff-docstrings branch 8 times, most recently from 31126f6 to bfed2d6 Compare October 15, 2026 00:06
@anth-volk
anth-volk force-pushed the ruff-docstrings branch 3 times, most recently from 3d9fa59 to 90d5fe9 Compare October 15, 2026 17:21
Base automatically changed from ruff-annotations to master October 16, 2026 06:44
anth-volk and others added 19 commits October 16, 2026 11:05
Run ruff check --fix for the pydocstyle (D) rules: put summaries on the
first line, drop blank lines after function docstrings, and normalise
blank lines around sections and closing quotes. Only docstring
whitespace changes; the published OpenAPI documents and Pydantic JSON
schemas are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tests are exempt from the missing-docstring rules (D1) but not from the
style rules, so give each flagged test and fixture docstring a one-line
imperative summary followed by a blank line, describe the parameters
the numpy-style sections left out, and correct the validate_country
test class, which said 404 where the decorator returns 400.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add docstrings to the Redis-backed runtime cache (its Protocols, the
in-memory fake, claims and the household and reform-impact caches), the
observability runtime and stage plans, and the gateway client and auth
helpers. Each says what a reader cannot see from the signature: what a
miss means, when entries are rejected, and which Redis behaviour a fake
command emulates.

Adding a docstring to the fake backend's get makes RET501 report its
explicit return None, which stays and is suppressed with a reason.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add docstrings to scripts/rules (the registry model, loader, resolver,
validator and renderer), the quality-guard runner and migration guard,
the migration baseline, mirroring and smoke-test scripts, the Alembic
environments, and the .github helper scripts. Reword the rules tool's
noun-phrase function summaries into the imperative and give its
multi-line summaries a separating blank line.

scripts/rules is the canonical copy of a tool shared byte-for-byte with
policyengine-sim-api, and the argparse help taken from module
docstrings is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add docstrings to the v1 SQLAlchemy models and connection settings, the
congressional-district metadata, the v2 catalog publication records and
staging, the household and policy migration qualification, the v2
migration target settings, and the v2 SQLModel tables and their enums.

The table docstrings say what a row represents: what makes it unique,
whether it is immutable, what owns it and what is deleted with it.
Pydantic publishes a class docstring as the model's JSON-schema
description, so these tables' schemas gain descriptions; none of them is
in the published OpenAPI document.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add docstrings to the v2 resource services (households, policies,
user-households and user-policies), the metadata catalog service, and
the comparison-run, simulation and report contracts: their sessions,
database connectors, transformations, validators and types. They say
what each read returns when nothing matches, which writes are
deduplicated or idempotent, which typed errors are raised, and how the
limit + 1 over-fetch drives has_more.

Pydantic publishes class docstrings as JSON-schema descriptions. The
metadata result types appear in the published OpenAPI document, so
their docstrings are written for API consumers; the simulation and
report types are the versioned Stage 12 worker contracts, so theirs
describe what each message means to producer and consumer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add docstrings to the native route dependencies (one contract line per
Protocol method), the health, metadata and specification routers, the
v2 metadata route builders and their shared read_resource helper, and
the v2 request, document and response models and their methods.

Pydantic publishes a model's class docstring as its JSON-schema
description, so the response and document models in the OpenAPI
document now carry descriptions written for API consumers: what each
object represents, that households and policies are immutable and
deduplicated, and how to page through results. Route functions, whose
docstrings FastAPI would publish as operation descriptions, are
unchanged, and so are the documented paths and operations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add module, function and class docstrings to the Flask blueprints, the
payload validators and utilities, and the top-level application,
constants, country, SPM, migration-flag and query-parameter modules.
Reword the existing error-handler, user-profile, policy and cache-key
docstrings into one-line imperative summaries, complete the Args
sections of get_policy, set_policy and validate_country (whose entry
described the wrapper's argument instead of the decorator's), and drop
the update_user_profile promise of a 403 for auth0_id edits, which the
code never makes.

Only validator methods on the published SPM and query-parameter models
gained docstrings; their class docstrings are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add docstrings to the v1 economy, household, policy, report, simulation
and user services, their legacy-to-v2 mirroring helpers and the budget-
window cache, including their Pydantic option, result and spec models.
They say what a reader cannot see from the signature: which results are
cached and how, which writes are mirrored to v2, what None means, and
which errors are raised. Reword the existing summaries that ran on
without a blank line or past 88 columns, correct get_economic_impact,
which claimed to return a tuple, and replace the pass bodies of two
exception classes with their new docstrings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Select the pydocstyle rules (D), keeping D211 and D212 of the two
mutually exclusive pairs. Test files stay exempt from the
missing-docstring rules (D1) but follow the docstring style rules.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The two validator fixtures were the last D103 findings. The disabled
cache backend's get() now ends at its docstring instead of suppressing
RET501 on an explicit return None.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
api.quality.ruff-lint now lists D, and the rendered rules page and
AGENTS.md Rules block are regenerated for the new tool hash.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Run ruff check --fix for the pydocstyle (D) rules over the Stage 12A
sign-in and user-association code: it drops the blank line after 87
function docstrings. Only docstring whitespace changes; the published
OpenAPI documents and Pydantic JSON schemas are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SimulationRunSegments and SimulationRunProgress.to_dict get docstrings
and the mock execution helper describes its run_progress argument: the
ruff group 4 findings in the code #3916 added. The economy impact
route's docstring now also says that a computing body carries the stage
fields the Simulation Entrypoint reports.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…dded

Add docstrings to the bearer-token and Auth0 Management libraries, the
shared association helpers, and the identity, account and legacy-
reference services with their sessions, connectors, validators and
types: 67 ruff group 4 findings in the code #3891 added. They say what
the signature cannot: when a principal's user is provisioned and when a
read leaves it absent, which typed errors are raised, how concurrent
first sign-ins and lost provisioning races resolve, and what deleting an
account removes in v2 and in Auth0.

Two existing summaries become imperative (D401) with the same meaning.
AccountUpdateInput's new class docstring does not reach the published
OpenAPI document, whose AccountPatchRequest keeps its own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add docstrings to the user-household, user-policy, user-report and
user-simulation services, sessions, connectors, transformations,
validators and types: 88 ruff group 4 findings in the code #3891 added.
They say that every operation acts for the session principal, that
reads never provision a signed-out browser's user, which v1 references
are checked before the v2 transaction, how a legacy id repoints an
association to the v2 copy of a v1 record, and which typed errors are
raised.

Docstrings the stack added before #3891 changed this code now match it:
row reads are owner-scoped, list filters include the legacy ids, and
updates can repoint the association.

The report provision, calibration, scorecard and validation models are
request-body models, so their class docstrings become component
descriptions in the published OpenAPI document; its structure is
unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add docstrings to the account, user-report and user-simulation response
models, the new route-dependency Protocol methods and the authentication
error: 60 ruff group 4 findings in the code #3891 added. Response
classes whose body was pass now hold their docstring instead.

Pydantic publishes a model's class docstring as its JSON-schema
description, so 34 /v2 OpenAPI components gain descriptions written for
API consumers; no path, operation or schema structure changes, and no
route function gained a docstring.

The user-policy and user-household Protocol lines now say that each
operation acts for the caller, that a policy patch can repoint the
association through legacy_policy_id, and that a household is repointed
through legacy_household_id rather than household_id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
UserType and the user-association migration qualification get
docstrings: 6 ruff group 4 findings in the code #3891 added. The saved
household and policy tables now say they link a v2 record or a v1
legacy id, and the user table says that a standard user always has a
primary country and that its sign-in identities are deleted with it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The api.v2.user-services-no-sql fixtures that #3891 added get one-line
docstrings, and two Stage 12A integration-test helpers get imperative
summaries (D401): the last 4 ruff group 4 findings in the code #3891
added.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch was successfully deployed

1 active deployment
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.

Enable ruff docstring rules (D)

1 participant