-
-
Notifications
You must be signed in to change notification settings - Fork 31.2k
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
Incorrect format passed to __annotate__
function
#125507
Comments
Ok, this is not so easy. What happens here:
My code in #122262 never had any But the question is: is this a good API? For me it feels like a very nuanced one with a lot of corner-cases. |
Practical question, how can I differentiate two calls in Lines 1614 to 1630 in 3b26e36
|
Would #124415 help here? |
@JelleZijlstra hm, I don't think so. Here's my simplified reproducer with #124415 applied: import annotationlib
class My:
def __annotate__(format):
assert format == annotationlib.Format.FORWARDREF, format
# Fails with: `AssertionError: 1`
return {}
annotationlib.get_annotations(My, format=annotationlib.Format.FORWARDREF) So, looks like it does still make the first call with |
I understand the issue now. You want to return For FORWARDREF format, we currently try using |
Though I'm curious if @larryhastings and @carljm have opinions here: If an object has At the sprint, we changed it so we preferred returning |
To me it seems like a useful, and sensible, invariant that if you successfully get To me, the proposed approach for dataclasses seems like over-optimization. I think it's fine to always import |
What Carl said. This should be documented behavior: if |
Thanks, then let's stick with the current behavior. |
Bug report
Consider this example:
This will fail with:
I think that we should still pass the format in
_BASE_GET_ANNOTATIONS
.I will try to fix this, since this affects my other PR: #122262
CC @JelleZijlstra
Linked PRs
The text was updated successfully, but these errors were encountered: