defining a `typing.Protocol` with `__annotate__` method raises `TypeError` since Python 3.14
Abierto
Nadie ha tomado este issue todavía.
3.14
3.15
stdlib
topic-typing
type-bug
- Lenguaje dominante
- Python
- Estrellas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
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
Linked PRs
- gh-151899
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con _get_protocol_attrs en typing.py y la ruta de gestión de anotaciones en annotationlib.py, especialmente get_annotations y call_annotate_function. Reproduce el ejemplo de CanAnnotate en Python 3.14 y, a continuación, verifica que definir el protocolo ya no provoque TypeError sin romper la evaluación de anotaciones.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- devtools
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 35/100