Documentation

Docs / Reference

ADR 0017 — Python implicit roots and empty FastAPI methods

Status: Accepted (developer review, 2026-10-11) Date: 2026-10-11

Context

ADR 0015's metadata roots lose absolute imports in legacy and Django-like projects without packaging metadata. Self-index lost four call sites in the nested Python fixture. The documented repository src probe is missing without repository metadata. Empty FastAPI methods collections were treated as GET.

Options considered

Decision

A directory with a scanned init.py is a top-level regular package when its parent has no scanned init.py. That parent is an implicit root. Namespace directories themselves create none. Only ancestors of the importing file apply; implicit roots never enter sibling fallback and receive no src child. A root equal to an explicit root is explicit.

Run explicit ancestor resolution deepest first, then existing sibling fallback including ambiguous_import, unchanged. Only when no candidate or ambiguity exists, try implicit ancestors deepest first, taking the first candidate. Keep regular-package/source-module/namespace probe order. Restore repository src in the documented explicit-root position when it contains scanned Python sources. Derive roots from the current inventory every link pass. Imports, calls, FastAPI objects, handlers and prefixes share one resolver. Initializer changes relink cached importers without reparsing them.

FastAPI APIRoute defaults only methods=None to GET, otherwise uses the supplied set; Starlette Route.matches restricts methods only when that set is nonempty. Missing/None methods retain GET. Literal empty [] and () emit one ANY route. set() remains a nonliteral call and produces route_dynamic_methods with no route. An ANY registration from empty methods has no OpenAPI operation in FastAPI's own specification; later OpenAPI generation must account for this difference. Offline framework sources were unavailable; these semantics follow T011e's stated library behavior.

Per-file syntax payloads do not change: roots and methods expansion are link-pass decisions. Retain extractors-10, contract v1, dependencies, store and schema.

Consequences

Legacy absolute imports gain scanned dependencies and callable edges. Explicit targets and sibling ambiguities retain priority. Empty-method route identity changes from GET to ANY intentionally, retaining the registration span/hash. Current-inventory linking preserves incremental replay.

Known gaps

Real sys.path depends on script directory, working directory and installed packages. These rules approximate launch from a top-level package's parent. Flat sibling modules outside regular packages remain external/unresolved even though executing a script there could make them importable. When repository and implicit roots both provide a candidate, the explicit repository root wins even if a project launches from the implicit root. Explicit sibling resolution and ambiguity also precede implicit ancestors to preserve the additive guarantee. The package-parent approximation can select a same-named component package instead of an installed SDK: Langflow's firecrawl component package under a namespace parent is one example. A scanned module dependency does not prove that its requested export exists; unavailable exports remain without callable edges. Launching an installed bundle with another sys.path can select the SDK.

No namespace-created roots, installed inventory, runtime execution, type inference or arbitrary method-expression evaluation is added. Postgres and cross-platform execution require CI; storage code is unchanged.

Review notes (developer, 2026-10-11)

Report a problem with this pageSource: docs/adr/0017-python-implicit-roots.md