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 <mvrachev@vmware.com>
This commit is contained in:
Martin Vrachev 2020-11-19 14:41:12 +02:00
parent 9d3ef85192
commit cf4902131e

View file

@ -156,17 +156,19 @@ class TestServerProcess():
List of additional arguments for the command
which will start the subprocess.
More precisely "python -u <path_to_server> <port> <extra_cmd_args>".
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)