Is there a way to parametrize typing.Annotated
s metadata?
#2023
Unanswered
MilanStaffehl
asked this question in
Q&A
Replies: 1 comment 1 reply
-
Linking python/mypy#18925 for related discussion |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am trying to make a type that behaves as
int
on type checking, but which has additional metadata on runtime (specifically for the purpose of specifying a subtype ofint
).typing.Annotated
seems the obvious choice to make this work. However, I would like to create a type (alias) which allows setting the metadata of an annotatedint
as a parameter.A naive first approach might look something like this:
Of course this does not work, since type checkers will see
IntMeta
as onlyint
, andint
does not take any type parameters.So, my question: is this possible in any way - whether using
Annotated
, or a custom type, or any other way?Beta Was this translation helpful? Give feedback.
All reactions