You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Aug 19, 2023. It is now read-only.
As of python 3.9.8, _type_check will reject a ClassVar type hint if it's not in a class, but the declaration for ForwardRef here:
defget_class_type_hints(klass: Type, localns=None) ->Dict[str, Any]:
"""Return type hints for a class. Adapted from `typing.get_type_hints`, adds support for PEP 585 & PEP 604"""hints= {}
forbaseinreversed(klass.__mro__):
base_globals=sys.modules[base.__module__].__dict__base_globals['_Union'] =Unionifsys.version_info< (3, 9):
base_globals['_List'] =Listbase_globals['_Set'] =Setbase_globals['_Type'] =Typebase_globals['_Tuple'] =Tuplebase_globals['_Dict'] =Dictann=base.__dict__.get('__annotations__', {})
forname, valueinann.items():
ifvalueisNone:
value=type(None)
ifisinstance(value, str):
t=ast.parse(value, '<unknown>', 'eval')
union_transformer=RewriteUnionTypes()
t=union_transformer.visit(t)
builtin_generics_transformer=RewriteBuiltinGenerics()
ifsys.version_info< (3, 9):
t=builtin_generics_transformer.visit(t)
ifbuiltin_generics_transformer.rewrittenorunion_transformer.rewritten:
# Note: ForwardRef raises a TypeError when given anything that isn't a string, so we need# to compile & eval the ast herecode=compile(t, '<unknown>', 'eval')
hints[name] =eval(code, base_globals, localns)
continueelse:
value=ForwardRef(value, is_argument=False)
value=_eval_type(value, base_globals, localns)
hints[name] =valuereturnhints
Doesn't include a check for if value is a class, which will always cause a failure when the annotation is some variation of the ClassVar generic.
I'm only working on a project using this library and don't know it super closely, would it be enough to always pass in is_class=True?
The text was updated successfully, but these errors were encountered:
BarakW
changed the title
The declaration of ForwardRef in get_class_type_hints doesn't include is_class, which breaks evaluation post Python 3.9.8
The declaration of ForwardRef in get_class_type_hints doesn't include is_class, which breaks evaluation on Python >=3.9.8
Dec 7, 2021
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
As of python 3.9.8,
_type_check
will reject aClassVar
type hint if it's not in a class, but the declaration forForwardRef
here:Doesn't include a check for if
value
is a class, which will always cause a failure when the annotation is some variation of theClassVar
generic.I'm only working on a project using this library and don't know it super closely, would it be enough to always pass in
is_class=True
?The text was updated successfully, but these errors were encountered: