Use type context from previous definition when renaming
オープン
まだ誰も着手していません。
false-positive
needs discussion
priority-1-normal
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Maybe we code like this shouldn't generate an error when using --allow-redefinition:
x: List[int] = []
# do something with x
x = [] # Error: need annotation
The reason for the error is that the second assignment creates a completely independent variable, so the type of the original definition has no effect.
There are still some open issues:
- Using the context can generate false positives, in case the correct type would be something different for the second definition. I don't know how often this would be an issue.
- Propagating the type context is somewhat tricky since the name of the previous definition is not trivial to calculate. The rules for renaming depend on the scope (local/class/global).
- If/when we support more general redefinitions (not just within a single block), it may be unclear when we should propagate context. It may be best to first to make redefinitions more general and then reconsider this issue.
Follow-up to #6197.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、フォローアップ issue #6197 と、この issue で説明されている再定義の動作を読んでください。提供されている --allow-redefinition の例を使って、列挙されている誤検知と名前変更に関する懸念を含め、スコープ間で型コンテキストをどのように扱うべきかを判断してください。実装前に意図した動作とスコープが確定していれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100