For example:
def foo(bar: int = None):
pass
When I check a type/annotation of bar pycharm tells me that it is Optional[int].
bar: int = None looks much cleaner rather then bar: Optional[int] = None, especially when you have 10+ parameters.
So can I simply omit Optional? Will tools like mypy or other linters highlight this case as en error?
Looks like python itself doesn't like the idea:
In [1]: from typing import Optional
In [2]: from inspect import signature
In [3]: def foo(a: int = None): pass
In [4]: def bar(a: Optional[int] = None): pass
In [5]: signature(foo).parameters['a'].annotation
Out[5]: int
In [6]: signature(bar).parameters['a'].annotation
Out[6]: typing.Union[int, NoneType]