Skip to content

Commit

Permalink
Shift valid origins to a variable
Browse files Browse the repository at this point in the history
  • Loading branch information
inno committed May 26, 2024
1 parent 8a4e85b commit d838266
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions simplecli/simplecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class UnsupportedType(TypeError):
ValueType = Union[type[DefaultIfBool], type[Empty], bool, float, int, str]
ArgDict = dict[str, ValueType]
ArgList = list[str]
valid_origins = (Union, UnionType)


class Param(inspect.Parameter):
Expand Down Expand Up @@ -92,7 +93,7 @@ def __init__(self, *argv: Any, **kwargs: Any) -> None:
def validate_annotation(self, name: str, annotation: object) -> None:
if annotation in get_args(ValueType):
return
if get_origin(annotation) in (Union, UnionType):
if get_origin(annotation) in valid_origins:
return
if annotation is Empty:
return
Expand Down Expand Up @@ -164,7 +165,7 @@ def help_name(self) -> str:

@property
def help_type(self) -> str:
if get_origin(self.annotation) in (Union, UnionType):
if get_origin(self.annotation) in valid_origins:
typelist = ", ".join([a.__name__ for a in self.datatypes])
return f"[{typelist}]"
return self.annotation.__name__
Expand Down

0 comments on commit d838266

Please sign in to comment.