Stop shadowing variable in customcom's arg handling

This commit is contained in:
jack1142 2021-05-04 16:53:39 +02:00
parent 7f05841b96
commit 1697d90c53
No known key found for this signature in database
GPG Key ID: 95A9D6BCDE5C1283

View File

@ -694,20 +694,20 @@ class CustomCommands(commands.Cog):
fin = [Parameter("_" + str(i), Parameter.POSITIONAL_OR_KEYWORD) for i in range(high + 1)] fin = [Parameter("_" + str(i), Parameter.POSITIONAL_OR_KEYWORD) for i in range(high + 1)]
for arg in args: for arg in args:
index = int(arg[0]) - low index = int(arg[0]) - low
anno = arg[1][1:] # strip initial colon anno_raw = arg[1][1:] # strip initial colon
if anno.lower().endswith("converter"): if anno_raw.lower().endswith("converter"):
anno = anno[:-9] anno_raw = anno_raw[:-9]
if not anno or anno.startswith("_"): # public types only if not anno_raw or anno_raw.startswith("_"): # public types only
name = "{}_{}".format("text", index if index < high else "final") name = "{}_{}".format("text", index if index < high else "final")
fin[index] = fin[index].replace(name=name) fin[index] = fin[index].replace(name=name)
continue continue
# allow type hinting only for discord.py and builtin types # allow type hinting only for discord.py and builtin types
try: try:
anno = getattr(discord, anno) anno = getattr(discord, anno_raw)
# force an AttributeError if there's no discord.py converter # force an AttributeError if there's no discord.py converter
getattr(commands, anno.__name__ + "Converter") getattr(commands, anno.__name__ + "Converter")
except AttributeError: except AttributeError:
anno = allowed_builtins.get(anno.lower(), Parameter.empty) anno = allowed_builtins.get(anno_raw.lower(), Parameter.empty)
if ( if (
anno is not Parameter.empty anno is not Parameter.empty
and fin[index].annotation is not Parameter.empty and fin[index].annotation is not Parameter.empty