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 }}
Repository navigation
Annotations: Nested generics containing forward references can evade evaluation in ForwardRef.evaluate #160766
If an annotation has a subscripted object that is not yet defined which contains a GenericAlias or Annotated alias that is defined that itself contains a reference that is not yet defined, this final reference can evade being evaluated in ForwardRef.evaluate.
It's a bit easier with an example, this shows the issues with Format.STRING and Format.VALUE:
fromannotationlibimportget_annotations, FormatclassX:
a: Y[list[Z]]
# Get annotations here to get the ForwardRefanno=get_annotations(X, format=Format.FORWARDREF)['a']
classY[T]:
passprint(anno.evaluate(format=Format.STRING))
print(anno.evaluate(format=Format.VALUE))
This is due to the containing alias that can be evaluated being collected as one object in __extra_names__. When .evaluate is then called, this object is retrieved and still contains the second ForwardRef which is never evaluated.
Even if Z is defined, the result of the evaluate call does not change. I stumbled upon this while writing some heavily nested annotations for tests for another issue.
Activity