defining a `typing.Protocol` with `__annotate__` method raises `TypeError` since Python 3.14
オープン
まだ誰も着手していません。
3.14
3.15
stdlib
topic-typing
type-bug
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
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
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
typing.py の _get_protocol_attrs と annotationlib.py のアノテーション処理パス、特に get_annotations と call_annotate_function から始めます。Python 3.14 で CanAnnotate の例を再現し、その後、アノテーションの評価を壊すことなくプロトコルの定義で TypeError が発生しなくなったことを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 35/100