Skip to main content

An awesome package is coming soon! 🎉

Project description

no-optional

Package version

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.

image

As the tweet says, we have two reasons for doing this:

  1. It's more explicit to write Union[str, None] than Optional[str]. Mainly because Optional[str] doesn't mean that the attribute is optional. It only means that it accepts None as a possible value.
  2. On Python 3.10+ you can type annotate as str | None instead of the above two. Which is more similar to Union[str, None] than Optional[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


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

no_optional-0.1.0.post1-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file no_optional-0.1.0.post1-py3-none-any.whl.

File metadata

File hashes

Hashes for no_optional-0.1.0.post1-py3-none-any.whl
Algorithm Hash digest
SHA256 5fc77266e6339ea2d940b1e3f2099f53fe37b877de1875d476ea7937fc367642
MD5 ae5555a65071d26d233bcfd615d00907
BLAKE2b-256 dd4f47eb0ccc18487e9e13a702f9417caf5107ba868873d9653c58a10d7ab271

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page