Skip to content

Commit

Permalink
_typing.get_origin fails on Literal with Python 3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
pchanial committed Sep 20, 2023
1 parent 7f1c010 commit a2fba85
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions typer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,9 +790,14 @@ def get_click_type(
case_sensitive=parameter_info.case_sensitive,
)

# we cast to the return type of typing.origin. _typing.get_origin has another signature.
origin = cast(Union[Any, None], get_origin(annotation))
args = get_args(annotation)
if sys.version_info < (3, 7):
origin = annotation.__class__
args = getattr(annotation, "__values__", None)
else:
# we cast to the return type of typing.get_origin. _typing.get_origin has another signature.
origin = cast(Union[Any, None], get_origin(annotation))
args = get_args(annotation)

if origin is Literal:
return click.Choice(
args,
Expand Down

0 comments on commit a2fba85

Please sign in to comment.