docs: make code examples run and fix factual errors - #260
Merged
Merged
Conversation
- 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 Report✅ All modified and coverable lines are covered by tests.
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Every Python block in
docs/**/*.mdandREADME.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 raisedDefaultScopeNotDefinedError(that_depends/meta.py:34-40). Addeddefault_scope = ContextScopes.ANY.container_context(preserve_global_context=False)andadd_middleware(DIContextMiddleware)with no context items raiseValueError(context_resources.py:549). Gave the first one a container and removed the second.DIContextMiddlewarehas nopreserve_global_context(context_resources.py:767-772). The sync-context error isRuntimeError: Context is not set. Use container_context(from running the example).introduction/scopes.md:ContextScope.APPchanged toContextScopes.APP,return ptoreturn val, and "providers" to "provides". The nested-scope example re-enteredpinREQUEST, which raisesInvalidContextErroras the block above it says. Added thedefault_scopecaveat.integrations/fastapi.md: the middleware example passedMyContainerand no scope. It now passesMyScopedContainer, scope=ContextScopes.REQUEST, and the test in the doc passes, opening and closing the session per request.override_contextis async (providers/base.py:309), so the tip usesoverride_context_sync/override_sync. Also fixedcontainer_context()with no args,Containerchanged toMyContainer, and a missingfetch_context_itemimport.providers/factories.md:print(msg())andawait ...provider()(factories.py:31).ContextScopesis not exported fromthat_depends.providers.provider_syncexists only on factories (factories.py:49), so the context example resolves aFactory. Dropped the closing sentence.introduction/injection.md:override_providers_sync(container.py:180) andoverride_context_sync. Fixed typos.introduction/generator-injection.md(_injectedchanged toinjected),introduction/ioc-container.md(two SyntaxErrors),providers/object.md(object_provider()returned a coroutine, so the assert failed),index.md(loggerwas 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'stestspackage. The Litestar lifespan is typedLitestar, notfastapi.FastAPI. The Litestar test now passes: it asserted"async resource"against a datetime resource. The FastStream example ran againstTestRabbitBroker.providers/resources.mdintro,testing/provider-overriding.mdintro,dev/contributing.md(git clone, "open to"): wording.Checklist
ruff)mypyandpyrefly)uv build) if packaging or build config changeddescription, profile blurb) if this touches packagingmkdocs build --strictpasses.