mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-25 19:14:00 +03:00
Fix a Python 3.9 GenericAlias introspection bug, issue #362
This commit is contained in:
parent
2ced67d52b
commit
4991c5d4b0
|
@ -7,6 +7,14 @@ that were made in every particular version.
|
||||||
From version 0.7.6 *Dependency Injector* framework strictly
|
From version 0.7.6 *Dependency Injector* framework strictly
|
||||||
follows `Semantic versioning`_
|
follows `Semantic versioning`_
|
||||||
|
|
||||||
|
Development version
|
||||||
|
-------------------
|
||||||
|
- Fix a Python 3.9 specific bug in ``wiring`` module: introspection doesn't work for
|
||||||
|
builtin ``types.GenericAlias``. This resulted in wiring failure for modules
|
||||||
|
importing ``queue.Queue``.
|
||||||
|
See issue `#362 <https://github.com/ets-labs/python-dependency-injector/issues/362>`_.
|
||||||
|
Thanks `@ventaquil <https://github.com/ventaquil>`_ for the bug report.
|
||||||
|
|
||||||
4.10.0
|
4.10.0
|
||||||
------
|
------
|
||||||
- Add ``strict`` mode and ``required`` modifier for ``Configuration`` provider.
|
- Add ``strict`` mode and ``required`` modifier for ``Configuration`` provider.
|
||||||
|
|
|
@ -28,6 +28,12 @@ else:
|
||||||
class GenericMeta(type):
|
class GenericMeta(type):
|
||||||
...
|
...
|
||||||
|
|
||||||
|
# Hotfix, see: https://github.com/ets-labs/python-dependency-injector/issues/362
|
||||||
|
if sys.version_info >= (3, 9):
|
||||||
|
from types import GenericAlias
|
||||||
|
else:
|
||||||
|
GenericAlias = None
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from fastapi.params import Depends as FastAPIDepends
|
from fastapi.params import Depends as FastAPIDepends
|
||||||
|
@ -333,6 +339,10 @@ def _unpatch(
|
||||||
def _fetch_reference_injections(
|
def _fetch_reference_injections(
|
||||||
fn: Callable[..., Any],
|
fn: Callable[..., Any],
|
||||||
) -> Tuple[Dict[str, Any], Dict[str, Any]]:
|
) -> Tuple[Dict[str, Any], Dict[str, Any]]:
|
||||||
|
# # Hotfix, see: https://github.com/ets-labs/python-dependency-injector/issues/362
|
||||||
|
if GenericAlias and fn is GenericAlias:
|
||||||
|
fn = fn.__init__
|
||||||
|
|
||||||
signature = inspect.signature(fn)
|
signature = inspect.signature(fn)
|
||||||
|
|
||||||
injections = {}
|
injections = {}
|
||||||
|
|
5
tests/unit/samples/wiringsamples/queuemodule.py
Normal file
5
tests/unit/samples/wiringsamples/queuemodule.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# Hotfix, see: https://github.com/ets-labs/python-dependency-injector/issues/362
|
||||||
|
from queue import Queue
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ('Queue',)
|
|
@ -263,6 +263,21 @@ class WiringTest(unittest.TestCase):
|
||||||
self.assertIsInstance(service, Service)
|
self.assertIsInstance(service, Service)
|
||||||
|
|
||||||
|
|
||||||
|
class WiringAndQueue(unittest.TestCase):
|
||||||
|
|
||||||
|
def test_wire_queue(self) -> None:
|
||||||
|
from wiringsamples import queuemodule
|
||||||
|
container = Container()
|
||||||
|
self.addCleanup(container.unwire)
|
||||||
|
|
||||||
|
# Should not raise exception
|
||||||
|
# See: https://github.com/ets-labs/python-dependency-injector/issues/362
|
||||||
|
try:
|
||||||
|
container.wire(modules=[queuemodule])
|
||||||
|
except:
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
class WiringAndFastAPITest(unittest.TestCase):
|
class WiringAndFastAPITest(unittest.TestCase):
|
||||||
|
|
||||||
container: Container
|
container: Container
|
||||||
|
|
Loading…
Reference in New Issue
Block a user