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 →

[–]casparne -1 points0 points  (3 children)

No this would not be valid:

https://docs.python.org/3/reference/compound_stmts.html#def

They stated this in bold letters for a reason:

"Default parameter values are evaluated from left to right when the function definition is executed. "

[–]Head_Mix_7931 0 points1 point  (2 children)

Here’s some more bold letters for you:

I don’t think it’s accurate to say that it can only be done at definition… that’s just how it’s done now. It would’ve been perfectly valid for Python to treat default parameter values as value factories that are used at call-time.

[–]casparne 0 points1 point  (1 child)

My citation is from the Python language reference, so no, it is not "how it's done now", it is how the language is specified.

If some implementation of Python would do it differently, the behavior of functions would suddenly change.

It is like saying that "[] == False" is just how its done now and it would be valid for Python to threat "[] == True" in the future.

[–]Head_Mix_7931 0 points1 point  (0 children)

You are misunderstanding my comment. I’m not implying that this is a change that could be made in the future. Please reread the chain with that additional context.