-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Annotated
to add aliases to options
#100
Comments
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 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. |
Is |
It is kind of needed for me to require it, yes. See PEP 593 which introduces
and then later:
So it seems like the PEP expects library authors to distinguish different annotations by their type, so unfortunately 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 |
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 |
The documentation gives an example of how to create aliases:
This, however, causes most linters to warn:
Unresolved reference 'p'
for all the aliases thus defined.
Since Python 3.9,
typing.Annotated
is available to add metadata to annotations, so this could be defined asand linters wouldn't complain.
The text was updated successfully, but these errors were encountered: