-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Add type stubs for punq #15274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+98
−0
Merged
Add type stubs for punq #15274
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| punq._Empty.__init__ |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| version = "0.7.*" | ||
| upstream_repository = "https://github.com/bobthemighty/punq" | ||
|
|
||
| [tool.stubtest] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| from collections.abc import Callable | ||
| from enum import Enum | ||
| from typing import Any, Final, Generic, NamedTuple, NewType, TypeVar, overload | ||
|
|
||
| __version__: str | ||
|
|
||
| class MissingDependencyException(Exception): ... | ||
| class MissingDependencyError(MissingDependencyException): ... | ||
| class InvalidRegistrationException(Exception): ... | ||
| class InvalidRegistrationError(InvalidRegistrationException): ... | ||
| class InvalidForwardReferenceException(Exception): ... | ||
| class InvalidForwardReferenceError(InvalidForwardReferenceException): ... | ||
|
|
||
| class Scope(Enum): | ||
| transient = 0 | ||
| singleton = 1 | ||
|
|
||
| _T = TypeVar("_T", default=Any) | ||
|
|
||
| class _Registration(NamedTuple, Generic[_T]): | ||
| service: type[_T] | str | ||
| scope: Scope | ||
| builder: Callable[..., _T] | ||
| needs: dict[str, Any] # the type hints of the builder's parameters | ||
| args: dict[str, Any] # passed to builder at instantiation time | ||
|
|
||
| _Empty = NewType("_Empty", object) # a class at runtime | ||
| empty: Final[_Empty] | ||
|
|
||
| class _Registry: | ||
| def register_service_and_impl( | ||
| self, | ||
| service: type[_T] | str, | ||
| scope: Scope, | ||
| impl: type[_T], | ||
| resolve_args: dict[str, Any], # forwarded to _Registration.builder | ||
| ) -> None: ... | ||
| def register_service_and_instance(self, service: type[_T] | str, instance: _T) -> None: ... | ||
| def register_concrete_service(self, service: type | str, scope: Scope) -> None: ... | ||
| def build_context(self, key: type | str, existing: _ResolutionContext | None = None) -> _ResolutionContext: ... | ||
| def register( | ||
| self, | ||
| service: type[_T] | str, | ||
| factory: Callable[..., _T] | _Empty = ..., | ||
| instance: _T | _Empty = ..., | ||
| scope: Scope = Scope.transient, | ||
| **kwargs: Any, # forwarded to _Registration.builder | ||
| ) -> None: ... | ||
| def __getitem__(self, service: type[_T] | str) -> list[_Registration[_T]]: ... | ||
|
|
||
| class _ResolutionTarget(Generic[_T]): | ||
| service: type[_T] | str | ||
| impls: list[_Registration[_T]] | ||
| def __init__(self, key: type[_T] | str, impls: list[_Registration[_T]]) -> None: ... | ||
| def is_generic_list(self) -> bool: ... | ||
| @property | ||
| def generic_parameter(self) -> Any: ... # returns the first annotated generic parameter of the service | ||
| def next_impl(self) -> _Registration[_T]: ... | ||
|
|
||
| class _ResolutionContext: | ||
| targets: dict[type | str, _ResolutionTarget[Any]] | ||
| cache: dict[type | str, Any] # resolved objects during this resolution | ||
| service: type | str | ||
| def __init__(self, key: type | str, impls: list[_Registration[Any]]) -> None: ... | ||
| def target(self, key: type[_T] | str) -> _ResolutionTarget[_T]: ... | ||
| def has_cached(self, key: type | str) -> bool: ... | ||
| def __getitem__(self, key: type[_T] | str) -> _T: ... | ||
| def __setitem__(self, key: type[_T] | str, value: _T) -> None: ... | ||
| def all_registrations(self, service: type[_T] | str) -> list[_Registration[_T]]: ... | ||
|
|
||
| class Container: | ||
| registrations: _Registry | ||
| def __init__(self) -> None: ... | ||
| # all kwargs are forwarded to _Registration.builder | ||
| @overload | ||
| def register(self, service: type[_T] | str, *, instance: _T, **kwargs: Any) -> Container: ... | ||
| @overload | ||
| def register( | ||
| self, service: type[_T] | str, factory: Callable[..., _T] | _Empty = ..., *, scope: Scope = Scope.transient, **kwargs: Any | ||
| ) -> Container: ... | ||
| @overload | ||
| def register( | ||
| self, | ||
| service: type[_T] | str, | ||
| factory: Callable[..., _T] | _Empty = ..., | ||
| instance: _T | _Empty = ..., | ||
| scope: Scope = Scope.transient, | ||
| **kwargs: Any, | ||
| ): ... | ||
| def resolve_all(self, service: type[_T] | str, **kwargs: Any) -> list[_T]: ... | ||
| def resolve(self, service_key: type[_T] | str, **kwargs: Any) -> _T: ... | ||
| def instantiate(self, service_key: type[_T] | str, **kwargs: Any) -> _T: ... | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They're actually all eventually passed to builder, which is the main destination of all the kwargs for all the functions. I put a single comment at the top of the Container indicating this for all the functions in that class.