Repository navigation
__annotate__ functions generated by CPython for class methods have an incorrect __qualname__ #137814
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Aug 15, 2025 - addedinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
on Aug 15, 2025 - added3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixes
on Aug 15, 2025 This is also similar for
__annotate__functions on global functions:>>> def f() -> None: pass ... >>> f.__annotate__.__qualname__ '__annotate__'Note arguably fixing this requires a magic number bump since it changes compiler output. Is this worth the disruption of a magic number bump? I'm not sure.
- added a commit that references this issue
on Aug 16, 2025 - marked
PicklingErroron CPython 3.14.0 when usingfunctools.update_wrapperand a type annotated function #143067 as a duplicate of this issueon Dec 23, 2025 See #143067 -- it breaks pickling.
Reacted by Olivier Grisel, Thomas S., Auguste Baum and Guillaume LemaitreIs this worth the disruption of a magic number bump? I'm not sure.
Just to provide a end-user feedback to give some particular context to the previous comment: on the scientific python side, we might have some parallel processing that would try to pickle some object coming from a class with annotations.
Not back-porting to 3.14 would mean that an entire library will not be compatible with a version of Python which looks strange I think.
Perhaps you can work around this by dropping the annotations before pickling? Do you really need the annotations in the parallel workers?
It looks something interesting to explore. I'll definitely have a look. Thanks @JelleZijlstra
This is now fixed on both 3.14 and main, though with different solutions.
Reacted by Thomas S. and David EllisThanks a bunch.
Bug report
Bug description:
The
__qualname__of__annotate__functions of methods of classes incorrectly refers to the__annotate__function of the class itself.Output:
CPython versions tested on:
3.14, CPython main branch
Operating systems tested on:
No response
Linked PRs
__qualname__of__annotate__#137842