implicit-optional (RUF013)#
Fix is sometimes available.
What it does#
Checks for the use of implicit Optional in type annotations when the
default parameter value is None.
Why is this bad?#
Implicit 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.
Example#
Use instead:
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:
Limitations#
Type aliases are not supported and could result in false negatives. For example, the following code will not be flagged: