
On Thu, Nov 4, 2021 at 4:56 AM Steven D'Aprano <steve@pearwood.info> wrote:
On Thu, Nov 04, 2021 at 04:36:27AM +1100, Chris Angelico wrote:
You use the name because you can't refer to it other than by name, and that's fine. But it's the *default* that is different. Not the parameter.
Wait, are you saying that the list display here:
parameter=[]
is different from the list display here?
parameter=>[]
Well obviously they are distinct *objects*, but we consider that the semantics of the [] is the same here:
a = [] b = []
even though a and b get distinct objects. So we should ignore the fact that they give distinct objects.
Here's a closer parallel. a = [] for _ in range(10): b = [] ... code that uses a and b Are the names a and b different? Are the lists different? Is the assignment different? What, exactly, is different? In a sense, nothing is.
What if we use a singleton as our default?
parameter=None parameter=>None
Now there's only a single object involved. There is no question at all that the token `None` refers to exactly the same thing in both cases. We cannot possibly say that "it's the *default* that is different" in this case, that one of the Nones is different from the other.
But one parameter is still early bound and the other is still late-bound.
The parameters are bound at the same time. One of the defaults is evaluated at function definition time, the other at function invocation time. It's the evaluation of None that is different.
It's not the binding itself that is different (the implementations are the same: we have a slot with a pointer to an object), and it's not the None defaults that are different, because there is only one None. It must be the parameter that is different.
Well, you have two evaluations that produce the same result, but that's because None is a singleton. I mean, you could write it like this and get the same result too: parameter=(None,)[0] I'm sure nobody would try to claim that that's the same expression as just None :) Different expressions can easily yield the same object. But the evaluation is what's different - not because the expression is different, but because the timing is.
I agree that both of those are horrible. That's why I'm not advocating either :)
I've lost track of what your preferred syntax is. It is this?
# move parameter name into the expression parameter=>expression
Yeah, but only a weak preference. I'm sticking to it for consistency, but only until something better comes along. However, I don't consider adorning the name to be better. :) ChrisA