Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add codemod to convert typing.Union to | #1270

Merged
merged 3 commits into from
Jan 3, 2025

Conversation

yangdanny97
Copy link
Contributor

Summary

This codemod can help upgrade typing syntax to Python 3.10+ by converting unions to use | as specified in PEP604

Test Plan

hatch run python -m unittest libcst.codemod.commands.tests.test_convert_union_to_or

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Dec 30, 2024
Copy link
Member

@zsol zsol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

Comment on lines 26 to 30
if QualifiedNameProvider.has_name(
self,
original_node,
QualifiedName(name="typing.Union", source=QualifiedNameSource.IMPORT),
):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I generally prefer early return in these cases

@yangdanny97 yangdanny97 merged commit d269872 into Instagram:main Jan 3, 2025
25 checks passed
@yangdanny97 yangdanny97 deleted the union branch January 3, 2025 00:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants