antonrh / anydi

Python Dependency Injection
https://anydi.readthedocs.io/
MIT License
34 stars 0 forks source link

Running unit test in Python 3.9 fails #104

Closed hoon0422 closed 1 month ago

hoon0422 commented 1 month ago

Running unit test in this project fails:

======================================= test session starts =======================================
platform darwin -- Python 3.9.7, pytest-8.2.2, pluggy-1.5.0
rootdir: /Users/Younghoon/projects/whova/anydi
configfile: pyproject.toml
plugins: anyio-4.4.0
collected 158 items / 2 errors                                                                    

============================================= ERRORS ==============================================
_______________________________ ERROR collecting tests/ext/fastapi ________________________________
../../../opt/anaconda3/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1030: in _gcd_import
    ???
<frozen importlib._bootstrap>:1007: in _find_and_load
    ???
<frozen importlib._bootstrap>:986: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:680: in _load_unlocked
    ???
../../../opt/anaconda3/lib/python3.9/site-packages/_pytest/assertion/rewrite.py:178: in exec_module
    exec(co, module.__dict__)
tests/ext/fastapi/conftest.py:9: in <module>
    from .app import app as _app
tests/ext/fastapi/app.py:90: in <module>
    anydi.ext.fastapi.install(app, container)
anydi/ext/fastapi.py:50: in install
    for parameter in get_typed_parameters(call):
anydi/_utils.py:97: in get_typed_parameters
    return [
anydi/_utils.py:99: in <listcomp>
    annotation=get_typed_annotation(
anydi/_utils.py:75: in get_typed_annotation
    annotation = ForwardRef(annotation, module=module, is_class=is_class)
E   TypeError: __init__() got an unexpected keyword argument 'is_class'
________________________ ERROR collecting tests/ext/test_pytest_plugin.py _________________________
'inject' not found in `markers` configuration option
===================================== short test summary info =====================================
ERROR tests/ext/fastapi - TypeError: __init__() got an unexpected keyword argument 'is_class'
ERROR tests/ext/test_pytest_plugin.py - Failed: 'inject' not found in `markers` configuration option

It seems ForwardRef does not support is_class parameter in Python 3.9, but the if-statement for the python version does not include Python 3.9

https://github.com/antonrh/anydi/blob/main/anydi/_utils.py#L72

antonrh commented 1 month ago

@hoon0422, thank you for finding this. It should be fixed in https://pypi.org/project/anydi/0.26.7/.

antonrh commented 1 month ago

Closing this issue. Let me know if you find any more compatibility issues.