On Sat, May 30, 2020 at 04:34:49PM +1200, Greg Ewing wrote:
> On 30/05/20 12:11 am, Steven D'Aprano wrote:
> >I said that the storage mechanism of *how* local variables are stored,
> >and hence whether or not writes to `locals()` are reflected in the
> >local variables, is an implementation detail.
> 
> That's true, but just to be clear, my ?= idea doesn't rely on
> that implementation detail. If locals were kept in a dict, for
> example, it could work by testing whether the name has an
> entry in the dict.

This thread is huge and I'm losing track of who said what and what they 
meant by it. I thought `?=` was Chris' idea :-)

Is this `?=` idea for a general purpose operator we can use anywhere we 
like? That's what I thought it was, but now I'm doubting my own memory.

E.g. I do this lots of times:

    try:
        spam
    except NameError:
        spam = expression

(Well, usually I end up using `def spam()...` but that's another story.) 
If we had that operator I could use:

    spam ?= value

Or do you mean for it to be purely syntax for function signature lines, 
i.e. only valid in a signature line:

    def spam(arg?=expression):
        ...

If so, I thought you were opposed to putting late-binding inside 
signature lines.

Also, it would still require special handling by the interpreter to 
ensure that the expression was re-evaluated each time it was needed. 
Otherwise it's still just early binding.


> This also means that it *could* be made to work in class and
> global scopes if it were so desired.

I cannot imagine why it could only be made to work in locals but not 
elsewhere. A NameError (including subclasses) is a NameError, and a name 
is always either bound or unbound, there is no third state it could be. 
It either is bound to a value, or not bound to a value.

Some people (Alex, Chris I think?) have tried to argue that there is a 
distinction between an unbound variable and a variable that doesn't 
exist at all, but I'm not clear what they think that distinction would 
be, or why (if such a distinction exists) the interpreter doesn't tell 
when it's one or the other:

    NameError: name 'grue' is not defined
    NameError: name 'bleen' doesn't exist at all


-- 
Steven
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/C6XLJF6OXEA6I4VT7MBGMPCHZ2LSNOZK/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to