From 53d00f76777d111c192b0674eb89f2073da73cf0 Mon Sep 17 00:00:00 2001 From: yukihira1992 Date: Tue, 14 Jan 2020 20:13:10 +0900 Subject: [PATCH] Refactored mutable default values. Signed-off-by: yukihira1992 --- compose/cli/command.py | 6 ++++-- compose/project.py | 3 ++- compose/service.py | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/compose/cli/command.py b/compose/cli/command.py index cf77237ac..2fabbe18a 100644 --- a/compose/cli/command.py +++ b/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) diff --git a/compose/project.py b/compose/project.py index a7770ddc9..696c8b040 100644 --- a/compose/project.py +++ b/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( diff --git a/compose/service.py b/compose/service.py index 024e7fbde..ebe237b8c 100644 --- a/compose/service.py +++ b/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 ''.format(self.name)