Browse Source

Refactored mutable default values.

Signed-off-by: yukihira1992 <[email protected]>
yukihira1992 5 years ago
parent
commit
53d00f7677
3 changed files with 8 additions and 5 deletions
  1. 4 2
      compose/cli/command.py
  2. 2 1
      compose/project.py
  3. 2 2
      compose/service.py

+ 4 - 2
compose/cli/command.py

@@ -40,7 +40,8 @@ SILENT_COMMANDS = {
 }
 
 
-def project_from_options(project_dir, options, additional_options={}):
+def project_from_options(project_dir, options, additional_options=None):
+    additional_options = additional_options or {}
     override_dir = options.get('--project-directory')
     environment_file = options.get('--env-file')
     environment = Environment.from_env_file(override_dir or project_dir, environment_file)
@@ -81,7 +82,8 @@ def set_parallel_limit(environment):
         parallel.GlobalLimit.set_global_limit(parallel_limit)
 
 
-def get_config_from_options(base_dir, options, additional_options={}):
+def get_config_from_options(base_dir, options, additional_options=None):
+    additional_options = additional_options or {}
     override_dir = options.get('--project-directory')
     environment_file = options.get('--env-file')
     environment = Environment.from_env_file(override_dir or base_dir, environment_file)

+ 2 - 1
compose/project.py

@@ -87,10 +87,11 @@ class Project(object):
         return labels
 
     @classmethod
-    def from_config(cls, name, config_data, client, default_platform=None, extra_labels=[]):
+    def from_config(cls, name, config_data, client, default_platform=None, extra_labels=None):
         """
         Construct a Project from a config.Config object.
         """
+        extra_labels = extra_labels or []
         use_networking = (config_data.version and config_data.version != V1)
         networks = build_networks(name, config_data, client)
         project_networks = ProjectNetworks.from_services(

+ 2 - 2
compose/service.py

@@ -185,7 +185,7 @@ class Service(object):
             scale=1,
             pid_mode=None,
             default_platform=None,
-            extra_labels=[],
+            extra_labels=None,
             **options
     ):
         self.name = name
@@ -201,7 +201,7 @@ class Service(object):
         self.scale_num = scale
         self.default_platform = default_platform
         self.options = options
-        self.extra_labels = extra_labels
+        self.extra_labels = extra_labels or []
 
     def __repr__(self):
         return '<Service: {}>'.format(self.name)