mypy rejects unpacking into same variable
オープン
まだ誰も着手していません。
bug
topic-usability
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- 平均マージ
- 1日 18時間
- マージ済み PR(30日)
- 54
説明
Bug Report
I believe the following code should be fine, however mypy rejects the case where we're unpacking into the variable which was expanded:
foo: tuple[int, ...] = ()
# Ok
bar, *quox = foo
# Incompatible types in assignment (expression has type "List[int]", variable has type "Tuple[int, ...]") [assignment]
bar, *foo = foo
There are a number of similar issues reported, the closest being https://github.com/python/mypy/issues/9706, however I believe this is distinct as it reproduces when the generic type is int (though my original code was using str). This suggests a different root cause.
Your Environment
- Mypy version used: 1.0.1
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.10
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、報告された Python 3.10 のスニペットを mypy 1.0.1 で実行し、展開される変数が同時にソースでもある場合に、アンパック代入がどのようにチェックされるかを追跡します。このケースの回帰テストを追加し、同じ変数のアンパックが受け入れられる一方で、互換性のない代入は引き続き診断されることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 45/100