Skip to content
This repository has been archived by the owner on Apr 24, 2023. It is now read-only.

Commit

Permalink
fix check for enum. previously failed when annotated as a typing.Union (
Browse files Browse the repository at this point in the history
  • Loading branch information
mpcusack-color authored Aug 4, 2021
1 parent 685a451 commit c3b62b1
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions clr/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ def resolve_command(query, cache=None):
return namespace_key, command_name


def _is_enum_param(param):
"""Returns whether the given param is annotated as an enum subclass."""
return inspect.isclass(param.annotation) and issubclass(param.annotation, Enum)


def _get_arg_type(param):
"""Returns the type/parser that should be used for the given command Parameter.
Expand All @@ -138,7 +143,7 @@ def _get_arg_type(param):
"""

# Special support for type hinted Enum params.
if issubclass(param.annotation, Enum):
if _is_enum_param(param):

def enum_parser(arg):
arg = arg.upper()
Expand Down Expand Up @@ -642,7 +647,7 @@ def is_positional(arg):
boolean_options.update(arg_names)
elif type(param.default) in (int, float):
numerical_options.update(arg_names)
elif issubclass(param.annotation, Enum):
elif _is_enum_param(param):
enum_options[arg_names[0]] = param.annotation

present_positionally = existing_positional_args > param_index
Expand Down

0 comments on commit c3b62b1

Please sign in to comment.