Skip to content

Commit

Permalink
Removed custom value mapping
Browse files Browse the repository at this point in the history
As hash(True) == hash(1), the primary use-case ('yes'<->True |
'no'<->False) is not feasible
  • Loading branch information
Tiger-Tom committed Dec 11, 2023
1 parent 2417b0f commit 3c1c551
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions _rsruntime/lib/rs_userio.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,6 @@ def __init__(self, func: typing.Callable):
self.params = tuple(inspect.signature(func).parameters.values())[1:]
self.args_line = self.render_args(self.params)

custom_vals_to_strs = {
True: Config['chat_commands/help/formatter/special_literal/true_yes'], False: Config['chat_commands/help/formatter/special_literal/false_no'],
}; custom_strs_to_vals = {v: k for k,v in custom_vals_to_strs.items()}

def parse_args(self, *args) -> typing.Generator[typing.Any, None, None]:
eargs = enumerate(args)
prms = iter(self.params)
Expand All @@ -165,7 +161,6 @@ def parse_args(self, *args) -> typing.Generator[typing.Any, None, None]:
raise ValueError(f'Expected one of {p.annotation.__args__}, not {a}')
yield a
elif isinstance(p.annotation, type): yield p.annotation(a)
elif a in custom_strs_to_vals: yield custom_strs_to_vals[a]
else: yield a
for p in prms:
if p.kind == p.VAR_POSITIONAL: yield ()
Expand Down Expand Up @@ -194,8 +189,7 @@ def render_arg(cls, arg: inspect.Parameter) -> str:
return braks.format(argstr=Config['chat_commands/help/formatter/argument/joiners/tokens'].join(build))
@classmethod
def render_annotation(cls, ann: typing.Any) -> str:
if ann in cls.custom_vals_to_strs: return cls.custom_vals_to_strs[ann]
elif ann in {None, type(None)}: return 'None'
if ann in {None, type(None)}: return 'None'
elif getattr(ann, '__origin__', None) is typing.Literal:
return Config['chat_commands/help/formatter/argument/joiners/literals'].join(cls.render_annotation(aa) for aa in ann.__args__ if aa not in {None, type(None)})
elif (getattr(ann, '__origin__', None) is typing.Union) or isinstance(ann, UnionType):
Expand Down

0 comments on commit 3c1c551

Please sign in to comment.