What if duck types are unions of all the ducklings
オープン
まだ誰も着手していません。
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
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
この issue の例から始め、提案されている union のセマンティクスを関連する issue #11511 および #11145 と比較してください。正確な float 型および bytes 型や isinstance による絞り込みを含め、duck typing された型がどのように振る舞うべきかを解決してください。合意された設計と、それに対応する型チェッカーの動作があれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 25/100