Skip to content

Return Annotated[Foo, ...] from Foo.__class_getitem__ #1229

Answered by erictraut
jfktrey asked this question in Q&A
Discussion options

You must be logged in to vote

There's currently no way to use non-type annotations in a generic type alias. Type aliases are intended to be used with types, not other forms of annotation. When you use Annotated, you need to spell out the entire annotation.

Could you describe in more detail what you are using the annotations for in this case? What does 'bar' and 'some_changing_value' represent in your use case? I'm wondering if they could be modeled as types within the type system, which would allow you to use normal type annotations and type aliases rather than falling back on Annotated.

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@jfktrey
Comment options

@jfktrey
Comment options

Answer selected by jfktrey
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants