-
-
Notifications
You must be signed in to change notification settings - Fork 32.9k
Closed
Labels
3.14bugs and security fixesbugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
I'm playing around with PEP 649, PEP 749 annotations and I found this surprising behaviour:
class C:
x: str
def __annotate__(format):
if format != 1:
raise NotImplementedError()
return {'x': int}
assert C.__annotate__(1) == {'x': int} # This returns {'x': str} and fails
I'm not yet sure why I would write code with annotations and then also write an explicit __annotate__
, but I would expect the explicit method to prevail over the compiler-generated one. If I explicitly set C.__annotate__ = some_func
afterwards it works as I would expect.
Calling dis
on the provided example shows both __annotate__
s getting compiled, and one overwriting the other in the class.
Related to #119180.
CPython versions tested on:
3.14, CPython main branch
Operating systems tested on:
Linux
Linked PRs
Metadata
Metadata
Assignees
Labels
3.14bugs and security fixesbugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error