Skip to content

Commit cf49021

Browse files
author
Martin Vrachev
committed
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 <[email protected]>
1 parent 9d3ef85 commit cf49021

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

tests/utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,17 +156,19 @@ class TestServerProcess():
156156
List of additional arguments for the command
157157
which will start the subprocess.
158158
More precisely "python -u <path_to_server> <port> <extra_cmd_args>".
159-
Default is empty list.
159+
When no list is provided, an empty list ("[]") will be assigned to it.
160160
"""
161161

162162

163163
def __init__(self, log, server='simple_server.py',
164-
timeout=10, popen_cwd=".", extra_cmd_args=[]):
164+
timeout=10, popen_cwd=".", extra_cmd_args=None):
165165

166166
self.server = server
167167
self.__logger = log
168168
# Stores popped messages from the queue.
169169
self.__logged_messages = []
170+
if extra_cmd_args is None:
171+
extra_cmd_args = []
170172

171173
try:
172174
self._start_server(timeout, extra_cmd_args, popen_cwd)

0 commit comments

Comments
 (0)