Skip to content

v4#210

Open
xelandernt wants to merge 9 commits intomainfrom
v4
Open

v4#210
xelandernt wants to merge 9 commits intomainfrom
v4

Conversation

@xelandernt
Copy link
Copy Markdown
Collaborator

No description provided.

@xelandernt xelandernt self-assigned this Apr 20, 2026
@xelandernt xelandernt added the enhancement New feature or request label Apr 20, 2026
@xelandernt xelandernt added this to the 4.0.0 milestone Apr 20, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

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

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

Files with missing lines Coverage Δ
tests/experimental/test_container_2.py 100.00% <100.00%> (ø)
tests/providers/test_attr_getter.py 100.00% <100.00%> (ø)
tests/providers/test_base.py 100.00% <100.00%> (ø)
tests/providers/test_collections.py 100.00% <100.00%> (ø)
tests/providers/test_context_resources.py 100.00% <100.00%> (ø)
tests/providers/test_local_singleton.py 100.00% <100.00%> (ø)
tests/providers/test_singleton.py 100.00% <100.00%> (ø)
tests/test_injection.py 100.00% <100.00%> (ø)
tests/test_meta.py 100.00% <100.00%> (ø)
that_depends/container.py 100.00% <100.00%> (ø)
... and 12 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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."""
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
"""Return the scope of the resource."""
"""Return the scope of the resource."""
...

Copilot uses AI. Check for mistakes.
Comment on lines +82 to +83
msg=msg, # type:ignore[unexpected-keyword]
context=context, # type:ignore[unexpected-keyword]
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
msg=msg, # type:ignore[unexpected-keyword]
context=context, # type:ignore[unexpected-keyword]
msg=msg, # type: ignore[unexpected-keyword]
context=context, # type: ignore[unexpected-keyword]

Copilot uses AI. Check for mistakes.
Comment thread that_depends/providers/base.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants