Use Optional instead of Union

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:

code-review-doctorbotsuggested changes just now
helpers.py
1
+
def foo_bar() -> Union[int, None]:
Suggested changes
-
def foo_bar() -> Union[int, None]:
+
def foo_bar() -> Optional[int]:
Commit suggestion

This could be simplified by using typing.Optional

Read more
2
+
    # sometimes return int other times None
Update helpers.py
We're your Python code review copilot. Get code improvements right in your pull request with our GitHub code review bot.

Configuring this check

Code Review Doctor will run this check by default. No configuration is needed but the check can be turned on/off using check code use-optional in your pyproject.toml file.

Read more about configuring Code Review Doctor.