[commands] Add support for typing.Annotated

This commit is contained in:
Rapptz
2022-04-22 06:21:10 -04:00
parent ab33551553
commit 5fcd4e411f
3 changed files with 35 additions and 0 deletions

View File

@ -625,6 +625,9 @@ def get_supported_annotation(
if hasattr(annotation, '__discord_app_commands_transform__'):
return (annotation.metadata, MISSING)
if hasattr(annotation, '__metadata__'):
return get_supported_annotation(annotation.__metadata__[0])
if inspect.isclass(annotation):
if issubclass(annotation, Transformer):
return (annotation, MISSING)

View File

@ -161,6 +161,12 @@ def get_signature_parameters(
if annotation is Greedy:
raise TypeError('Unparameterized Greedy[...] is disallowed in signature.')
if hasattr(annotation, '__metadata__'):
# Annotated[X, Y] can access Y via __metadata__
metadata = annotation.__metadata__
if len(metadata) >= 1:
annotation = metadata[0]
if isinstance(annotation, discord.app_commands.transformers._TransformMetadata):
annotation = annotation.metadata