diff options
author | Maxim P. DEMENTYEV <dememax@hotmail.com> | 2024-09-13 14:30:11 +0200 |
---|---|---|
committer | Maxim P. Dementiev <maxime.dementiev@kalyzee.com> | 2024-11-17 11:26:58 +0100 |
commit | 46ccde7b7d4224f71a9168917eb372293657d269 (patch) | |
tree | 81b94ab3d41c0505665cd043769540cf57f0e60a | |
parent | a510c249552734fe7ad1bf29541815663b97caec (diff) |
Fixing B006 - mutable objects as function argument defaults using None and if
Part-of: <https://gitlab.freedesktop.org/gstreamer/cerbero/-/merge_requests/1566>
-rw-r--r-- | cerbero/build/cookbook.py | 10 | ||||
-rw-r--r-- | cerbero/commands/__init__.py | 4 | ||||
-rw-r--r-- | cerbero/commands/bundlesource.py | 2 | ||||
-rw-r--r-- | cerbero/commands/cache.py | 12 | ||||
-rw-r--r-- | cerbero/commands/debugpackages.py | 4 | ||||
-rw-r--r-- | cerbero/commands/deps.py | 4 | ||||
-rw-r--r-- | cerbero/commands/fetch.py | 4 | ||||
-rw-r--r-- | cerbero/commands/graph.py | 4 | ||||
-rw-r--r-- | cerbero/packages/ninja_syntax.py | 5 | ||||
-rw-r--r-- | cerbero/packages/packagesstore.py | 6 | ||||
-rw-r--r-- | cerbero/packages/windows/wix_on_ninja.py | 4 | ||||
-rw-r--r-- | cerbero/tools/depstracker.py | 6 | ||||
-rw-r--r-- | cerbero/utils/shell.py | 4 |
13 files changed, 50 insertions, 19 deletions
diff --git a/cerbero/build/cookbook.py b/cerbero/build/cookbook.py index 1499a5c2..86d84ee0 100644 --- a/cerbero/build/cookbook.py +++ b/cerbero/build/cookbook.py @@ -56,8 +56,8 @@ class RecipeStatus(object): @type file_hash: int """ - def __init__(self, filepath, steps=[], needs_build=True, mtime=time.time(), built_version='', file_hash=0): - self.steps = steps + def __init__(self, filepath, steps=None, needs_build=True, mtime=time.time(), built_version='', file_hash=0): + self.steps = [] if steps is None else steps self.needs_build = needs_build self.mtime = mtime self.filepath = filepath @@ -339,7 +339,11 @@ class CookBook(object): except IOError as ex: m.warning(_('Could not cache the CookBook: %s') % ex) - def _find_deps(self, recipe, state={}, ordered=[]): + def _find_deps(self, recipe, state=None, ordered=None): + if state is None: + state = {} + if ordered is None: + ordered = [] if state.get(recipe, 'clean') == 'processed': return if state.get(recipe, 'clean') == 'in-progress': diff --git a/cerbero/commands/__init__.py b/cerbero/commands/__init__.py index c90080ae..863ae75f 100644 --- a/cerbero/commands/__init__.py +++ b/cerbero/commands/__init__.py @@ -31,8 +31,8 @@ class Command: doc = '' name = None - def __init__(self, arguments=[]): - self.arguments = arguments + def __init__(self, arguments=None): + self.arguments = [] if arguments is None else arguments def run(self, config, args): """The body of the command""" diff --git a/cerbero/commands/bundlesource.py b/cerbero/commands/bundlesource.py index 68ee7f89..588af02e 100644 --- a/cerbero/commands/bundlesource.py +++ b/cerbero/commands/bundlesource.py @@ -31,7 +31,7 @@ class BundleSource(Command): doc = N_('Bundle Source code of recipes and Cerbero') name = 'bundle-source' - def __init__(self, args=[]): + def __init__(self, args=None): args = [ ArgparseArgument('bundlepackages', nargs='+', help=_('packages to bundle')), ArgparseArgument('--add-recipe', action='append', default=[], help=_('additional recipes to bundle')), diff --git a/cerbero/commands/cache.py b/cerbero/commands/cache.py index 7b04f695..b046d2e2 100644 --- a/cerbero/commands/cache.py +++ b/cerbero/commands/cache.py @@ -39,7 +39,9 @@ class BaseCache(Command): log_size = 10 dry_run = False - def __init__(self, args=[]): + def __init__(self, args=None): + if args is None: + args = [] args += [ ArgparseArgument( '--commit', action='store', type=str, default='HEAD', help='the commit to pick artifact from' @@ -305,7 +307,9 @@ class GenCache(BaseCache): doc = N_('Generate build cache from current state.') name = 'gen-cache' - def __init__(self, args=[]): + def __init__(self, args=None): + if args is None: + args = [] BaseCache.__init__(self, args) def create_tarball_tarfile(self, workdir, out_file, *in_files, exclude=None): @@ -405,7 +409,9 @@ class UploadCache(BaseCache): doc = N_('Build build cache to external storage.') name = 'upload-cache' - def __init__(self, args=[]): + def __init__(self, args=None): + if args is None: + args = [] BaseCache.__init__(self, args) def upload_dep(self, config, args, deps): diff --git a/cerbero/commands/debugpackages.py b/cerbero/commands/debugpackages.py index df50c5aa..ffa2a907 100644 --- a/cerbero/commands/debugpackages.py +++ b/cerbero/commands/debugpackages.py @@ -58,7 +58,9 @@ class DebugPackages(Command): m.message('Found duplicates files in packages:') m.message('%r' % duplicates) - def find_orphan_files(self, allfiles, prefix, excludes=[]): + def find_orphan_files(self, allfiles, prefix, excludes=None): + if excludes is None: + excludes = [] cmd = ['find', '.', '-type', 'f'] for x in excludes: cmd += ['(', '!', '-name', x, ')'] diff --git a/cerbero/commands/deps.py b/cerbero/commands/deps.py index 91bea222..1386370e 100644 --- a/cerbero/commands/deps.py +++ b/cerbero/commands/deps.py @@ -66,7 +66,9 @@ class Deps(Command): m.message(recipe.name) else: - def print_dep(cookbook, recipe, level=0, already_shown=[]): + def print_dep(cookbook, recipe, level=0, already_shown=None): + if already_shown is None: + already_shown = [] m.message('%s%s' % (' ' * 3 * level, recipe.name)) already_shown.append(recipe) for r in [cookbook.get_recipe(x) for x in recipe.list_deps()]: diff --git a/cerbero/commands/fetch.py b/cerbero/commands/fetch.py index db12d607..1a9171d8 100644 --- a/cerbero/commands/fetch.py +++ b/cerbero/commands/fetch.py @@ -40,7 +40,9 @@ NUMBER_OF_JOBS_IF_USED = 2 * determine_num_of_cpus() class Fetch(Command): - def __init__(self, args=[]): + def __init__(self, args=None): + if args is None: + args = [] args.append( ArgparseArgument( '--reset-rdeps', diff --git a/cerbero/commands/graph.py b/cerbero/commands/graph.py index 40bc5992..6f2ec301 100644 --- a/cerbero/commands/graph.py +++ b/cerbero/commands/graph.py @@ -101,7 +101,9 @@ class Graph(Command): shell.new_call(['dot', '-Tsvg', tmp.name, '-o', output]) m.message('Dependency graph for %s generated at %s' % (name, output)) - def _dot_gen(self, name, graph_type, already_parsed=[]): + def _dot_gen(self, name, graph_type, already_parsed=None): + if already_parsed is None: + already_parsed = [] already_parsed.append(name) if graph_type == GraphType.RECIPE: deps = self.cookbook.get_recipe(name).list_deps() diff --git a/cerbero/packages/ninja_syntax.py b/cerbero/packages/ninja_syntax.py index 9289b85d..3f967b1b 100644 --- a/cerbero/packages/ninja_syntax.py +++ b/cerbero/packages/ninja_syntax.py @@ -214,13 +214,16 @@ def escape(string: str) -> str: return string.replace('$', '$$') -def expand(string: str, vars: Dict[str, str], local_vars: Dict[str, str] = {}) -> str: +def expand(string: str, vars: Dict[str, str], local_vars: Dict[str, str] = None) -> str: """Expand a string containing $vars as Ninja would. Note: doesn't handle the full Ninja variable syntax, but it's enough to make configure.py's use of it work. """ + if local_vars is None: + local_vars = {} + def exp(m: Match[str]) -> str: var = m.group(1) if var == '$': diff --git a/cerbero/packages/packagesstore.py b/cerbero/packages/packagesstore.py index bfd50d4d..563ce4c5 100644 --- a/cerbero/packages/packagesstore.py +++ b/cerbero/packages/packagesstore.py @@ -120,7 +120,11 @@ class PackagesStore(object): self._packages[package.name] = package def _list_metapackage_deps(self, metapackage): - def get_package_deps(package_name, visited=[], depslist=[]): + def get_package_deps(package_name, visited=None, depslist=None): + if visited is None: + visited = [] + if depslist is None: + depslist = [] if package_name in visited: return visited.append(package_name) diff --git a/cerbero/packages/windows/wix_on_ninja.py b/cerbero/packages/windows/wix_on_ninja.py index 35f2ae16..151b191f 100644 --- a/cerbero/packages/windows/wix_on_ninja.py +++ b/cerbero/packages/windows/wix_on_ninja.py @@ -59,8 +59,8 @@ class Light(object): options = {} - def __init__(self, extra=[]): - self.options['extra'] = extra + def __init__(self, extra=None): + self.options['extra'] = [] if extra is None else extra def compile(self, writer: Writer, objects: list[str], msi_name: str, merge_module=False, implicit_deps=None): """ diff --git a/cerbero/tools/depstracker.py b/cerbero/tools/depstracker.py index b7098805..582125e4 100644 --- a/cerbero/tools/depstracker.py +++ b/cerbero/tools/depstracker.py @@ -26,7 +26,11 @@ class RecursiveLister: def list_file_deps(self, prefix, path): raise NotImplementedError() - def find_deps(self, prefix, lib, state={}, ordered=[]): + def find_deps(self, prefix, lib, state=None, ordered=None): + if state is None: + state = {} + if ordered is None: + ordered = [] if state.get(lib, 'clean') == 'processed': return if state.get(lib, 'clean') == 'in-progress': diff --git a/cerbero/utils/shell.py b/cerbero/utils/shell.py index c5b8af02..9c957b61 100644 --- a/cerbero/utils/shell.py +++ b/cerbero/utils/shell.py @@ -532,8 +532,10 @@ def find_files(pattern, prefix): return glob.glob(os.path.join(prefix, pattern)) -def prompt(message, options=[]): +def prompt(message, options=None): """Prompts the user for input with the message and options""" + if options is None: + options = [] if len(options) != 0: message = '%s [%s] ' % (message, '/'.join(options)) res = input(message) |