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 rename typing aliases of builtins #1267

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

yangdanny97
Copy link
Contributor

Summary

This PR adds a codemod for Python 3.9+ that updates references like typing.List to just list. It includes all the builtins that have an alias in the typing module.

We can also do the same thing for some non-builtin types in the collections module (the full list is in https://peps.python.org/pep-0585/#implementation) but I'm not sure if that should be a separate codemod or added to this one.

I also had to update the RenameCommand to avoid adding imports if the new name is a builtin.

Test Plan

hatch run python -m unittest libcst.codemod.commands.tests.test_rename
hatch run python -m unittest libcst.codemod.commands.tests.test_rename_typing_generic_aliases

@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
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.

2 participants