Refactor parial types to avoid code duplication
オープン
まだ誰も着手していません。
priority-1-normal
refactoring
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Currently there is some duplication around partial types:
- Logic in
try_infer_partial_generic_type_from_assignment()essentially duplicates the logic inlined incheck_assignment()forNonepartial types. These two probably can be refactored to the same method if we also updatehandle_partial_var_type()to not special-case partialNonetypes, and instead consistently return a partial type in lvalue context. - Logic in
try_infer_partial_type_from_indexed_assignment()duplicates that intry_infer_partial_type()(there is already a TODO item). This one can be refactored by either pushing the latter a bit down the call stack (closer tocheck_call()), or by generating a syntheticCallExprwith__setitem__and passing it totry_infer_partial_type().
The second item may be something to watch out when implementing support for these:
a = defaultdict(list)
a[0].append('yes')
b = {}
b.setdefault(0, []).append('yes')
c = defaultdict(set)
c[0].add('yes')
d = {}
d.setdefault(0, set()).add('yes')
@JukkaL this is probably not something important, but maybe it makes sense to fix this while we are at it?
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず try_infer_partial_generic_type_from_assignment()、check_assignment()、handle_partial_var_type()、try_infer_partial_type_from_indexed_assignment()、try_infer_partial_type() の場所を確認します。それらの部分型の処理を比較し、続いて defaultdict と setdefault の例をリグレッションケースとして評価します。これらの推論シナリオを壊すことなく重複したロジックが統合されていれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers, devtools
- issue の種類
- リファクタリング
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 38/100