Skip to content

Python docs drift

Rimfe parses changed .py and .pyi files without running them and records the public surface: functions and classes with typed parameters and defaults, FastAPI and Flask routes, Click and argparse options, pydantic fields and os.environ reads. A docs section that names a changed one is checked, and a stale line gets a finding with a suggested edit.

Updated

What Rimfe reads

A name without a leading underscore is public, and a name listed in __all__ is exported. Each pull request is compared fact by fact between its base and head.

SurfaceWhat is read
Public APIFunctions, classes, methods, enum members and UPPER_CASE module constants, with parameter types and defaults. self and cls are dropped. Docstrings are kept.
RoutesFastAPI decorators (@app.get, @router.post, @app.api_route(methods=...)) and Flask (@app.route(methods=...), @bp.get), with APIRouter(prefix=...) and Blueprint(url_prefix=...) applied.
CLIClick @command and @group with their @click.option and @click.argument stack: type, default, required, is_flag and help. argparse add_argument, including store_true and positionals.
ConfigFields of pydantic BaseModel, BaseSettings and RootModel classes and of TypedDict, with type and default.
Env varsos.environ["X"], os.environ.get("X", default), os.getenv and environ.setdefault, with the default read.
Packagingpyproject.toml scripts, GUI scripts, entry points and Poetry scripts as commands. Dependencies from pyproject.toml, requirements*.txt and Pipfile.
Deprecationswarnings.warn(..., DeprecationWarning) in a body and a .. deprecated:: directive in a docstring.

Example: a CLI flag is renamed

docs/cli.md tells readers to pass --output-dir build. The page now names an option the code no longer has, so Rimfe reports a Broken reference on that line. A shell snippet that uses the old flag is reported as an Outdated code sample, since flags match snippets in any language.

src/acme/cli.py
- parser.add_argument("--output-dir", default="dist")+ parser.add_argument("--out", default="dist")

Example: a settings default changes

docs/configuration.md says timeout defaults to 30 seconds. Rimfe posts a Docs conflict that quotes the page line and the changed field, with an edit that sets the value to 10.

src/acme/settings.py
 class Settings(BaseSettings):-    timeout: float = 30.0+    timeout: float = 10.0

Example: a function is deprecated

The quickstart still recommends load() with no notice. Rimfe reports an Undocumented deprecation and points at the pages that mention load. Later pull requests that add a line using load without a notice get a Deprecated name in the docs finding.

src/acme/io.py
 def load(path):+    warnings.warn("load is deprecated, use read", DeprecationWarning)     return read(path)

Docs tools beside Python

Python projects usually publish with MkDocs, often with Material, or with Sphinx. Rimfe reads .md and .rst pages as written. That means generated reference is not visible: a page holding only a mkdocstrings ::: directive or a Sphinx automodule shows Rimfe the directive, not the output. Keep defaults, flags and settings you want checked in written pages.

Set up a Python repository

Map the CLI and settings modules to the pages that describe them, so those pages are read first. surface lists env vars and flags to count in docs coverage. The file applies when Documentation scope is set to .rimfe.json at the PR base.

.rimfe.json
{  "$schema": "https://rimfe.com/schema/rimfe.json",  "docsGlobs": ["README.md", "docs/**/*.{md,rst}"],  "codeMappings": [    { "source": "src/acme/cli/**", "target": "docs/cli.md" },    { "source": "src/acme/settings.py", "target": "docs/configuration.md" }  ],  "surface": ["ACME_HOME", "--out"]}

Limits

  • Typer is not read as a CLI framework. Its commands are plain functions to Rimfe, so their parameters and defaults are compared but no --flag names come from them.
  • Django URL patterns and other routers produce no route facts. A prefix passed to include_router is not applied; one set in APIRouter(prefix=...) is.
  • Code is parsed, never run. Routes, options or settings built at runtime are not seen, and types are what the source declares.
  • Tests (tests/, test_*.py, *_test.py, conftest.py) and files whose header says they are generated, such as protobuf _pb2.py output, are skipped.

Try it on your next pull request.

Free for public repositories, with unlimited members.

Start free with GitHub