Skip to content

docs: make code examples run and fix factual errors - #260

Merged
lesnik512 merged 1 commit into
mainfrom
docs/fix-facts
Oct 3, 2026
Merged

lesnik512 merged 1 commit into
mainfrom
docs/fix-facts

Conversation

@lesnik512

Copy link
Copy Markdown
Member

Summary

Every Python block in docs/**/*.md and README.md (167 blocks) was extracted, compiled, and run in page order in a venv with the package and its extras. The blocks below failed or contradicted the source, and are fixed here. The blocks that still fail are intentional: examples that show an error being raised, placeholders (my_project, def foo(...), <YieldType>), migration-guide snippets for the old API, and the provider-overriding example that needs Postgres via testcontainers.

Changes

  • providers/context-resources.md: the quick-start container raised DefaultScopeNotDefinedError (that_depends/meta.py:34-40). Added default_scope = ContextScopes.ANY. container_context(preserve_global_context=False) and add_middleware(DIContextMiddleware) with no context items raise ValueError (context_resources.py:549). Gave the first one a container and removed the second. DIContextMiddleware has no preserve_global_context (context_resources.py:767-772). The sync-context error is RuntimeError: Context is not set. Use container_context (from running the example).
  • introduction/scopes.md: ContextScope.APP changed to ContextScopes.APP, return p to return val, and "providers" to "provides". The nested-scope example re-entered p in REQUEST, which raises InvalidContextError as the block above it says. Added the default_scope caveat.
  • integrations/fastapi.md: the middleware example passed MyContainer and no scope. It now passes MyScopedContainer, scope=ContextScopes.REQUEST, and the test in the doc passes, opening and closing the session per request. override_context is async (providers/base.py:309), so the tip uses override_context_sync/override_sync. Also fixed container_context() with no args, Container changed to MyContainer, and a missing fetch_context_item import.
  • providers/factories.md: print(msg()) and await ...provider() (factories.py:31). ContextScopes is not exported from that_depends.providers. provider_sync exists only on factories (factories.py:49), so the context example resolves a Factory. Dropped the closing sentence.
  • introduction/injection.md: override_providers_sync (container.py:180) and override_context_sync. Fixed typos.
  • introduction/generator-injection.md (_injected changed to injected), introduction/ioc-container.md (two SyntaxErrors), providers/object.md (object_provider() returned a coroutine, so the assert failed), index.md (logger was undefined), experimental/lazy.md (typing.Iterator[int]).
  • introduction/multiple-containers.md, integrations/faststream.md, integrations/litestar.md: inlined the definitions instead of importing the repo's tests package. The Litestar lifespan is typed Litestar, not fastapi.FastAPI. The Litestar test now passes: it asserted "async resource" against a datetime resource. The FastStream example ran against TestRabbitBroker.
  • README feature list, providers/resources.md intro, testing/provider-overriding.md intro, dev/contributing.md (git clone, "open to"): wording.

Checklist

  • Lint and format pass (ruff)
  • Type check passes (mypy and pyrefly)
  • Tests pass and new behavior is covered
  • Build succeeds (uv build) if packaging or build config changed
  • Docs updated if behavior or public API changed
  • Repo metadata stays consistent across the three surfaces (GitHub description, pyproject description, profile blurb) if this touches packaging

mkdocs build --strict passes.

- context-resources: add default_scope to the quick-start container, pass a
  context item where container_context/DIContextMiddleware had no arguments,
  use the real sync-context error message, list only global_context and scope
  as middleware arguments
- scopes: ContextScopes.APP, return val, nested-scope example no longer
  re-enters p in REQUEST, default_scope caveat
- fastapi: scoped middleware example uses MyScopedContainer with
  scope=REQUEST, sync override helpers, missing imports
- factories: call provider/provider_sync, import ContextScopes from
  that_depends, context example uses a Factory, drop closing sentence
- injection, generator-injection, ioc-container, object, index, lazy:
  syntax and name errors
- multiple-containers, faststream, litestar: inline definitions instead of
  importing the repo's tests package; Litestar lifespan type
- README, resources, provider-overriding, contributing: wording fixes
@codecov

codecov Bot commented Oct 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
unittests 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@lesnik512
lesnik512 merged commit b30121c into main Oct 3, 2026
18 checks passed
@lesnik512
lesnik512 deleted the docs/fix-facts branch October 3, 2026 10:06
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