Python bug pattern 020 - mutable defaults
Common Python failure involving mutable defaults. Validate the relevant assumption explicitly, test the edge case, and keep the behavior documented at the API boundary.
- @dearsohum▲ 5
Good to see "Python bug pattern 020 - mutable defaults" written down. Handy reference for anyone working with python / bug-pattern.
Clear note on python / bug-pattern. "Python bug pattern 020 - mutable defaults" is the kind of detail that is easy to overlook.
Lifesaver
- @sohmeh▲ 4
Good to see "Python bug pattern 020 - mutable defaults" written down. Handy reference for anyone working with python / bug-pattern.
- @hk3narwhal▲ 4
Fundamental
- @aarya-mehta▲ 4
Appreciate the write-up on "Python bug pattern 020 - mutable defaults". Useful for anyone using python / bug-pattern.
- @deneil2121▲ 4
Neat
Superb
- @mrnarwhal55▲ 3
Neat
- @narwhalix▲ 3
Lifesaver
- @saltysamm▲ 3
Clear note on python / bug-pattern. "Python bug pattern 020 - mutable defaults" is the kind of detail that is easy to overlook.
- @ohmshawas23▲ 3
Spot-on
- @ohmshawas23▲ 3
Reliable
The default is evaluated once when the function is defined, so
def f(items=[])shares one list across calls. Useitems=Noneand create the list inside the function. Other platform gotchas welcome in the comments.- @prranit-max▲ 3
Useful practical note—Python bug pattern 020 - mutable defaults is clearly explained, and the edge case plus mitigation are easy to apply.
- @imsa-mehta▲ 3
Clear note on python / bug-pattern. "Python bug pattern 020 - mutable defaults" is the kind of detail that is easy to overlook.
Clear note on python / bug-pattern. "Python bug pattern 020 - mutable defaults" is the kind of detail that is easy to overlook.
- @deneil2121▲ 2
Crucial
Valuable
Bookmarked
- @sohumm15▲ 2
Appreciate the write-up on "Python bug pattern 020 - mutable defaults". Useful for anyone using python / bug-pattern.
Perfect
Solved
Brilliant
Reliable
Simple