Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use mutables as argument defaults in functions #19

Closed
kanu opened this issue May 26, 2017 · 1 comment
Closed

Don't use mutables as argument defaults in functions #19

kanu opened this issue May 26, 2017 · 1 comment

Comments

@kanu
Copy link

kanu commented May 26, 2017

https://github.com/veox/python3-krakenex/blob/master/krakenex/api.py#L151
When defining functions like this def query_private(self, method, req={}, conn = None): you share a single instance of the req dictionary for every call that uses the default of req.

def fn(x={}):
    return x

call1 = fn()
print(call1)
call1["a"] = "A"
call2 = fn()
print(call2)
print (call1 == call2)

If you want a fresh instance of an dictionary on every call of the function I suggest something like this.

def fn(x=None):
    if x is None:
        x = {}

Nevertheless I don't see a concrete problem raised by this in your code.

@veox
Copy link
Owner

veox commented May 26, 2017

Looks like sugar. Good point, though.

Some of this code is slated to become obsolete - see #11. No warning for that has been issued yet, since there hasn't been a release.

Will try to include that when time permits. Feel free to PR, too.


EDIT: Oh, and thanks for taking a look. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants