This could be simplified by using typing.Optional
Core to the philosophy of Python is it's written to be read. Optional
does a better job at communicates to the reader that the value is optional. Given that these are completely equivalent:
Why not choose the easiest to both read and write (the first one)
If our GitHub code review bot spots this issue in your pull request it gives this advice:
1 | + | def foo_bar() -> Union[int, None]: |
This could be simplified by using typing.Optional
- | def foo_bar() -> Union[int, None]: |
+ | def foo_bar() -> Optional[int]: |
2 | + | # sometimes return int other times None |