`_v` can be read and written from the outside of the class so the generic class should be invariant properly.
オープン
まだ誰も着手していません。
bug
pending
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
*Memo:
- mypy --strict test.py
- mypy 1.19.1
- Python 3.14.0
- Windows 11
v can be read and written from the outside of the class so the generic class is invariant properly as shown below:
class Cls[T]:
v: T = cast(T, 100) # Invariant
cls: Cls[int] = Cls[int]()
# It indicates `Invariant`.
cls1: Cls[float] = cls # Errpr
cls2: Cls[int] = cls # No error
cls3: Cls[bool] = cls # Error
# Read & Write
print(cls.v) # No error
cls.v = 200 # No error
Now, _v can be read and written from the outside of the class but the generic class is covariant improperly as shown below so it should be invariant properly:
*Memo:
- A single leading underscore(_abc) just indicates Internal use so it's not private(Readable & Writable).
class Cls[T]:
_v: T = cast(T, 100) # Covariant
cls: Cls[int] = Cls[int]()
# It indicates `Covariant`.
cls1: Cls[float] = cls # No error
cls2: Cls[int] = cls # No error
cls3: Cls[bool] = cls # Error
# Read & Write
print(cls._v) # No error
cls._v = 200 # No error
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、指定されたバージョンの mypy 1.19.1 と Python 3.14.0 で、mypy --strict を使って test.py の報告を再現します。公開属性と単一アンダースコア属性を持つジェネリッククラスについて、mypy がどのように変性を推論するかを追跡します。_v の例が不変として扱われ、示されている有効な代入と無効な代入が維持されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 38/100