pywps icon indicating copy to clipboard operation
pywps copied to clipboard

Dangerous default value [] as argument

Open cehbrecht opened this issue 6 years ago • 1 comments

This issue came up in PR #456.

I wasn't really aware of this issue ... thought it would be just coding style. We should open an issue and fix it in a new PR, maybe like this:

def __init__(self, some_list=None):
    self.some_list = some_list or []

Codacy is giving me "Dangerous default value [] as argument" but this happens a lot elsewhere. I agree this should be changed, but maybe not in this PR...

I think this should really be changed, because this can lead to very hard to find bugs:

class Test:
    def __init__(self, some_list=[]):
        self.some_list = some_list


t1 = Test()
t2 = Test()

t2.some_list.append(1)
print(t1.some_list)  # prints [1]

Originally posted by @cehbrecht in https://github.com/geopython/pywps/pull/456#issuecomment-471551513

cehbrecht avatar Mar 13 '19 16:03 cehbrecht

Hello,

Yes look sane, we may also use copy(some_list)

Best regards.

gschwind avatar Feb 11 '22 13:02 gschwind