Post #2075104
2026-05-02 09:25 UTC
Replies (4)
-
@brass75@twit.social 2026-05-02 11:46
@grant_h@mastodon.social @qoyyuum@fosstodon.org because that's how mutable variables work. It seems more like you want to know why an exception wasn't made for the case where a mutable value was used as the default for a parameter.
-
@stylus@social.afront.org 2026-05-02 12:06
@grant_h@mastodon.social @brass75@twit.social function default arguments are evaluated when the function definition is encountered, not each time it's called. https://peps.python.org/pep-0671/ seeks to add an alternative behavior but doesn't dive into the history of how we got here
-
@grant_h@mastodon.social 2026-05-02 13:44
@hugovk@mastodon.social @brass75@twit.social @stylus@social.afront.org Triggered by this post: https://mastodon.social/@grant_h/116504261915412452 Parts of the thread were 'followers only' The essence: tylus@social.afront.org @grant_h@mastodon.social @brass75 function default arguments are evaluated when the function definition is encountered, not each time it's called. https:// peps.python.org/pep-0671/ seeks to add an alternative behavior ... We were wondering how to get some support for PEP 671, since it seems to give a neat way of avoiding a common footgun?
-
@MrBerard@mastodon.acm.org 2026-05-02 13:58
@grant_h@mastodon.social Don't think it's a mutability problem, more the fact that lists are passed by reference? (And they're mutable, but that's not really their fault)