Can't assign entry to `__annotations__` unless a class has existing annotation
オープン
まだ誰も着手していません。
topic-typing
type-bug
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 36k
- 平均マージ
- 1日 9時間
- マージ済み PR(30日)
- 558
説明
Bug report
Can't assign entry to __annotations__ unless a class has existing annotation. This is related to https://github.com/python/cpython/issues/88067.
python 3.9:
Python 3.9.7 | packaged by conda-forge | (default, Sep 29 2021, 20:33:18)
[Clang 11.1.0 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> class Foo:
... __annotations__["b"] = int
...
>>> Foo.__annotations__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: type object 'Foo' has no attribute '__annotations__'
>>> class Foo:
... a: int
... __annotations__["b"] = int
...
>>> Foo.__annotations__
{'a': <class 'int'>, 'b': <class 'int'>}
python 3.10/python 3.11-rc:
Python 3.10.5 (main, Jul 12 2022, 11:32:11) [GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> class Foo:
... __annotations__["a"] = int
...
>>> Foo.__annotations__
{}
>>> class Foo:
... a: float
... __annotations__["b"] = int
...
>>> Foo.__annotations__
{'a': <class 'float'>, 'b': <class 'int'>}
Your environment
- CPython versions tested on: 3.9, 3.10, 3.11-rc
- Operating system and architecture: Mac, Linux
I'm interested in submitting a PR for this, but first would like to double check that such PR/change would be acceptable?
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、影響を受ける Python バージョンでクラス本体の例を再現し、アノテーションに関する周辺の動作を確認するため、関連する issue 88067 を読みます。クラスレベルの annotations がどのように初期化されるかを追跡し、アノテーションが事前に存在しないクラスでエントリを代入した場合に、そのエントリが保持され、既存のアノテーション付きクラスの動作が変更されないことを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100