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
If there's an annotation with an incorrect attribute access, the AttributeError causes get_annotations to return an empty dictionary for the annotations instead of failing or returning a ForwardRef.
importtypingfromannotationlibimportget_annotations, FormatclassExample2:
real_attribute: typing.Anyfake_attribute: typing.DoesNotExistnew_ann=get_annotations(Example2, format=Format.FORWARDREF)
print(f"{new_ann=}")
# This should fail, but instead returns an empty dictvalue_ann=get_annotations(Example2, format=Format.VALUE)
print(f"{value_ann=}")
string_ann=get_annotations(Example2, format=Format.STRING)
print(f"{string_ann=}")
I think this is due to _get_dunder_annotations catching AttributeError and returning an empty dict, intended for static types but catching this by mistake.