Replace typing.Union[X, Y] with X | Y
Recipe ID
org.openrewrite.python.migrate.ReplaceTypingUnionWithPipeArtifactopenrewrite-migrate-pythonPEP 604 introduced the | operator for union types in Python 3.10. Replace Union[X, Y, ...] with the more concise X | Y | ... syntax. Applies inside if TYPE_CHECKING: blocks as well; X | Y is valid at runtime from Python 3.10 on, so no from __future__ import annotations is needed.
Single recipepythonmigrationtyping3.10pep604Proprietary
Usage
This recipe has no required configuration options. You’ll need the Moderne CLI configured before running the command below.
mod run . --recipe org.openrewrite.python.migrate.ReplaceTypingUnionWithPipeIf the recipe isn’t available locally, install it with:
mod config recipes pip install openrewrite-migrate-python