mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-05-23 05:56:19 +03:00
Do not override methods without patching (#886)
This commit is contained in:
parent
9a08bfcede
commit
dbf86e4eb4
|
@ -523,6 +523,10 @@ def _patch_method(
|
||||||
|
|
||||||
_bind_injections(fn, providers_map)
|
_bind_injections(fn, providers_map)
|
||||||
|
|
||||||
|
if fn is method:
|
||||||
|
# Hotfix, see: https://github.com/ets-labs/python-dependency-injector/issues/884
|
||||||
|
return
|
||||||
|
|
||||||
if isinstance(method, (classmethod, staticmethod)):
|
if isinstance(method, (classmethod, staticmethod)):
|
||||||
fn = type(method)(fn)
|
fn = type(method)(fn)
|
||||||
|
|
||||||
|
|
40
tests/unit/wiring/test_no_interference.py
Normal file
40
tests/unit/wiring/test_no_interference.py
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
from typing import Any, Iterator
|
||||||
|
|
||||||
|
from pytest import fixture
|
||||||
|
|
||||||
|
from dependency_injector.containers import DeclarativeContainer
|
||||||
|
from dependency_injector.providers import Object
|
||||||
|
from dependency_injector.wiring import Provide, inject
|
||||||
|
|
||||||
|
|
||||||
|
class A:
|
||||||
|
@inject
|
||||||
|
def foo(self, value: str = Provide["value"]) -> str:
|
||||||
|
return "A" + value
|
||||||
|
|
||||||
|
|
||||||
|
class B(A): ...
|
||||||
|
|
||||||
|
|
||||||
|
class C(A):
|
||||||
|
def foo(self, *args: Any, **kwargs: Any) -> str:
|
||||||
|
return "C" + super().foo()
|
||||||
|
|
||||||
|
|
||||||
|
class D(B, C): ...
|
||||||
|
|
||||||
|
|
||||||
|
class Container(DeclarativeContainer):
|
||||||
|
value = Object("X")
|
||||||
|
|
||||||
|
|
||||||
|
@fixture
|
||||||
|
def container() -> Iterator[Container]:
|
||||||
|
c = Container()
|
||||||
|
c.wire(modules=[__name__])
|
||||||
|
yield c
|
||||||
|
c.unwire()
|
||||||
|
|
||||||
|
|
||||||
|
def test_preserve_mro(container: Container) -> None:
|
||||||
|
assert D().foo() == "CAX"
|
Loading…
Reference in New Issue
Block a user