News for hackers. Stuff that matters.
Re:Why Do Python Lists Multiply Oddly? Exploring the CPython... by abhi9u on Tuesday April 09, 2024 @09:06AM (#39979009)
Yes, the default function argument values is another surprising behavior.

In this case, the default arguments get compiled as part of the function code and are part of the function's environment. As a result every time that function is called it is always having the same environment, i.e. the default argument values are not reinterpreted on every invocation. So the mutations to the environment are visible across function calls.

Re:Why Do Python Lists Multiply Oddly? Exploring the CPython... by kerkeslager on Tuesday April 09, 2024 @11:19AM (#39980388)
> In this case, the default arguments get compiled as part of the function code and are part of the function's environment.

Yeah, I understand that; I'm saying that was a choice they made, and I think having the defaults be evaluated at each call time would have been a better choice.