1525 if state:
1526 return
1527 # Creates temporary folder for storing the audio file
1528 import os1529 if not os.path.isdir("./tempMusic"):
1530 os.mkdir("./tempMusic")
1531 if not os.path.isdir("./tempMusic/" + str(ctx.guild.id)):
325 self.subcommands: list[BridgeCommand] = []
326
327 self.mapped: SlashCommand | None = None
328 if map_to := getattr(callback, "__custom_map_to__", None):329 kwargs.update(map_to)
330 self.mapped = self.slash_variant.command(**kwargs)(callback)
331
440 else:
441 func.__guild_only__ = True
442
443 from ..commands import guild_only444
445 return guild_only()(func)
446
464 else:
465 func.__nsfw__ = True
466
467 from ..commands import is_nsfw468
469 return is_nsfw()(func)
470
486 """
487
488 def predicate(func: Callable | ApplicationCommand):
489 from ..commands import has_permissions490
491 func = has_permissions(**perms)(func)
492 _perms = Permissions(**perms)
The local variable name hides the variable defined in the outer scope, making it inaccessible and might confuse.
filename = 'myfile.txt'
def read_file(filename): # This shadows the global `filename`
with open(filename) as file:
return file.readlines()
FILENAME = 'myfile.txt' # renamed global to UPPER_CASE as convention
def read_file(filename):
with open(filename) as file:
return file.readlines()
Another usual suspect of this is when you use the same parameter name inside a function as the global variable you are using. For example:
def run_app(app):
# This `app` shadows the global app...
app.run()
if __name__ == '__main__':
app = MyApp() # This is a global variable!
run_app(app)
To avoid this re-defining of a global, consider not defining app
as a global, but inside a main()
function instead:
def run_app(app):
# There is no longer a global `app` variable.
app.run()
def main():
app = MyApp()
run_app(app)
if __name__ == '__main__':
main()