Skip to content

Commit 1cb2a0e

Browse files
committed
Fixed problems with converter
1 parent b4ffa1d commit 1cb2a0e

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

dico_command/bot.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import traceback
66
import importlib
77
import dico
8-
from contextlib import suppress
98
from .command import Command
109
from .context import Context
1110
from .converter import AVAILABLE_CONVERTERS, ConverterBase
@@ -254,11 +253,11 @@ def load_module(self, import_path: str):
254253
importlib.reload(module)
255254
if module.__name__ in self.modules:
256255
raise ModuleAlreadyLoaded(path=import_path)
257-
self.modules.append(module.__name__)
258256
if hasattr(module, "load"):
259257
module.load(self)
260258
else:
261259
raise MissingLoadFunction(path=import_path)
260+
self.modules.append(module.__name__)
262261
except ImportError:
263262
raise InvalidModule(path=import_path)
264263

dico_command/converter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ async def convert(self, ctx: "Context", value: str) -> Optional[T]:
6363

6464

6565
class GuildMemberConverter(ConverterBase):
66-
CONVERT_TYPE =dico. GuildMember
66+
CONVERT_TYPE = dico.GuildMember
6767

6868
def __init__(self, bot: "Bot"):
6969
super().__init__(bot)

dico_command/utils.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def smart_split(ipt: str, args_data: dict, subcommand: bool = False) -> typing.T
3939
last_arg = args_data[args_name[-1]]
4040
var_positional_in = True in [*map(lambda n: n["kind"] == n["kind"].VAR_POSITIONAL, args_data.values())]
4141
keyword_only_count = len([x for x in args_data.values() if x["kind"] == x["kind"].KEYWORD_ONLY])
42+
all_optional = bool([x for x in args_data.values() if x["required"] is False])
4243
if len(args_data) == 1:
4344
if last_arg["kind"] == last_arg["kind"].VAR_POSITIONAL:
4445
if ipt:
@@ -54,14 +55,17 @@ def smart_split(ipt: str, args_data: dict, subcommand: bool = False) -> typing.T
5455
return [initial_split[0]] if initial_split else [], {}
5556
if (len(initial_split) == len(args_data) and not keyword_only_count) or last_arg["kind"] == last_arg["kind"].VAR_POSITIONAL: # assuming this matches
5657
return initial_split, {}
57-
if len(initial_split) != len(args_data) and not var_positional_in and not keyword_only_count:
58+
if len(initial_split) != len(args_data) and not var_positional_in and not keyword_only_count and not all_optional:
5859
raise ValueError("argument count does not match.")
5960
if keyword_only_count > 1:
6061
raise AttributeError("maximum keyword-only param number is 1.")
6162
args = []
6263
kwargs = {}
6364
if not ipt.replace(" ", ""):
64-
raise ValueError("empty input.")
65+
for v in args_data.values():
66+
if v["required"]:
67+
raise ValueError("empty input.")
68+
return [], {}
6569
for i, x in enumerate(args_data.items()):
6670
k, v = x
6771
if v["kind"] == v["kind"].KEYWORD_ONLY:
@@ -70,7 +74,10 @@ def smart_split(ipt: str, args_data: dict, subcommand: bool = False) -> typing.T
7074
kwargs[k] = ipt or None
7175
# TODO: fix kwargs is added even if it is not present
7276
break
73-
args.append(initial_split[i])
77+
if i < len(initial_split):
78+
args.append(initial_split[i])
79+
else:
80+
break
7481
ipt = ipt.split(initial_split[i], 1)[-1].lstrip()
7582
return args, kwargs
7683

0 commit comments

Comments
 (0)