typer
typer copied to clipboard
✨ Add support for `typing.TypeAliasType` as valid parameter type.
📝 Docs preview for commit e13d1d822f5d5190270f89fc545079f143363bcb at: https://45f079b8.typertiangolo.pages.dev
📝 Docs preview for commit c97aff6ca4c3304f053da3bda10a728c35185e14 at: https://8682c9ff.typertiangolo.pages.dev
@svlandeg I've fixed all the CI. To properly handle the TypeAliasType I also have to update mypy version to v1.10, I don't know if this might be an issue.
The only failing check is the one using Python 3.7 (not supported), se my other PR to bump the minimum requirement to Python 3.8. Therefore, these change should be put on queue with: 🔥 Drop support for Python 3.7
Hello,
I was digging on the topic on that matter and I think this PR is incomplete:
- one of the things I'm trying to achieve is to share parameter definition across sub-commands, e.g.
type Name = Annotated[str, Argument(help="The human in front of the screen")]
@app.command()
def greet(name: Name):
echo(f"Hello {name}")
@app.command()
def farewell(name: Name):
echo(f"Good bye, {name}")
To get it working, I had to modify utils._split_annotation_from_typer_annotations to enable extraction of ParameterInfo from the type alias
(basically added a recursive call to same method with base_annotation.__value__)
- also, because it can be useful to support nested annotations under the
TypeAliasType, I had to unwrap a bit further down the types before reachingget_click_typee.g.
from typing import Doc
from pydantic import PositiveInt, validate_call
type Name = Annotated[str, Doc("An human's full name")]
type Age = Annotated[PositiveInt, Doc("An human's age")]
type Identity = tuple[Name, Age]
@app.command()
@validate_call
def register_to_vote(user_identity: Identity):
...
Happy to discuss/help on this topic
Hi @lachaib, Sorry for the delayed response. To help move this forward, could you please:
Share the branch/commit - Do you have a specific branch or commit with these changes that can be pushed to this branch? Provide test coverage - Could you include unit tests that cover the additional functionalities you've implemented?
This will help ensure we can properly review and integrate your changes. Thanks!
Hi @lachaib, Sorry for the delayed response. To help move this forward, could you please:
Share the branch/commit - Do you have a specific branch or commit with these changes that can be pushed to this branch? Provide test coverage - Could you include unit tests that cover the additional functionalities you've implemented?
This will help ensure we can properly review and integrate your changes. Thanks!
Hello @zarch ,
This is not a ready-to-merge contribution but I pushed my state so that you can get inspiration and consolidate this existing pull request.
https://github.com/lachaib/typer/tree/pep695
Thanks a lot
This pull request has a merge conflict that needs to be resolved.
📝 Docs preview
Last commit 110972ac54d65d46dc39781096c7dd0f1d2db885 at: https://3a314827.typertiangolo.pages.dev