From cf4902131efaf2f39109c5e2f883d91d18edc06f Mon Sep 17 00:00:00 2001 From: Martin Vrachev Date: Thu, 19 Nov 2020 14:41:12 +0200 Subject: [PATCH] Fix empty list as a default value for function arg This quote from the Google Python style guide made me realize why empty list as a default value for an argument could be dangerous: "Default arguments are evaluated once at module load time. This may cause problems if the argument is a mutable object such as a list or a dictionary. If the function modifies the object (e.g., by appending an item to a list), the default value is modified." Read more here: https://google.github.io/styleguide/pyguide.html#2123-cons Signed-off-by: Martin Vrachev --- tests/utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/utils.py b/tests/utils.py index 5d4e5724..ea85d320 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -156,17 +156,19 @@ class TestServerProcess(): List of additional arguments for the command which will start the subprocess. More precisely "python -u ". - Default is empty list. + When no list is provided, an empty list ("[]") will be assigned to it. """ def __init__(self, log, server='simple_server.py', - timeout=10, popen_cwd=".", extra_cmd_args=[]): + timeout=10, popen_cwd=".", extra_cmd_args=None): self.server = server self.__logger = log # Stores popped messages from the queue. self.__logged_messages = [] + if extra_cmd_args is None: + extra_cmd_args = [] try: self._start_server(timeout, extra_cmd_args, popen_cwd)