[BUG] Import error when using the basic package
Closed this issue · 1 comments
Dosenpfand commented
Describe the bug
When installing the basic package (according to the README), typing-inspect
is not installed as dependency and needs to be manually installed.
Traceback (most recent call last):
File "/home/m/dev/fastapi_restful_test/main.py", line 1, in <module>
import fastapi_restful
File "/home/m/dev/fastapi_restful_test/venv/lib/python3.11/site-packages/fastapi_restful/__init__.py", line 1, in <module>
from .cbv_base import Api, Resource, set_responses, take_init_parameters
File "/home/m/dev/fastapi_restful_test/venv/lib/python3.11/site-packages/fastapi_restful/cbv_base.py", line 5, in <module>
from .cbv import INCLUDE_INIT_PARAMS_KEY, RETURN_TYPES_FUNC_KEY, _cbv
File "/home/m/dev/fastapi_restful_test/venv/lib/python3.11/site-packages/fastapi_restful/cbv.py", line 11, in <module>
from typing_inspect import is_classvar
ModuleNotFoundError: No module named 'typing_inspect'
To Reproduce
Steps to reproduce the behavior:
- Install the basic slim package according to the
README.md
:pip install fastapi-restful
- Create a .py file just containing
import fastapi_restful
and execute it - Get
ModuleNotFoundError: No module named 'typing_inspect'
Expected behavior
- In the best case no error because
typing_inspect
was installed as dependency. But that would mean a unneeded dependency for v1 of Pydantic? - Alternatively, the error message could be improved, or an additional
extra
be added? - At the very least the README should be adapted.
I would be willing to open a PR if there is consensus on how to proceed. is_classvar()
(the only function from typing-inspect being used, could also be implemented in FastApi-RESTful itself. For Python 3.7+ it's a one-liner.
Environment:
- OS: Linux
pydantic version: 2.3.0
pydantic-core version: 2.6.3
pydantic-core build: profile=release pgo=true
install path: /home/m/dev/fastapi_restful_test/venv/lib/python3.11/site-packages/pydantic
python version: 3.11.5 (main, Aug 28 2023, 20:02:58) [GCC 13.2.1 20230801]
platform: Linux-6.4.12-arch1-1-x86_64-with-glibc2.38
optional deps. installed: ['typing-extensions']
- Python version:
Python 3.11.5
yuval9313 commented
It's because you're using pydantic>2 which is not the basic package you should use the fastapi-restful[all] and I will shortly add a v2 'extras' as well