Add `--allow-redefinition-line-heuristic`, which would allow force-redefining in all cases
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Feature
Right now, --allow-redefinition only allows redefinitions in cases of blocks on the same level.
If I understand it correctly, it is hypothetically possible to extend it to work on different block levels, as long as redefinition is a superseding block.
However, why not try something simpler? Instead of worrying about blocks, let's say that x: int # mypy:force or # mypy:manual means "x has a type int from this line onward, up until it's explicitly redefined again or goes out of scope (meaning function ends)".
Pitch
The problem with adding typing to dynamic language is that there are things like redefinitions - things that are not compatible with static typing out of the box. mypy proposes some ways of working around, e.g. muting such problems on a case-by-case basis. The big problem here, however, is that redefinition cannot be "fixed" by single comment or annotation - we have to add #mypy:ignore to every place the redefined symbol is used.
The another way of "fixing" is to actually fix them - but the thing with redefinitions is that they happen in Python is because they are convenient. Even some static languages add support for them (Rust wink wink). Removing them require code refactoring, and often adding more variables, which can lead to silent bugs (i.e. accidental use of old name). This is feasible only on a small scale, or with highest quality code, not on a big & diverse codebase.
The proposed solution is definitely wonky, but actually it provides a way to "fix" all redefinition-related issues without modifying the code and without sprinkling every line with #type:ignore.
From the moment user opt ins with mypy:force, they are basically responsible for manually annotating this symbol's type. This sounds bad but it's actually what we want - mypy cannot manage this variable's type anyway after all.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、既存の --allow-redefinition の動作と、issue で提案されている行ベースの force/manual セマンティクスを確認します。関数境界でスコープがどのように終了するか、また明示的な再定義をどのように扱うべきかを判断します。新しいオプションによって、使用箇所ごとに ignore を要求せず、説明されているケースを一貫して許可できるようになった時点で作業は完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 25/100