python / python/mypy

What if duck types are unions of all the ducklings

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

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

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

説明

If the duck typed types were actually unions of all the ducklings then it would fix a bunch of edge cases that arise.
And would make this feature more easily understood and discovered.

def func1(c: complex):
    reveal_type(c)  # float | int | complex

def func2(f: float):
    reveal_type(f)  # float | int

def func3(b: bytes):
    reveal_type(b)  # bytes | bytearray | memoryview

def func4(u: unicode):  # python 2 moment
    reveal_type(u)  # unicode | str

edge cases:

def func(f: float):
    f.is_integer()  # error: int has no member "is_integer"
def func(f: float):
    if not isinstance(f, float):
        print("hi")  # no 'unreachable code' error
        reveal_type(f)  # int | complex

It would also be useful to have type types for float and bytes, when you want exactly float and don't want any stinking ints.

Related #11511, #11145

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

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

はじめの一歩

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

調査の方向性

この issue の例から始め、提案されている union のセマンティクスを関連する issue #11511 および #11145 と比較してください。正確な float 型および bytes 型や isinstance による絞り込みを含め、duck typing された型がどのように振る舞うべきかを解決してください。合意された設計と、それに対応する型チェッカーの動作があれば完了です。

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

評価

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

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

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