python / python/mypy

(inter-)dependent variable types

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

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

feature needs discussion priority-2-low
主要言語
Python
スター
20.6k
フォーク
3.3k
PR マージ指標
PR 指標を取得中

説明

I'm not sure how to entitle this, but I think it's a dependent type.

  • Are you reporting a bug, or opening a feature request? yes
  • 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 Tuple, Union

def x() -> Union[Tuple[int, int], Tuple[str, str]]:
    ...

a, b = x()

if isinstance(b, int):
    reveal_type(a) # can only be int but is reported as Union[int, str]

  • What is the actual behavior/output?
    type is reported as Union[int, str]
  • What is the behavior/output you expect?
    type of a can only be int given the return type signature
  • What are the versions of mypy and Python you are using? 7.20
    Do you see the same issue after installing mypy from Git master? yes
  • What are the mypy flags you are using? (For example --strict-optional)
    python_version=3.7

I'm assuming this would be a difficult change, but I figured I'd open an issue for the sake of having a record, and in the meantime I can use assert isinstance()

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

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

はじめの一歩

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

調査の方向性

issue にある最小限の Python 再現コードから始め、指定された Python 3.7 構成で現在の reveal_type の出力を確認します。b を int に絞り込むと a も int に絞り込まれ、対応する str のケースと、無関係な union に対する既存の動作が維持されれば、変更は完了です。

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

評価

技術スタック
python
領域
compilers
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
30/100

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

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