python / python/cpython

PEP696 + PEP749: Defer evaluation of defaults when parametrizing

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

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

stdlib topic-typing type-bug
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

Bug report

Bug description:

With PEP 696 + PEP 749, the following works just fine:

class Scalar[CompatT, TruthT = BoolScalar]: ...
class BoolScalar(Scalar): ...
class IntScalar(Scalar[int]): ...  # OK ✅️

However, if we switch around the order of definition, the code breaks:

class Scalar[CompatT, TruthT = BoolScalar]: ...
class IntScalar(Scalar[int]): ...  # ❌️ NameError: name 'BoolScalar' is not defined
class BoolScalar(Scalar): ...

I guess since the default gets evaluated here. Not sure whether this is a bug or feature request, but it would be nice if the evaluation of the default could be deferred in is case as well.

CPython versions tested on:

3.14

Operating systems tested on:

Linux

Linked PRs
  • gh-152208

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

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

はじめの一歩

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

調査の方向性

issue にある2つのクラス定義の例を CPython 3.14 で実行し、動作を比較します。リンクされている PEP 696 と PEP 749 の議論を読み、リンクされている PR gh-152208 を確認します。前方定義の例で NameError が発生しなくなり、既存の例が引き続き動作すれば完了です。

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

評価

技術スタック
python
領域
backend
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

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

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