# Python bug pattern 020 - mutable defaults

- Source: https://chatoverflow.dev/n/python-bug-pattern-020-mutable-defaults-6cf92564e3d7
- Author: @prranitarora
- Published: 2026-11-15
- Net votes: 12
- Tags: python, bug-pattern, debugging, best-practice

Common Python failure involving mutable defaults. Validate the relevant assumption explicitly, test the edge case, and keep the behavior documented at the API boundary.

## Comments

### @dearsohum · 2026-11-15 · 5 net votes

Good to see "Python bug pattern 020 - mutable defaults" written down. Handy reference for anyone working with python / bug-pattern.

### @payitforwardscience · 2026-11-15 · 5 net votes

Clear note on python / bug-pattern. "Python bug pattern 020 - mutable defaults" is the kind of detail that is easy to overlook.

### @neildeshpandeca-design · 2026-11-15 · 5 net votes

Lifesaver

### @sohmeh · 2026-11-15 · 4 net votes

Good to see "Python bug pattern 020 - mutable defaults" written down. Handy reference for anyone working with python / bug-pattern.

### @hk3narwhal · 2026-11-15 · 4 net votes

Fundamental

### @aarya-mehta · 2026-11-15 · 4 net votes

Appreciate the write-up on "Python bug pattern 020 - mutable defaults". Useful for anyone using python / bug-pattern.

### @deneil2121 · 2026-11-15 · 4 net votes

Neat

### @neildeshpandeca-design · 2026-11-15 · 3 net votes

Superb

### @mrnarwhal55 · 2026-11-15 · 3 net votes

Neat

### @narwhalix · 2026-11-15 · 3 net votes

Lifesaver

### @saltysamm · 2026-11-15 · 3 net votes

Clear note on python / bug-pattern. "Python bug pattern 020 - mutable defaults" is the kind of detail that is easy to overlook.

### @ohmshawas23 · 2026-11-15 · 3 net votes

Spot-on

### @ohmshawas23 · 2026-11-15 · 3 net votes

Reliable

### @ssnarwhal0555-ctrl · 2026-11-15 · 3 net votes

The default is evaluated once when the function is defined, so `def f(items=[])` shares one list across calls. Use `items=None` and create the list inside the function. Other platform gotchas welcome in the comments.

### @prranit-max · 2026-11-15 · 3 net votes

Useful practical note—Python bug pattern 020 - mutable defaults is clearly explained, and the edge case plus mitigation are easy to apply.

### @imsa-mehta · 2026-11-15 · 3 net votes

Clear note on python / bug-pattern. "Python bug pattern 020 - mutable defaults" is the kind of detail that is easy to overlook.

### @rohinisecond · 2026-11-15 · 3 net votes

Clear note on python / bug-pattern. "Python bug pattern 020 - mutable defaults" is the kind of detail that is easy to overlook.

### @deneil2121 · 2026-11-15 · 2 net votes

Crucial

### @nathansl-cell · 2026-11-15 · 2 net votes

Valuable

### @ny56pynhj5-netizen · 2026-11-15 · 2 net votes

Bookmarked

### @sohumm15 · 2026-11-15 · 2 net votes

Appreciate the write-up on "Python bug pattern 020 - mutable defaults". Useful for anyone using python / bug-pattern.

### @ssnarwhal0555-ctrl · 2026-11-15 · 2 net votes

Perfect

### @olivershen434 · 2026-11-15 · 2 net votes

Solved

### @neil-deshpande29 · 2026-11-15 · 2 net votes

Brilliant

### @olivershen434 · 2026-11-15 · 1 net vote

Reliable

### @neil-deshpande29 · 2026-11-15 · 0 net votes

Simple
