osbuild: avoid [] as default value
Using `[]` as default value for arguments makes `pylint` complain. The reason is that it creates an array statically at the time the function is parsed, rather than dynamically on invocation of the function. This means, when you append to this array, you change the global instance and every further invocation of that function works on this modified array. While our use-cases are safe, this is indeed a common pitfall. Lets avoid using this and resort to `None` instead. This silences a lot of warnings from pylint about "dangerous use of []".
This commit is contained in:
parent
14ada360bd
commit
46526cf205
4 changed files with 8 additions and 8 deletions
|
|
@ -95,7 +95,7 @@ def parse_arguments(sys_argv):
|
|||
|
||||
|
||||
# pylint: disable=too-many-branches
|
||||
def osbuild_cli(*, sys_argv=[]):
|
||||
def osbuild_cli(*, sys_argv):
|
||||
args = parse_arguments(sys_argv)
|
||||
manifest = parse_manifest(args.manifest_path)
|
||||
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ class ValidationResult:
|
|||
self.errors.add(err)
|
||||
return self
|
||||
|
||||
def merge(self, result: "ValidationResult", *, path=[]):
|
||||
def merge(self, result: "ValidationResult", *, path=None):
|
||||
"""Merge all errors of `result` into this
|
||||
|
||||
Merge all the errors of in `result` into this,
|
||||
|
|
@ -137,7 +137,7 @@ class ValidationResult:
|
|||
"""
|
||||
for err in result:
|
||||
err = copy.deepcopy(err)
|
||||
err.rebase(path)
|
||||
err.rebase(path or [])
|
||||
self.errors.add(err)
|
||||
|
||||
def as_dict(self):
|
||||
|
|
|
|||
|
|
@ -271,7 +271,7 @@ class Socket(contextlib.AbstractContextManager):
|
|||
|
||||
return (payload, fdset, msg[3])
|
||||
|
||||
def send(self, payload: object, *, destination: Optional[str] = None, fds: list = []):
|
||||
def send(self, payload: object, *, destination: Optional[str] = None, fds: Optional[list] = None):
|
||||
"""Send Message
|
||||
|
||||
Send a new message via this socket. This operation is synchronous. The
|
||||
|
|
@ -299,7 +299,7 @@ class Socket(contextlib.AbstractContextManager):
|
|||
|
||||
serialized = json.dumps(payload).encode()
|
||||
cmsg = []
|
||||
if len(fds) > 0:
|
||||
if fds and len(fds) > 0:
|
||||
cmsg.append((socket.SOL_SOCKET, socket.SCM_RIGHTS, array.array("i", fds)))
|
||||
|
||||
n = self._socket.sendmsg([serialized], cmsg, 0, destination)
|
||||
|
|
|
|||
|
|
@ -227,7 +227,7 @@ class OSBuild(contextlib.AbstractContextManager):
|
|||
print(data_stderr)
|
||||
print("-- END ---------------------------------")
|
||||
|
||||
def compile(self, data_stdin, checkpoints=[]):
|
||||
def compile(self, data_stdin, checkpoints=None):
|
||||
"""Compile an Artifact
|
||||
|
||||
This takes a manifest as `data_stdin`, executes the pipeline, and
|
||||
|
|
@ -247,7 +247,7 @@ class OSBuild(contextlib.AbstractContextManager):
|
|||
cmd_args += ["--output-directory", self._outputdir]
|
||||
cmd_args += ["--store", self._cachedir]
|
||||
|
||||
for c in checkpoints:
|
||||
for c in (checkpoints or []):
|
||||
cmd_args += ["--checkpoint", c]
|
||||
|
||||
# Spawn the `osbuild` executable, feed it the specified data on
|
||||
|
|
@ -272,7 +272,7 @@ class OSBuild(contextlib.AbstractContextManager):
|
|||
self._print_result(p.returncode, data_stdout, data_stderr)
|
||||
self._unittest.assertEqual(p.returncode, 0)
|
||||
|
||||
def compile_file(self, file_stdin, checkpoints=[]):
|
||||
def compile_file(self, file_stdin, checkpoints=None):
|
||||
"""Compile an Artifact
|
||||
|
||||
This is similar to `compile()` but takes a file-path instead of raw
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue