Skip to content

Commit dbf86e4

Browse files
authored
Do not override methods without patching (#886)
1 parent 9a08bfc commit dbf86e4

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/dependency_injector/wiring.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,10 @@ def _patch_method(
523523

524524
_bind_injections(fn, providers_map)
525525

526+
if fn is method:
527+
# Hotfix, see: https://github.com/ets-labs/python-dependency-injector/issues/884
528+
return
529+
526530
if isinstance(method, (classmethod, staticmethod)):
527531
fn = type(method)(fn)
528532

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from typing import Any, Iterator
2+
3+
from pytest import fixture
4+
5+
from dependency_injector.containers import DeclarativeContainer
6+
from dependency_injector.providers import Object
7+
from dependency_injector.wiring import Provide, inject
8+
9+
10+
class A:
11+
@inject
12+
def foo(self, value: str = Provide["value"]) -> str:
13+
return "A" + value
14+
15+
16+
class B(A): ...
17+
18+
19+
class C(A):
20+
def foo(self, *args: Any, **kwargs: Any) -> str:
21+
return "C" + super().foo()
22+
23+
24+
class D(B, C): ...
25+
26+
27+
class Container(DeclarativeContainer):
28+
value = Object("X")
29+
30+
31+
@fixture
32+
def container() -> Iterator[Container]:
33+
c = Container()
34+
c.wire(modules=[__name__])
35+
yield c
36+
c.unwire()
37+
38+
39+
def test_preserve_mro(container: Container) -> None:
40+
assert D().foo() == "CAX"

0 commit comments

Comments
 (0)