Conditional annotations are always included in `STRING` annotations

オープン
#156,515 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
python
領域
backend

調査の方向性

まず get_annotations と Format.STRING を使って例を再現し、その後 annotationlib の実装と関連するテストを調べます。STRING の結果に b などの条件付きアノテーションが含まれず、VALUE と FORWARDREF の動作と一致し、回帰が成功するテストでカバーされていれば完了です。

索引モデルが issue の本文から書いたものです。

説明

3.14 3.15 3.16 stdlib type-bug

Bug report

Bug description:

If an annotation is excluded via a conditional block it is correctly excluded in VALUE and FORWARDREF annotations but is incorrectly included under STRING annotations.

from annotationlib import get_annotations, Format

class Example:
    a: int
    if False:
        b: str

print(get_annotations(Example))
print(get_annotations(Example, format=Format.STRING))
{'a': <class 'int'>}
{'a': 'int', 'b': 'str'}

'b' should not be included in string annotations here.

CPython versions tested on:

3.14, 3.15, CPython main branch

Operating systems tested on:

No response

Linked PRs
  • gh-156516
主要言語
Python
スター
77.2k
フォーク
36k
平均マージ
1日 9時間
マージ済み PR(30日)
558

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

python/cpython のほかの issue

python/cpython の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。