Variety of codemods/scripts for libcst, that are helpful for automated refactoring/moderanization of Python code.
- ConstantToFinal: Add
Final
as an annotation to all constant variables (UPPER_UNDERSCORE
).- Input:
FOO = 1 BAR: int = 2 LIT: Literal[3]
- Output:
FOO: Final = 1 BAR: Final[int] = 2 LIT: Final[Literal[3]]
- Flags:
-c
to include class constants,-s
to run the codemod on stubs only. - Note: This is more useful for projects using MyPy, or libraries with MyPy users, as Pyright allows you to enforce constants based on convention through the
reportConstantRedefinition
rule.
- Input: