Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
gh-125618: Make FORWARDREF format succeed more often#132818
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Looks like this works in the case where the object is defined globally, but this still manages to fail if the object used in the annotation is defined (or evenpotentially redefined) within the function. Repro: fromannotationlibimportget_annotations,Formatdefboom():obj=object()classRaisesAttributeError:attriberr:obj.missingget_annotations(RaisesAttributeError,format=Format.FORWARDREF)boom() Output: Traceback (mostrecentcalllast):File"C:\Users\ducks\Source\cpython\.cache\annotation_examine.py",line9,in<module>boom()~~~~^^File"C:\Users\ducks\Source\cpython\.cache\annotation_examine.py",line7,inboomget_annotations(RaisesAttributeError,format=Format.FORWARDREF)~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File"C:\Users\ducks\Source\cpython\Lib\annotationlib.py",line778,inget_annotationsann=_get_and_call_annotate(obj,format)File"C:\Users\ducks\Source\cpython\Lib\annotationlib.py",line902,in_get_and_call_annotateann=call_annotate_function(annotate,format,owner=obj)File"C:\Users\ducks\Source\cpython\Lib\annotationlib.py",line629,incall_annotate_functionresult=func(Format.VALUE_WITH_FAKE_GLOBALS)File"C:\Users\ducks\Source\cpython\.cache\annotation_examine.py",line6,in__annotate__attriberr:obj.missing^^^^^^^^^^^File"C:\Users\ducks\Source\cpython\Lib\annotationlib.py",line380,in__getattr__returnself.__make_new(ast.Attribute(self.__get_ast(),attr))~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File"C:\Users\ducks\Source\cpython\Lib\annotationlib.py",line358,in__make_newself.__stringifier_dict__.stringifiers.append(stringifier)^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^AttributeError:'builtin_function_or_method'objecthasnoattribute'stringifiers' This came up because this is how I'd written my test case for this (writing the test case was actually as far as I'd gone, because the first test case raised the other issue). deftest_attributeerror_handled(self):classMissingAttrib:passclassRaisesAttributeError:attriberr:MissingAttrib.missingwithself.assertRaises(AttributeError):get_annotations(RaisesAttributeError,format=Format.VALUE)self.assertEqual(get_annotations(RaisesAttributeError,format=Format.FORWARDREF), {"attriberr":support.EqualToForwardRef("MissingAttrib.missing",owner=RaisesAttributeError,is_class=True, ) } )self.assertEqual(get_annotations(RaisesAttributeError,format=Format.STRING), {"attriberr":"MissingAttrib.missing"} ) |
Thanks! This was a silly bug that also broke |
af5799f
intopython:mainUh oh!
There was an error while loading.Please reload this page.
* origin/main:pythongh-125618: Make FORWARDREF format succeed more often (python#132818)
Uh oh!
There was an error while loading.Please reload this page.
Fixes#125618.
cc@DavidCEllis
AttributeError
is raised when__annotations__
is accessed #125618