I am aware this is clarified in the Python documentation for the typing module but I and others have thought the naming of Optional is still quite confusing by itself.
"Note that this is not the same concept as an optional argument, which is one that has a default. An optional argument with a default does not require the Optional qualifier on its type annotation just because it is optional." - typing.Optional docs
Google defines optional as this, "available to be chosen but not obligatory."
Pretend we have a function like this:
def test_func(param: Optional[str]) -> None:
The argument param is typed as Optional[str] meaning Union[str, None] or str | None. Optional here if we follow the definition above, basically means it can be str but not required or obligated to be that type. See the problem with the naming? This is a function where param can be None or str, not just it can be str but not obligated. Some interpretations may think optional means left to one's choice as well. The docs even have to clarify the use of Optional with typing because of this confusion.
I believe this has been proposed before (not sure) but something like Nullable or Noneable (not sure about naming) would make much more sense in the context of typing.
def test_func(param: Noneable[str]) -> None:
It also would work and still make sense if there is a default value for the argument:
def test_func(param: Noneable[str] = None) -> None:
def test_func(param: Noneable[str] = "hello world") -> None: