Open
Description
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 int
s.