Truthiness of None Does not Narrow Optional Types
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Note: if you are reporting a wrong signature of a function or a class in
the standard library, then the typeshed tracker is better suited
for this report: https://github.com/python/typeshed/issues
Please provide more information to help us understand the issue:
-
Are you reporting a bug, or opening a feature request?
I believe this is a bug -
Please insert below the code you are checking with mypy,
or a mock-up repro if the source is private. We would appreciate
if you try to simplify your case to a minimal repro.
from typing import Optional
def the_method(maybe_int: Optional[int]):
can_divide = bool(maybe_int)
if can_divide:
100 / maybe_int
- What is the actual behavior/output?
error: Unsupported operand types for / ("int" and "None")
-
What is the behavior/output you expect?
I would think that the conditional branch would recognize that onlyintvalues would ever make it there -
What are the versions of mypy and Python you are using?
mypy 0.720 with Python 3.7.3 -
Do you see the same issue after installing mypy from Git master?
Yes still exists on master
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
Issue にある最小限の Python 再現コードから始め、mypy の truthiness ベースの型絞り込みのエントリーポイントを追跡してください。報告にはソースファイルもテストも指定されていません。完了条件は、条件分岐によって Optional[int] が 100 / maybe_int の型チェックに十分なところまで絞り込まれ、回帰テストのカバレッジが追加されていることです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100