Skip to content

Commit

Permalink
revert type
Browse files Browse the repository at this point in the history
  • Loading branch information
b8zhong committed Feb 6, 2025
1 parent d32c9e0 commit 97ab3c3
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions python-threatexchange/threatexchange/cli/config_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,26 +184,24 @@ def _add_argument(cls, ap: argparse._ArgumentGroup, field: Field) -> None:
), "rework class to not have forward ref"

origin = t.get_origin(field.type)
argparse_type: t.Union[t.Type[t.Any], t.Callable[[str], t.Any]] = field.type
argparse_type: t.Callable[[str], t.Any] = field.type
metavar: str
if isinstance(field.type, type) and issubclass(field.type, Enum):
argparse_type = common.argparse_choices_pre_type(
[m.name for m in field.type],
lambda s: getattr(field.type, s),
lambda s: field.type[s],
)
metavar = f"[{','.join(m.name for m in field.type)}]"
elif origin is not None:
arg_type = t.get_args(field.type)[0]
if isinstance(origin, type) and issubclass(
origin, collections.abc.Collection
):
def make_collection(s: str) -> t.Any:
return list(arg_type(p.strip()) for p in s.split(","))
argparse_type = make_collection
argparse_type = lambda s: origin(arg_type(p.strip()) for p in s.split(",")) # type: ignore # mypy not smart enough for origin == type
metavar = f"{arg_type.__name__}[,{arg_type.__name__}[,...]]"
elif origin == t.Union: # Should this be is?
argparse_type = arg_type
metavar = getattr(arg_type, "__name__", str(arg_type))
metavar = arg_type.__name__
else:
raise AssertionError(
f"Unhandled complex type for {field.name}: {field.type}"
Expand Down

0 comments on commit 97ab3c3

Please sign in to comment.