Skip to content

Commit

Permalink
fix: Fix param parsing logic again
Browse files Browse the repository at this point in the history
  • Loading branch information
seriaati committed Sep 8, 2024
1 parent c382378 commit e0bbbb1
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions line/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,16 @@ def __get_param_type(annotation: Any) -> ParamType:

if is_optional:
annotation = next((arg for arg in args if arg is not type(None)), None)
print(annotation)

# Now check the base type
if annotation is int:
if annotation == "int":
return ParamType.INTEGER
if annotation is bool:
if annotation == "bool":
return ParamType.BOOLEAN
if annotation is float:
if annotation == "float":
return ParamType.FLOAT
if annotation is str:
if annotation == "str":
return ParamType.STRING
return ParamType.UNKNOWN

Expand All @@ -153,6 +154,7 @@ def _parse_params(

if value is not None:
param_type = BaseBot.__get_param_type(annotations[param.name])
print(param.name, param_type.name)

if param_type is ParamType.INTEGER:
if not value.isdigit():
Expand Down Expand Up @@ -245,7 +247,7 @@ async def process_command(self, text: str, user_id: str, reply_token: str) -> An
params = sig.parameters
try:
args, kwargs = self._parse_params(
dict(params), data, func.__annotations__
dict(params), data, func.original_function.__annotations__
)
except Exception as e:
raise ParamParseError(cmd, e) from e
Expand Down

0 comments on commit e0bbbb1

Please sign in to comment.