-
-
Notifications
You must be signed in to change notification settings - Fork 34.3k
defining a typing.Protocol with __annotate__ method raises TypeError since Python 3.14 #146643
Copy link
Copy link
Open
Labels
3.14bugs and security fixesbugs and security fixes3.15new features, bugs and security fixesnew features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
from annotationlib import Format
from collections.abc import Mapping
from typing import Any, Protocol
class CanAnnotate(Protocol):
def __annotate__(self, format: Format, /) -> Mapping[str, Any]: ...On Python 3.14.3 and 3.15.0a7 this results in a TypeError:
Traceback (most recent call last):
File "/home/joren/.local/share/uv/python/cpython-3.14.3-linux-x86_64-gnu/lib/python3.14/typing.py", line 1853, in _get_protocol_attrs
annotations = base.__annotations__
^^^^^^^^^^^^^^^^^^^^
TypeError: CanAnnotate.__annotate__() missing 1 required positional argument: 'format'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/joren/Workspace/optype/repro.py", line 6, in <module>
class CanAnnotate(Protocol):
def __annotate__(self, format: Format, /) -> Mapping[str, Any]: ...
File "/home/joren/.local/share/uv/python/cpython-3.14.3-linux-x86_64-gnu/lib/python3.14/typing.py", line 1999, in __init__
cls.__protocol_attrs__ = _get_protocol_attrs(cls)
~~~~~~~~~~~~~~~~~~~^^^^^
File "/home/joren/.local/share/uv/python/cpython-3.14.3-linux-x86_64-gnu/lib/python3.14/typing.py", line 1856, in _get_protocol_attrs
annotations = _lazy_annotationlib.get_annotations(
base, format=_lazy_annotationlib.Format.FORWARDREF
)
File "/home/joren/.local/share/uv/python/cpython-3.14.3-linux-x86_64-gnu/lib/python3.14/annotationlib.py", line 982, in get_annotations
ann = _get_and_call_annotate(obj, format)
File "/home/joren/.local/share/uv/python/cpython-3.14.3-linux-x86_64-gnu/lib/python3.14/annotationlib.py", line 1121, in _get_and_call_annotate
ann = call_annotate_function(annotate, format, owner=obj)
File "/home/joren/.local/share/uv/python/cpython-3.14.3-linux-x86_64-gnu/lib/python3.14/annotationlib.py", line 720, in call_annotate_function
return annotate(format)
TypeError: CanAnnotate.__annotate__() missing 1 required positional argument: 'format'On Python 3.13 (when you replace the annotationlib.Format with Any), there is no error.
CPython versions tested on:
3.14
Operating systems tested on:
Linux
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
3.14bugs and security fixesbugs and security fixes3.15new features, bugs and security fixesnew features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error