This codemod replaces
typing.Union[T, None] in the codebase.
This tool was inspired by a tweet from Sebastián Ramírez (as you see below), and a conversation between us.
As the tweet says, we have two reasons for doing this:
- It’s more explicit to write
Optional[str]. Mainly because
Optional[str]doesn’t mean that the attribute is optional. It only means that it accepts
Noneas a possible value.
- On Python 3.10+ you can type annotate as
str | Noneinstead of the above two. Which is more similar to
pip install no-optional
Run the following on the repository you want to format:
python -m libcst.tool initialize .
Then, add the
no_optional module to the
modules list on the
Then you are able to run:
python -m libcst.tool codemod main.NoOptionalCommand -j 1 <files>
This project is licensed under the terms of the MIT license.