Typehinted Classes for Cleo 2.x
The authors of the excellent Cleo library have declared a plan to overhaul Typing in Cleo 3.x, amongst the many other improvements listed in their Writeup.
In the meantime, some of the projects that I work on make use of Cleo 2.x, whose Command.option() and Command.argument() methods are annotated with t.Any and don't enforce returned types.
This library adds type-hinted, type-enforced wrappers for these methods as a holdover until Cleo 3.x is ready for use.
If Cleo 3.x is out by the time you're reading this: You should probably be using that instead!
PyPi
https://pypi.org/project/typehints-cleo2/
Installation
With Poetry:
poetry add typehints_cleo2
With pip:
pip install typehints_cleo2
Example Usage
Modified example from Cleo's README.md
from cleo.helpers import argument, option
# Instead of `from cleo.commands.command import Command`
from typehints_cleo2 import TypeHintedCommand
# use TypeHintedCommand as a drop-in replacement for cleo's Command class
class GreetCommand(TypeHintedCommand):
...
def handle(self):
name: str = self.argument_str("name") # Type-Hinted argument_str guarantees a string return
...
...
Optional Arguments & Options
class TestCommand(TypeHintedCommand):
name = "test"
description = "Test Command"
arguments = [
argument("test_argument", description="A test argument", optional=False),
argument("test_argument2", description="A test argument", optional=True),
]
options = [option("test_option", description="A test option")]
...
def handle(self):
arg1: str = self.argument_str("test_argument")
arg2: str | None = self.argument_str_optional("test_argument2")
opt1: str | bool = self.option_str("test_option")
self.line(f"Test Command! -- Arg1: '{arg1}' -- Arg2: '{arg2}' -- Opt1: '{opt1}'")
...
poetry run python -m my_application test a_test_val
Output: Test Command! -- Arg1: 'a_test_val' -- Arg2: 'None' -- Opt1: 'False'
Metadata
Release files for typehints-cleo2 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| typehints_cleo2-1.0.0.tar.gz | 4.0 kB | Without provenance | Details for typehints_cleo2-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| typehints_cleo2-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for typehints_cleo2-1.0.0-py3-none-any.whl |
Total release size: 8.6 kB
Release files / typehints_cleo2-1.0.0.tar.gz
| Download URL | typehints_cleo2-1.0.0.tar.gz |
|---|---|
| Size | 4.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b6e9c4b0acd9b67facf545c4c5cf665b896a6c4c5a968cbdcce753113f35fabf
|
|
BLAKE2b-256 checksum How to use checksums |
fb2c56dc0d9c0d64b2c83ea88ea6d757e34a2d7a4dfbc765c44b1b454b47d962
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.0.0 CPython/3.12.4
|
Release files / typehints_cleo2-1.0.0-py3-none-any.whl
| Download URL | typehints_cleo2-1.0.0-py3-none-any.whl |
|---|---|
| Size | 4.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
467d5190ac63226c54347dff710c8f72b71760a3e34bd698b8545d89fef66b03
|
|
BLAKE2b-256 checksum How to use checksums |
f27fe9bfbb0a47917b3c29fb7bae46fb05102891758237b7e688ef1f916d761e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.0.0 CPython/3.12.4
|
Security for typehints-cleo2 1.0.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.