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:
David Rheinsberg 2020-05-26 17:31:01 +02:00
parent 14ada360bd
commit 46526cf205
4 changed files with 8 additions and 8 deletions

View file

@ -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)