factorization of auto-detected arguments

This commit is contained in:
Shadow15510 2023-06-12 18:29:58 +02:00
parent 490f6b7e8f
commit 31b0f29a9e
2 changed files with 13 additions and 13 deletions

View File

@ -37,6 +37,8 @@ def hour(bot, msg):
@api.command("wiki", desc="wiki <recherche> [limite=1]\nFait une recherche wikipedia.")
def wiki(bot, msg, text: str, limit: int=1):
if not (1 < limit <= 10):
limit = 1
session = requests.Session()
params = {
'action': 'opensearch',

View File

@ -271,21 +271,19 @@ def check_args(func, *input_args):
if len(input_args) < required_args:
return None
# construction of a list of tuples (type, default_value) for each arguments
check_args = []
for index, arg_type in enumerate(annotations.values()):
if index + 1 > required_args:
check_args.append((arg_type, defaults[index - required_args]))
else:
check_args.append((arg_type, None))
# transtypes each given arguments to its target type
converted_args = []
for index, arg in enumerate(check_args):
if len(input_args) > index:
converted_args.append(convert(input_args[index], *check_args[index]))
for index, arg_type in enumerate(annotations.values()):
# construction of a tuple (type, default_value) for each expected argument
if index + 1 > required_args:
check_args = (arg_type, defaults[index - required_args])
else:
converted_args.append(check_args[index][1])
check_args = (arg_type, None)
# transtypes each given arguments to its target type
if len(input_args) > index:
converted_args.append(convert(input_args[index], *check_args))
else:
converted_args.append(check_args[1])
# if an argument has no default value and transtyping has failed
if None in converted_args: