On Wed, May 27, 2020 at 2:51 AM Steven D'Aprano <st...@pearwood.info> wrote:
> But doing otherwise, having Undef be *not an object* but a kinda ghost
> in the interpreter, is a huge language change and I doubt it would be
> worth it.
>

But is it a huge change? I thought so too, until Greg suggested a
quite plausible option: leave the local unbound. There'd be two
changes needed, and one of them could have other value. The semantics
would be exactly the same as any other unbound local.

def foo():
    if False: x = 0
    # what is x now?

There is no *value* in x, yet x has a state. So we could have some
kind of definition of optional parameters where, rather than receiving
a default, they would simply not be bound.

def foo(?x):
    # what is x?

There would want to be a new way to query this state, though, because
I think this code is ugly enough to die:

def foo(?x):
    try:
        x
    except UnboundLocalError:
        ... # do this if x wasn't passed in
    else:
        ... # do this if we have a value for x

But if we could do something a bit more elegant, this would become
quite plausible. And the "is this name bound" check would potentially
have other value, too.

"Undef" wouldn't be a thing. It wouldn't be a global name, it wouldn't
be a keyword, it certainly wouldn't be an object. But "unbound" would
become a perfectly viable state for a local variable.

(It's probably best to define this ONLY for local variables. Module or
class name bindings behave differently, so they would simply never be
in this unbound state. For the intended purpose - parameter
nondefaults - that won't be a problem.)

ChrisA
_______________________________________________
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/SJPGHG2XPVM2ONDGPUHJZNBVRKAOMZMF/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to