Conversation
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:
|
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR appears to be the “v4” performance/refactor update for the DI system, focusing on reducing per-resolution overhead (argument resolution, injection planning) and tightening context-scope initialization behavior.
Changes:
- Add cached argument/keyword resolution helpers and reuse precomputed “is provider” flags across multiple providers (Factory/Singleton/Resource/etc.).
- Refactor context-scope/context-resource initialization and injection context handling (including new sync injection context path).
- Make collection providers return immutable/read-only results (tuple + mappingproxy) and update docs/tests/benchmarks accordingly.
Reviewed changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| that_depends/providers/base.py | Adds shared arg/kwarg resolution helpers and scope init-order caching/invalidation for providers. |
| that_depends/providers/mixin.py | Introduces argument-registration state tracking to avoid repeated parent/child graph registration. |
| that_depends/providers/singleton.py | Uses new resolution helpers + caches provider-ness of args/kwargs; adds early instance return. |
| that_depends/providers/local_singleton.py | Same resolution/registration optimizations as Singleton, adapted to thread-local instance storage. |
| that_depends/providers/factories.py | Uses new resolution helpers + caches provider-ness of args/kwargs; avoids repeated checks. |
| that_depends/providers/context_resources.py | Refactors SupportsContext to a runtime-checkable Protocol; updates container_context provider discovery/caching; introduces sync injection context objects. |
| that_depends/providers/collection.py | Changes List/Dict providers to return immutable/read-only Sequence/Mapping views. |
| that_depends/injection.py | Adds cached injection “plan” and new sync injection stack; reworks scope context initialization setup. |
| that_depends/meta.py | Adds type->provider lookup caching; removes context-management from metaclass. |
| that_depends/container.py | Moves container context-management methods onto BaseContainer class (async/sync context entry). |
| that_depends/entities/resource_context.py | Adds helper to reset context state and uses it during teardown. |
| that_depends/experimental/providers.py | Updates LazyProvider context support handling (protocol typing + method forwarding) and adds regression coverage. |
| that_depends/integrations/faststream.py | Updates typing for SupportsContext usage and middleware cloning. |
| tests/test_meta.py | Adds coverage for explicit default_scope behavior on BaseContainerMeta. |
| tests/providers/test_context_resources.py | Updates tests for new ResourceContext state helper and default-scope behavior. |
| tests/providers/test_collections.py | Updates expectations for immutable Sequence/Mapping results and verifies immutability. |
| tests/experimental/test_container_2.py | Adds coverage for LazyProvider behavior when context method access raises AttributeError. |
| docs/providers/context-resources.md | Updates docs wording to “SupportsContext protocol”. |
| docs/providers/collections.md | Updates docs/examples to reflect immutable/read-only collection results. |
| examples/benchmark/RESULTS.md | Adds benchmark results for 4.0 vs prior versions. |
| pyproject.toml | Updates dev deps (adds pyrefly). |
| Justfile | Adds pyrefly and tweaks mypy invocation options for lint targets. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| @abstractmethod | ||
| def get_scope(self) -> ContextScope | None: | ||
| """Return the scope of the resource.""" |
There was a problem hiding this comment.
SupportsContext.get_scope() has no function body (no .../pass), which makes the module invalid Python (SyntaxError) and will break imports. Add an ellipsis body (like the other Protocol methods) to indicate it's a Protocol stub.
| """Return the scope of the resource.""" | |
| """Return the scope of the resource.""" | |
| ... |
| msg=msg, # type:ignore[unexpected-keyword] | ||
| context=context, # type:ignore[unexpected-keyword] |
There was a problem hiding this comment.
The inline mypy/pyright ignore comments use # type:ignore[...] (missing space). Type checkers generally require # type: ignore[...]; without the space the ignore may not apply and CI type-checking can fail on these keyword arguments.
| msg=msg, # type:ignore[unexpected-keyword] | |
| context=context, # type:ignore[unexpected-keyword] | |
| msg=msg, # type: ignore[unexpected-keyword] | |
| context=context, # type: ignore[unexpected-keyword] |
No description provided.