Type field declared in multiple flows as common base

オープン
#5,111 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
25/100
issue の種類
機能追加
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
python
領域
devtools

調査の方向性

The issue names no files, tests, or entry points. Start by reviewing the conditional-assignment examples and the requested common-base inference, then determine the intended typing behavior for optional and related model types. Done means the desired inference is defined and supported without requiring either explicit annotation form.

索引モデルが issue の本文から書いたものです。

説明

feature topic-type-narrowing

In this code:

if condition:
  s = get_str()
else:
  s = get_optional_str()

we currently need to add hints, i.e. (a)

if condition:
  s: Optional[str] = get_str()
else:
  s = get_optional_str()

or (b)

s: Optional[str]
if condition:
  s = get_str()
else:
  s = get_optional_str()

Both (a) and (b) seem overly verbose to me, for what seems like a common pattern. If the optionality of s serves a problem for the code that's to follow, that's what mypy should alert us about.

Perhaps optionality is actually somewhat of a special case. A more natural application of this logic would allow for:

if condition:
   model = get_foo_model()  # FooModel
else:
   model = get_bar_model()  # BarModel
# model is Model
主要言語
Python
スター
20.6k
フォーク
3.3k
平均マージ
1日 18時間
マージ済み PR(30日)
54

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

python/mypy のほかの issue

python/mypy の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。