Skip to content

Commit dd0e56e

Browse files
authored
Add support for Protocols without specific __ini__
1 parent fff09f4 commit dd0e56e

4 files changed

Lines changed: 29 additions & 2 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ deps
1212
*.py,cover
1313
junit
1414
coverage.xml
15+
.venv

rodi/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ def _get_resolvers_for_parameters(
477477
services = self.services
478478

479479
for param_name, param in params.items():
480-
if param_name == "self":
480+
if param_name in ("self", "args", "kwargs"):
481481
continue
482482

483483
param_type = param.annotation

tests/examples.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ def value(self):
9393

9494

9595
class ValueProvider(IValueProvider):
96-
9796
__slots__ = "_value"
9897

9998
def __init__(self, value):

tests/test_services.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
Iterable,
88
List,
99
Mapping,
10+
Protocol,
1011
Sequence,
1112
Tuple,
1213
Type,
@@ -2382,3 +2383,29 @@ class B:
23822383
for key, value in container:
23832384
assert key is A or key is B
23842385
assert isinstance(value, DynamicResolver)
2386+
2387+
2388+
def test_provide_protocol_generic() -> None:
2389+
T = TypeVar("T")
2390+
2391+
class P(Protocol[T]):
2392+
def foo(self, t: T) -> T:
2393+
...
2394+
2395+
class A:
2396+
...
2397+
2398+
class Impl(P[A]):
2399+
def foo(self, t: A) -> A:
2400+
return t
2401+
2402+
container = Container()
2403+
2404+
container.register(Impl)
2405+
2406+
try:
2407+
resolved = container.resolve(Impl)
2408+
except CannotResolveParameterException as e:
2409+
pytest.fail(str(e))
2410+
2411+
assert isinstance(resolved, Impl)

0 commit comments

Comments
 (0)