On Tue, Oct 20, 2020, at 22:03, David Mertz wrote:
> My initial impression of your intent was:
> 
> foo, bar = 42, 99
> # ... a million lines ...
> line = "123/"
> # ... more lines ...
> f"{foo}/{bar}" = line
> # raises if bar wasn't previously set
> # binds to prior value if it was set
> 
> 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.

"whether 'bar' is a name"? It is definitely a name, what you have no means to 
know is whether it has been assigned a value. I suspect you're trying to do the 
thing some people do where they insist on 'name' to avoid using the term 
'variable', and I don't want to start a debate about that, but you've used it 
incorrectly here, and your language seems to suggest it would be reasonable to 
treat bar as *global* if unassigned here. In fact, all names assigned in the 
function are in scope for the entire function regardless of whether they have 
been assigned values, whether that assignment is in a conditional that wasn't 
taken or even simply later in the function than when it is used.

Do you have similar objections to assigning inside an if statement? Because the 
suggested semantics are essentially the same as
x = sscanf(line, "%d/%d")
if len(x) >= 1: foo = x[0]
if len(x) >= 2: bar = x[1]
_______________________________________________
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/JKEJYTG2TS3AS263GKNEXZYK4C7D3YRT/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to