Fix is sometimes available.
What it does#
Checks for the use of implicit
Optional in type annotations when the
default parameter value is
Why is this bad?#
Optional is prohibited by PEP 484. It is confusing and
inconsistent with the rest of the type system.
It's recommended to use
Optional[T] instead. For Python 3.10 and later,
you can also use
T | None.
Or, for Python 3.10 and later:
If you want to use the
| operator in Python 3.9 and earlier, you can
use future imports:
Type aliases are not supported and could result in false negatives. For example, the following code will not be flagged: