Replace typing.Optional[X] with X | None
ProprietaryPEP 604 introduced the | operator for union types in Python 3.10. Replace Optional[X] with the more concise X | None syntax. Applies inside if TYPE_CHECKING: blocks as well; X | None is valid at runtime from Python 3.10 on, so no from __future__ import annotations is needed. A subscript holding a string forward reference or a comment is left alone.
org. openrewrite. python. migrate. ReplaceTypingOptionalWithUnionmod run . --recipe= org. openrewrite. python. migrate. ReplaceTypingOptionalWithUnionInstall it once, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.