geopython / geopython/pywps

Dangerous default value [] as argument

Open
#458 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
186
Forks
117
Avg merge
11d 20h
Merged PRs (30d)
1

Description

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:
>
> ```python
> 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_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.