mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-25 11:04:01 +03:00
Fix wiring for @classmethod
This commit is contained in:
parent
467e7ec9aa
commit
2565a1eab0
|
@ -7,6 +7,10 @@ that were made in every particular version.
|
|||
From version 0.7.6 *Dependency Injector* framework strictly
|
||||
follows `Semantic versioning`_
|
||||
|
||||
Develop
|
||||
-----
|
||||
- Fix wiring for ``@classmethod``.
|
||||
|
||||
4.1.5
|
||||
-----
|
||||
- Fix Travis CI windows and MacOS builds.
|
||||
|
|
|
@ -158,7 +158,7 @@ def wire(
|
|||
if inspect.isfunction(member):
|
||||
_patch_fn(module, name, member, providers_map)
|
||||
elif inspect.isclass(member):
|
||||
for method_name, method in inspect.getmembers(member, inspect.isfunction):
|
||||
for method_name, method in inspect.getmembers(member, _is_method):
|
||||
_patch_fn(member, method_name, method, providers_map)
|
||||
|
||||
|
||||
|
@ -235,6 +235,10 @@ def _fetch_modules(package):
|
|||
return modules
|
||||
|
||||
|
||||
def _is_method(member):
|
||||
return inspect.ismethod(member) or inspect.isfunction(member)
|
||||
|
||||
|
||||
def _patch_with_injections(fn, injections):
|
||||
if inspect.iscoroutinefunction(fn):
|
||||
@functools.wraps(fn)
|
||||
|
|
|
@ -17,6 +17,14 @@ class TestClass:
|
|||
def method(self, service: Service = Provide[Container.service]):
|
||||
return service
|
||||
|
||||
@classmethod
|
||||
def class_method(cls, service: Service = Provide[Container.service]):
|
||||
return service
|
||||
|
||||
@staticmethod
|
||||
def static_method(service: Service = Provide[Container.service]):
|
||||
return service
|
||||
|
||||
|
||||
def test_function(service: Service = Provide[Container.service]):
|
||||
return service
|
||||
|
|
|
@ -61,6 +61,14 @@ class WiringTest(unittest.TestCase):
|
|||
service = test_class_object.method()
|
||||
self.assertIsInstance(service, Service)
|
||||
|
||||
def test_class_classmethod_wiring(self):
|
||||
service = module.TestClass.class_method()
|
||||
self.assertIsInstance(service, Service)
|
||||
|
||||
def test_class_staticmethod_wiring(self):
|
||||
service = module.TestClass.static_method()
|
||||
self.assertIsInstance(service, Service)
|
||||
|
||||
def test_function_wiring(self):
|
||||
service = module.test_function()
|
||||
self.assertIsInstance(service, Service)
|
||||
|
|
Loading…
Reference in New Issue
Block a user