fastapi-utils
fastapi-utils copied to clipboard
[BUG] Required dependency `typing_inspect`?
Describe the bug
If I'm using Pydantic 2, cbv.py imports package typing_inspect
. However this is listed as an optional dependency.
To Reproduce Steps to reproduce the behavior:
- Install latest Fast API, fastapi-utils
- Add a Resource
- Run service using
fastapi dev ...
- See error
Expected behavior It doesn't crash
Screenshots
│ /home/kevin/.../venv/lib/python3.11/site-packages/fastapi │
│ _utils/cbv_base.py:5 in <module> │
│ │
│ 2 │
│ 3 from fastapi import APIRouter, FastAPI │
│ 4 │
│ ❱ 5 from .cbv import INCLUDE_INIT_PARAMS_KEY, RETURN_TYPES_FUNC_KEY, _cbv │
│ 6 │
│ 7 │
│ 8 class Resource: │
│ │
│ ╭────────────────────── locals ──────────────────────╮ │
│ │ Any = typing.Any │ │
│ │ APIRouter = <class 'fastapi.routing.APIRouter'> │ │
│ │ Dict = typing.Dict │ │
│ │ FastAPI = <class 'fastapi.applications.FastAPI'> │ │
│ │ Optional = typing.Optional │ │
│ │ Tuple = typing.Tuple │ │
│ ╰────────────────────────────────────────────────────╯ │
│ │
│ /home/kevin/.../venv/lib/python3.11/site-packages/fastapi │
│ _utils/cbv.py:21 in <module> │
│ │
│ 18 │
│ 19 PYDANTIC_VERSION = pydantic.VERSION │
│ 20 if PYDANTIC_VERSION[0] == "2": │
│ ❱ 21 │ from typing_inspect import is_classvar │
│ 22 else: │
│ 23 │ from pydantic.typing import is_classvar # type: ignore[no-redef] │
│ 24 │
│ │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │ Any = typing.Any │ │
│ │ APIRoute = <class 'fastapi.routing.APIRoute'> │ │
│ │ APIRouter = <class 'fastapi.routing.APIRouter'> │ │
│ │ Callable = typing.Callable │ │
│ │ cast = <function cast at 0x74cc440459e0> │ │
│ │ Depends = <function Depends at 0x74cc4224dda0> │ │
│ │ get_type_hints = <function get_type_hints at 0x74cc44045b20> │ │
│ │ inspect = <module 'inspect' from '/usr/lib/python3.11/inspect.py'> │ │
│ │ List = typing.List │ │
│ │ pydantic = <module 'pydantic' from │ │
│ │ '/home/kevin/.../venv/lib/python3… │ │
│ │ PYDANTIC_VERSION = '2.7.4' │ │
│ │ Route = <class 'starlette.routing.Route'> │ │
│ │ Tuple = typing.Tuple │ │
│ │ Type = typing.Type │ │
│ │ TypeVar = <class 'typing.TypeVar'> │ │
│ │ Union = typing.Union │ │
│ │ WebSocketRoute = <class 'starlette.routing.WebSocketRoute'> │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
ModuleNotFoundError: No module named 'typing_inspect'
Environment:
- OS: Linux
- FastAPI Utils, FastAPI, and Pydantic versions [e.g.
0.3.0
], get them with:
import fastapi_utils
import fastapi
import pydantic.utils
print(fastapi_utils.__version__)
print(fastapi.__version__)
print(pydantic.utils.version_info())
^ This also fails to run w/o typing_inspect.
After installing it:
0.7.0
0.111.0
/home/kevin/.../venv/lib/python3.11/site-packages/pydantic/_migration.py:283: UserWarning: `pydantic.utils:version_info` has been moved to `pydantic.version:version_info`.
warnings.warn(f'`{import_path}` has been moved to `{new_location}`.')
pydantic version: 2.7.4
pydantic-core version: 2.18.4
pydantic-core build: profile=release pgo=true
install path: /home/kevin/.../venv/lib/python3.11/site-packages/pydantic
python version: 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0]
platform: Linux-6.5.0-41-generic-x86_64-with-glibc2.38
related packages: typing_extensions-4.12.2 fastapi-0.111.0
commit: unknown
- Python version, get it with:
3.11.6
Additional context Add any other context about the problem here.