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

[BUG] mutable object as default values #587

Open
VukW opened this issue Apr 30, 2024 · 0 comments
Open

[BUG] mutable object as default values #587

VukW opened this issue Apr 30, 2024 · 0 comments

Comments

@VukW
Copy link
Contributor

VukW commented Apr 30, 2024

In some places we are using {} as default function param values. However this is error-prone as these default values are mutable and can be modified unexpectedly during the call:

In [1]: def fun(d={}):
   ...:     d['count'] = d.get('count', 0) + 1
   ...:     print(d)
   ...:

In [2]: fun()
{'count': 1}

In [3]: fun()
{'count': 2}  # default value was modified

Right now it doesn't break anything, but it's worth to fix these cases, not using mutable objects as default values

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

No branches or pull requests

1 participant