On Wed, Oct 21, 2020, 12:12 AM Chris Angelico

> > But I think what you want is for the binding line never to raise, but
> also not to have any local means to know whether 'bar' is a name after that
> line. Or whether 'foo' is, for that matter.
>
> Easy: it always is. Whether it has had a value assigned to it is a
> separate consideration. Consider:
>
> if cond: x = 1
>
> Is x a name after this line? Yes, yes it is. There's nothing spooky
> happening here.


I have no idea whether 'x' is a name after that line. Neither do you. I
mean, in some Platonic abstraction, I guess 'x' is eternally a name and
always has been.

But I have no idea whether the next line of:

   print(x)

Will raise an exception or print something out. I.e. is it a key in
globals() and/or locals()?

I've been stung many times by thinking "x was surely bound" and finding it
wasn't. I'm certain you have been too. But I know that conditional blocks
have that special property of maybe being executed, maybe not.

So among other things, you are introducing another way to spell a
conditional block. Even the ternary expression cannot conditionally bind a
name ('while' blocks can, of course; and try/except blocks). This is way
too much baggage for something that is far clearer as a plain function.
_______________________________________________
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/SZTYUSMBGB7TFXPLKA4YNSVXQHG2DVLX/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to