Comments (4)
Hello!
Currently there is rudimentary support for using typing.Annotated in 5.0.0. It is not in the documentation, but there is an example that uses it: https://github.com/epsy/clize/blob/v5.0.0/examples/typed_cli.py
You have to wrap parts of the annotation meant for Clize with Clize[]
, for example your example would read:
def echo(*text:Parameter.REQUIRED,
prefix: Annotated[str, Clize['p']] ='',
suffix: Annotated[str, Clize['s']] = '',
reverse: Annotated[bool, Clize['r']] = False,
repeat: Annotated[int, Clize['n']] = 1,
):
...
There's room to make this better, but this is a start. Let me know if you have feedback or ideas.
from clize.
Is Clize
needed? Can't just be a Literal
?
from clize.
It is kind of needed for me to require it, yes.
See PEP 593 which introduces typings.Annotated
, which says:
Ultimately, the responsibility of how to interpret the annotations (if at all) is the responsibility of the tool or library encountering the Annotated type. A tool or library encountering an Annotated type can scan through the annotations to determine if they are of interest (e.g., using isinstance()).
and then later:
Namespaces are not needed for annotations since the class used by the annotations acts as a namespace.
So it seems like the PEP expects library authors to distinguish different annotations by their type, so unfortunately str
would be too ambiguous.
I hear you on this being very verbose. The PEP has a suggestion on the subject:
T = TypeVar('T')
Const = Annotated[T, my_annotations.CONST]
class C:
def const_method(self: Const[List[int]]) -> int:
Perhaps in the future it could be applied like:
ValueType = TypeVar("ValueType")
ClizeAnnotationsT = TypeVar("ClizeAnnotationsT")
TypeAndClize = typings.Annotated[T, ClizeAnnotationsT]
def main(prefix: TypeAndClize[str, "p"]):
...
Though I think Clize may have to be updated to understand TypeVar/ClizeAnnotationsT
from clize.
Though I think Clize may have to be updated to understand TypeVar/ClizeAnnotationsT
Agreed. And we may need to say something like
def main(a: str, b: Annotated[int, Parameter.REQUIRED]):
...
I don't know how to handle this case without Annotated
...
from clize.
Related Issues (20)
- Support for Google Style Python Docstrings HOT 1
- make pathlib.Path a first citizen by adding default converter HOT 4
- Add intro for `repeated_test` in contribution guidelines
- KeyError when decorator rewrites varargs HOT 1
- Docs do not mention setup or setup.py
- Is this project still alive? HOT 1
- Missing 4.1.1 release HOT 1
- Requesting support for automatic shell completion
- Allow the creation of command aliases HOT 4
- Any issue with `attrs>=20.0.0`? HOT 2
- Proposing a PR to fix a few small typos
- repeated_test no longer compatible with 3.10 HOT 2
- What is going wrong here? HOT 2
- Errors when using dictionnary to specify alternate commands HOT 3
- Any way to give negative number as argument ? HOT 1
- `typing.List[str]` not supported by Clize
- Update version on conda-forge HOT 2
- FR: pre-dispatch options
- More streamlined support for config objects
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clize.