-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Required dependency typing_inspect
?
#318
Comments
From the source of the function https://github.com/ilevkivskyi/typing_inspect/blob/master/typing_inspect.py#L261-L275: NEW_TYPING = sys.version_info[:3] >= (3, 7, 0) # it's always True, since fastapi-utils requires >=3.7
def is_classvar(tp):
"""Test if the type represents a class variable. Examples::
is_classvar(int) == False
is_classvar(ClassVar) == True
is_classvar(ClassVar[int]) == True
is_classvar(ClassVar[List[T]]) == True
"""
if NEW_TYPING:
return (tp is ClassVar or
isinstance(tp, typingGenericAlias) and tp.__origin__ is ClassVar)
elif WITH_CLASSVAR:
return type(tp) is _ClassVar
else:
return False we get that to solve this problem we need only a few lines instead of the undocumented requirement of from typing import _GenericAlias
if sys.version_info[:3] >= (3, 9, 0):
from typing import _SpecialGenericAlias
typingGenericAlias = (_GenericAlias, _SpecialGenericAlias, types.GenericAlias)
else:
typingGenericAlias = (_GenericAlias,)
def is_classvar(tp):
"""Test if the type represents a class variable. Examples::
is_classvar(int) == False
is_classvar(ClassVar) == True
is_classvar(ClassVar[int]) == True
is_classvar(ClassVar[List[T]]) == True
"""
return tp is ClassVar or isinstance(tp, typingGenericAlias) and tp.__origin__ is ClassVar And after October 2024, when Python 3.8 reaches its end of life https://peps.python.org/pep-0569/, the number of lines will become even smaller. |
There is another option using
def is_classvar(tp):
return typing_extensions.get_origin(tp) is ClassVar |
hey, will this be fixed? The Issue still exists |
Well, it seems like a misunderstanding, To use pydantic v2 it is required to install fastapi-utils[all]. I do think maybe upgrading typing_extensions will make the cut |
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:
fastapi dev ...
Expected behavior
It doesn't crash
Screenshots
Environment:
0.3.0
], get them with:^ This also fails to run w/o typing_inspect.
After installing it:
3.11.6
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: