4 ms·
That is false. On point 1: def use_int(n: int): return n * 2 def foo(n: Optional[int]): use_int(n) # MYPY complaints here because n could be N
by mijamo 7y ago
That is false.
On point 1:
def use_int(n: int):
return n * 2
def foo(n: Optional[int]):
use_int(n) # MYPY complaints here because n could be None
if n is not None:
use_int(n) #MYPY allows this because it understood it cannot be None
2) TypeDict work fine, do you have an example of waht does not work
3) Of course, JS is different from Python, "keyof" doesn't make any sense in Python because Python uses class where JS uses dicts
4) Of course there is:
Accepted = Literal["foo", "bar", 3]
def accept_values(v: Accepted):
print(v)
accept_values("foo")
accept_values("bar")
accept_values(3)
accept_values("wrong") # MYPY complains
accept_values(5) # MYPY complains