Repository navigation
None is accepted as a type but it behaves erratically #299
Description
Activity
After we add Optional checking, maybe we can make
Nonemore consistently mean "the type containing just the value None" instead of also "the uninhabited type" and "a value you can't use".Fixed by #3024.
In
mypyversion 0.501, if you write:from typing import List from typing import Optional from typing import Union from typing import Generic from typing import TypeVar a: List[None] = [None] a.append(None) b: List[Optional[None]] = [None] b.append(None) c: List[Union[None]] = [None] c.append(None) T = TypeVar('T') class Foo(Generic[T]): def __init__(self, value: T) -> None: return def append(self, value: T) -> None: return f: Foo[None] = Foo(None) f.append(None)
Then
mypywill complain:example.py:7: error: List item 0 has incompatible type None example.py:8: error: Argument 1 to "append" of "list" has incompatible type None; expected None example.py:10: error: List item 0 has incompatible type None example.py:11: error: Argument 1 to "append" of "list" has incompatible type None; expected None example.py:13: error: List item 0 has incompatible type None example.py:14: error: Argument 1 to "append" of "list" has incompatible type None; expected None example.py:25: error: Argument 1 to "Foo" has incompatible type None; expected None example.py:26: error: Argument 1 to "append" of "Foo" has incompatible type None; expected NoneSo it seems that using
Noneas a type still doesn't behave exactly as "the type containing just the valueNone" - more over, it seems like there's no way to trickmypyinto declaring such a type.@orenbenkiki 0.501 is pretty old. Have you a tried the latest versions? it works for me on git master.
Ah, it works in version 0.550. Thanks.
Version 0.501 was released in March this year, if that makes it "old.".. it is great to see
mypyadvancing so fast!Yeah, 0.501 is already old in "mypy years" :-)
The following fragment generates a confusing error message: