From 0ca06e39a9bc075ffef03bc54769941a719284ae Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Wed, 13 Dec 2023 11:29:22 +0000 Subject: [PATCH] refactor: fix dangerous default argument MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Do not use a mutable like `list` or `dictionary` as a default value to an argument. Python’s default arguments are evaluated once when the function is defined. Using a mutable default argument and mutating it will mutate that object for all future calls to the function as well. --- cogs/skyeval.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cogs/skyeval.py b/cogs/skyeval.py index 01726e9..619da71 100644 --- a/cogs/skyeval.py +++ b/cogs/skyeval.py @@ -21,7 +21,9 @@ def insert_returns(body): if isinstance(body[-1], ast.With): insert_returns(body[-1].body) -async def execute_python_code(code, env={}): +async def execute_python_code(code, env=None): + if env is None: + env = {} try: fn_name = "_eval_expr" cmd = "\n".join(f" {i}" for i in code.splitlines())