[BUG] Mutable default args should be avoided
See original GitHub issue🐛🐛 Bug Report
@ElevenPhonons on reddit provided feedback to remove Mutable default args if possible with reference to link
⚗️ Current Behavior
Examples
- https://github.com/activeloopai/Hub/blob/master/hub/api/tensorview.py
- https://github.com/activeloopai/Hub/blob/master/hub/client/base.py
...
def request(
self,
method,
relative_url,
endpoint=None,
params={},
data={},
files={},
json={},
timeout=config.DEFAULT_TIMEOUT,
headers={},
):
Expected behavior/code
Mutable default args should be avoided if possible. They can generate unexpected behavior and create difficult to track down bugs.
⚙️ Environment
Python
version(s): 3.8OS
: OSX 10.13.4
🧰 Possible Solution (optional)
Follow the guide to modify the arguments.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Python Mutable Defaults Are The Source of All Evil
In Python, when passing a mutable value as a default argument in a function, the default argument is mutated anytime that value is...
Read more >Why does PyCharm warn about mutable default arguments ...
Default argument values are evaluated only once at function definition time, which means that modifying the default value of the argument will affect...
Read more >Python Pitfall: Mutable Default Arguments | by Don Cross
It's just a matter of avoiding using a mutable default value. A common way to create a new mutable object by default every...
Read more >Common Gotchas - The Hitchhiker's Guide to Python
Python's default arguments are evaluated once when the function is defined, not each time the function is called (like it is in say,...
Read more >It's worth explaining why mutable defaults are bad. ...
It's worth explaining why mutable defaults are bad. The problem with mutable defaults is that they are evaluated once only when the function...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Static code analysis, good, I like that!
I agree with @Anselmoo
@davidbuniat Shall I add the pylint step to the github actions pipeline?