Replace `Optional[T]` by `Union[T, None]`! 🎉
Project description
no-optional
This codemod replaces typing.Optional[T]
by typing.Union[T, None]
in the codebase.
Why?
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
Union[str, None]
thanOptional[str]
. Mainly becauseOptional[str]
doesn't mean that the attribute is optional. It only means that it acceptsNone
as a possible value. - On Python 3.10+ you can type annotate as
str | None
instead of the above two. Which is more similar toUnion[str, None]
thanOptional[str]
.
Installation
pip install no-optional
Usage
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 .libcst.codemod.yaml
generated.
Then you are able to run:
python -m libcst.tool codemod main.NoOptionalCommand -j 1 <files>
License
This project is licensed under the terms of the MIT license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for no_optional-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5647e0fa63141be5446d6389ad47848e2bcfa98c88d1cfa8849d6fcbe7798541 |
|
MD5 | b07c9dc397f1881d21600a3f07cac6fc |
|
BLAKE2b-256 | 3bd627af764849cedb192163f748486b01608e6e655ad4fba1f575013243ef4f |