python-dependency-injector icon indicating copy to clipboard operation
python-dependency-injector copied to clipboard

The example “fastapi-sqlalchemy” cannot be executed ...

Open hustlmh opened this issue 4 years ago • 2 comments

hi, I cloned the git-master code and try to run the example without any modification in my miniconda environment where python version is 3.8.11, but the example “fastapi-sqlalchemy” cannot be executed. The error message is "TypeError: 'ABCMeta' object is not subscriptable". related environment is uvicorn 0.15.0 fastapi 0.68.1 dependency-injector 4.36.0

how to fix it ? Thanks !

fastapi-sqlalchemy % python -m webapp.application

Traceback (most recent call last): File "/Users/zoo/miniconda3/envs/gui/lib/python3.8/runpy.py", line 194, in _run_module_as_main return _run_code(code, main_globals, None, File "/Users/zoo/miniconda3/envs/gui/lib/python3.8/runpy.py", line 87, in _run_code exec(code, run_globals) File "/Users/zoo/Downloads/python-dependency-injector-master/examples/miniapps/fastapi-sqlalchemy/webapp/application.py", line 5, in from .containers import Container File "/Users/zoo/Downloads/python-dependency-injector-master/examples/miniapps/fastapi-sqlalchemy/webapp/containers.py", line 5, in from .database import Database File "/Users/zoo/Downloads/python-dependency-injector-master/examples/miniapps/fastapi-sqlalchemy/webapp/database.py", line 16, in class Database: File "/Users/zoo/Downloads/python-dependency-injector-master/examples/miniapps/fastapi-sqlalchemy/webapp/database.py", line 32, in Database def session(self) -> Callable[..., AbstractContextManager[Session]]: TypeError: 'ABCMeta' object is not subscriptable

hustlmh avatar Sep 08 '21 02:09 hustlmh

Thanks for reporting the issue @hustlmh . After a quick search, I found that adding from __future__ import annotations might help as a workaround. I didn't test it yet. A dirtier but 100% working fix is to just remove type annotations from line 32:

    @contextmanager
    def session(self) -> Callable[..., AbstractContextManager[Session]]:

I'll also try to see how to make it work on all supported Python versions. Thanks again.

rmk135 avatar Sep 13 '21 01:09 rmk135

@rmk135 where should this import be set? @hustlmh , did it work for you?

vlio20 avatar Apr 09 '22 16:04 vlio20