Commit 71185ac7 authored by Konrad Sztyber's avatar Konrad Sztyber Committed by Tomasz Zawadzki
Browse files

rpc: remove mutable default argument



Using mutable objects (e.g. a dict) as default arguments to a function
can lead to unexpected behavior, as the same object will be used for
each call to that function.  For example:

def foo(bar, baz=[]):
	baz.append(bar)
	return baz

>>> foo(1)
[1]
>>> foo(2)
[1, 2]

We don't want params to be remembered between function calls, so they're
now default initialized to None and set to an empty dict in the body of
the function.

Signed-off-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Change-Id: I63c71b5424286658759f09aed2d30c529c2d1081
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/19807


Reviewed-by: default avatarArtur Paszkiewicz <artur.paszkiewicz@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <jim.harris@gmail.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
parent 0165cd07
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -180,8 +180,9 @@ class JSONRPCClient(object):
        self._logger.info("response:\n%s\n", json.dumps(response, indent=2))
        return response

    def call(self, method, params={}):
    def call(self, method, params=None):
        self._logger.debug("call('%s')" % method)
        params = {} if params is None else params
        req_id = self.send(method, params)
        try:
            response = self.recv()