question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[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

...
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.8
  • OS: OSX 10.13.4

🧰 Possible Solution (optional)

Follow the guide to modify the arguments.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jebladcommented, Feb 16, 2021

Static code analysis, good, I like that!

1reaction
ADI10HEROcommented, Dec 22, 2020

I agree with @Anselmoo

@davidbuniat Shall I add the pylint step to the github actions pipeline?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found