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 acceptsNoneas a possible value. - On Python 3.10+ you can type annotate as
str | Noneinstead 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 no_optional <files>
You can also use the pre-commit. Add the following to your .pre-commit-config.yaml file:
- repo: https://github.com/Kludex/no-optional
rev: 0.4.0
hooks:
- id: no_optional
License
This project is licensed under the terms of the MIT license.
Metadata
Release files for no-optional 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| no_optional-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for no_optional-0.4.0-py3-none-any.whl |
Release files / no_optional-0.4.0-py3-none-any.whl
| Download URL | no_optional-0.4.0-py3-none-any.whl |
|---|---|
| Size | 6.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d4a625f7abbbaeef3b77ed88f53a44134c6f2d5a365378bb4a0197d94b95c998
|
|
BLAKE2b-256 checksum How to use checksums |
9a64b6d3d2e446c7c0b7d815359c2991724253be769a4e744ae4658a3caf8540
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.8.12
|
Security for no-optional 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.