Skip to content

Conversation

@zarch
Copy link

@zarch zarch commented Sep 3, 2024

See discussion for further details and sample code.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 3, 2024

📝 Docs preview for commit e13d1d8 at: https://45f079b8.typertiangolo.pages.dev

Copy link
Member

@svlandeg svlandeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @zarch, thanks for the contribution, we appreciate it!

The CI is currently failing - could you look into that? I'll put the PR in draft in the meantime. The review process will go much smoother once the CI is green 😉

@svlandeg svlandeg changed the title Add support for typing.TypeAliasType as valid parameter type. ✨ Add support for typing.TypeAliasType as valid parameter type. Sep 3, 2024
@svlandeg svlandeg added the feature New feature, enhancement or request label Sep 3, 2024
@svlandeg svlandeg marked this pull request as draft September 3, 2024 08:39
@github-actions
Copy link
Contributor

github-actions bot commented Sep 3, 2024

📝 Docs preview for commit c97aff6 at: https://8682c9ff.typertiangolo.pages.dev

@zarch
Copy link
Author

zarch commented Sep 3, 2024

@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

@zarch zarch marked this pull request as ready for review September 4, 2024 08:20
@lachaib
Copy link

lachaib commented May 5, 2025

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 reaching get_click_type
    e.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

@zarch
Copy link
Author

zarch commented Jul 31, 2025

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!

@lachaib
Copy link

lachaib commented Aug 1, 2025

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

@github-actions github-actions bot added the conflicts Automatically generated when a PR has a merge conflict label Sep 1, 2025
@github-actions

This comment was marked as outdated.

@github-actions github-actions bot removed the conflicts Automatically generated when a PR has a merge conflict label Oct 31, 2025
@github-actions
Copy link
Contributor

📝 Docs preview

Last commit 110972a at: https://3a314827.typertiangolo.pages.dev

@svlandeg svlandeg marked this pull request as draft October 31, 2025 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature, enhancement or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants