Skip to content

Conversation

@stevenfontanella
Copy link
Member

@stevenfontanella stevenfontanella commented Jan 6, 2026

The test appends to opts which can refer to the default value of the function, causing future calls with the default value to be changed. e.g.

**>>> def f(a=[]):
...     a.append(1)
...     print(a)
...
>>> f()
[1]
>>> f()
[1, 1]

This would cause -g to be added to the arguments even when debug=False.

There are other instances that use lists as a default argument, but I left them alone for now since they never mutate it.

@stevenfontanella stevenfontanella marked this pull request as ready for review January 6, 2026 21:18
Copy link
Member

@tlively tlively left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof, that's a big footgun.

@stevenfontanella stevenfontanella merged commit 8e1cb7f into main Jan 6, 2026
17 checks passed
@stevenfontanella stevenfontanella deleted the mutable-default branch January 6, 2026 21:44
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

Successfully merging this pull request may close these issues.

3 participants