Skip to content

Commit a4a0e45

Browse files
author
Abraham Murciano
committed
Add type stubs for punq
punq is an IOC (Inversion of Control) Container for Python 3.8+
1 parent ce2b37d commit a4a0e45

3 files changed

Lines changed: 80 additions & 0 deletions

File tree

pyrightconfig.stricter.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"stubs/protobuf",
7575
"stubs/psutil/psutil/__init__.pyi",
7676
"stubs/psycopg2",
77+
"stubs/punq",
7778
"stubs/pyasn1",
7879
"stubs/pycurl",
7980
"stubs/Pygments",

stubs/punq/METADATA.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
version = "0.7.*"
2+
upstream_repository = "https://github.com/bobthemighty/punq"
3+
4+
[tool.stubtest]

stubs/punq/punq/__init__.pyi

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
from collections.abc import Callable
2+
from enum import Enum
3+
from typing import Any, Generic, NamedTuple, TypeVar, overload
4+
5+
__version__: str
6+
7+
class MissingDependencyException(Exception): ...
8+
class MissingDependencyError(MissingDependencyException): ...
9+
class InvalidRegistrationException(Exception): ...
10+
class InvalidRegistrationError(InvalidRegistrationException): ...
11+
class InvalidForwardReferenceException(Exception): ...
12+
class InvalidForwardReferenceError(InvalidForwardReferenceException): ...
13+
14+
class Scope(Enum):
15+
transient = 0
16+
singleton = 1
17+
18+
_T = TypeVar("_T")
19+
_TOpt = TypeVar("_TOpt", default=object)
20+
21+
class _Registration(NamedTuple, Generic[_T]):
22+
service: type[_T] | str
23+
scope: Scope
24+
builder: Callable[[], _T]
25+
needs: dict[str, object]
26+
args: dict[str, object]
27+
28+
class _Empty: ...
29+
30+
empty: _Empty
31+
32+
class _Registry:
33+
def register_service_and_impl(
34+
self, service: type | str, scope: Scope, impl: Callable[..., object], resolve_args: dict[str, object]
35+
) -> None: ...
36+
def register_service_and_instance(self, service: type[_T] | str, instance: _T) -> None: ...
37+
def register_concrete_service(self, service: type | str, scope: Scope) -> None: ...
38+
def build_context(self, key: type | str, existing: _ResolutionContext | None = None) -> _ResolutionContext: ...
39+
def register(
40+
self, service: type[_T] | str, factory: Callable[..., _T] = ..., instance: _T = ..., scope: Scope = ..., **kwargs: object
41+
) -> None: ...
42+
def __getitem__(self, service: type[_T] | str) -> list[_Registration[_T]]: ...
43+
44+
class _ResolutionTarget(Generic[_T]):
45+
service: type[_T] | str
46+
impls: list[_Registration[_T]]
47+
def __init__(self, key: type[_T] | str, impls: list[_Registration[_T]]) -> None: ...
48+
def is_generic_list(self) -> bool: ...
49+
@property
50+
def generic_parameter(self) -> Any: ...
51+
def next_impl(self) -> _Registration[_T]: ...
52+
53+
class _ResolutionContext:
54+
targets: dict[type | str, _ResolutionTarget[object]]
55+
cache: dict[type | str, object]
56+
service: type | str
57+
def __init__(self, key: type | str, impls: list[_Registration[object]]) -> None: ...
58+
def target(self, key: type[_T] | str) -> _ResolutionTarget[_T]: ...
59+
def has_cached(self, key: type | str) -> bool: ...
60+
def __getitem__(self, key: type | str) -> object: ...
61+
def __setitem__(self, key: type | str, value: object) -> None: ...
62+
def all_registrations(self, service: type[_T] | str) -> list[_Registration[_T]]: ...
63+
64+
class Container:
65+
registrations: _Registry
66+
def __init__(self) -> None: ...
67+
@overload
68+
def register(self, service: type[_TOpt] | str, *, instance: _TOpt, **kwargs: Any) -> Container: ...
69+
@overload
70+
def register(
71+
self, service: type[_TOpt] | str, factory: Callable[..., _TOpt] = ..., *, scope: Scope = ..., **kwargs: Any
72+
) -> Container: ...
73+
def resolve_all(self, service: type[_TOpt] | str, **kwargs: Any) -> list[_TOpt]: ...
74+
def resolve(self, service_key: type[_TOpt] | str, **kwargs: Any) -> _TOpt: ...
75+
def instantiate(self, service_key: type[_TOpt] | str, **kwargs: Any) -> _TOpt: ...

0 commit comments

Comments
 (0)