Stop shadowing variable in customcom's arg handling

* Merge pull request #5027

Stop shadowing variable in customcom's arg handling
This commit is contained in:
Draper 2021-05-19 15:02:47 +01:00 committed by GitHub
commit 3f39a93e59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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