-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
[3.14] annotationlib - calling get_annotations
on instances gets an unexpected error
#132261
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
Comments
That's a difficult one. It's because One approach I can think of would be to make it so the |
Actually I thought of something: we can store the annotate function at some other key in the class dictionary than Turns out I should have eaten breakfast before spending time on GitHub :) |
I slightly worry about moving My suggestion for this bug would have just been to wrap it as a Breakfast on the other hand is always a good idea. :) |
What if we made https://docs.python.org/3.14/library/annotationlib.html#annotationlib.get_annotate_function support a dictionary as its argument so you can use it in this context? I generally want to get rid of any case where users may be tempted to reach directly into the dictionary, because that means we lose the flexibility to change later exactly what we put in the dictionary.
I thought of that too; not too excited about the complexity it introduces, and it means that if you access
I forgot that |
I'm not sure - I'll note I'm not the only one doing this as someone else was also asking what the best practice would be for getting and replacing
Ah I hadn't noticed that as I'd forgotten to look in Footnotes
|
Bug report
Bug description:
In 3.13,
inspect.get_annotations
would fail if called on instances and give you aTypeError
explaining as much.In 3.14 if you call
annotationlib.get_annotations(inst, format=Format.STRING)
on an instance you currently get a more confusing error.As far as I can tell this appears to be because
__annotate__
has turned into a bound method.You currently only see this if you use
Format.STRING
due to #125618 masking the issue, as with both other formats if__annotations__
has been created on the class it is used instead of calling__annotate__
and if it doesn't you get an empty dict.CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Linked PRs
The text was updated successfully, but these errors were encountered: