diff --git a/fastapi_utils/cbv.py b/fastapi_utils/cbv.py index 231325c..0f1e881 100644 --- a/fastapi_utils/cbv.py +++ b/fastapi_utils/cbv.py @@ -1,4 +1,6 @@ +import functools import inspect +import sys from typing import ( Any, Callable, @@ -16,6 +18,9 @@ from fastapi.routing import APIRoute from starlette.routing import Route, WebSocketRoute +if sys.version_info >= (3, 9, 0): + get_type_hints = functools.partial(get_type_hints, include_extras=True) + PYDANTIC_VERSION = pydantic.VERSION if PYDANTIC_VERSION[0] == "2": from typing_inspect import is_classvar @@ -74,7 +79,7 @@ def _init_cbv(cls: Type[Any], instance: Any = None) -> None: ] dependency_names: List[str] = [] - for name, hint in get_type_hints(cls).items(): + for name, hint in get_type_hints(cls, include_extras=True).items(): if is_classvar(hint): continue parameter_kwargs = {"default": getattr(cls, name, Ellipsis)}