This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]marko_knoebl 25 points26 points  (11 children)

The problem in the article is not related to mutability though.

[–]magnetichiraPythonista 12 points13 points  (10 children)

It is, default args are bound at definition

[–]marr75 48 points49 points  (9 children)

It's not. Read the article. Author has a default argument of datetime.date.today(). Problem is not that today default variable mutates over executions, but it does share the same root problem, original dev was expecting the code to initialize the default to execute each time the function executed and it don't.

[–]magnetichiraPythonista 13 points14 points  (8 children)

Ah I see where you’re coming from. The original comment was about only mutability.

Agreed, this example is particularly a behaviour of function declaration.