Fix nested Annotated calls not resolving

This commit is contained in:
Rapptz
2022-08-17 10:38:12 -04:00
parent 8dd186cf1e
commit 1c7747fe9d
7 changed files with 70 additions and 18 deletions

View File

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

View File

@ -160,12 +160,6 @@ 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]
params[name] = parameter.replace(annotation=annotation)
return params

View File

@ -184,11 +184,6 @@ def get_flags(namespace: Dict[str, Any], globals: Dict[str, Any], locals: Dict[s
flag.name = name
annotation = flag.annotation = resolve_annotation(flag.annotation, globals, locals, cache)
if hasattr(annotation, '__metadata__'):
# Annotated[X, Y] can access Y via __metadata__
metadata = annotation.__metadata__
if len(metadata) >= 1:
annotation = flag.annotation = metadata[0]
if flag.default is MISSING and hasattr(annotation, '__commands_is_flag__') and annotation._can_be_constructible():
flag.default = annotation._construct_default

View File

@ -1062,6 +1062,11 @@ def evaluate_annotation(
cache[tp] = evaluated
return evaluated
if hasattr(tp, '__metadata__'):
# Annotated[X, Y] can access Y via __metadata__
metadata = tp.__metadata__[0]
return evaluate_annotation(metadata, globals, locals, cache)
if hasattr(tp, '__args__'):
implicit_str = True
is_literal = False