[Python-ideas] Inline assignments using "given" clauses
rosuav at gmail.com
Sun May 13 17:59:44 EDT 2018
On Mon, May 14, 2018 at 7:00 AM, Cameron Simpson <cs at cskk.id.au> wrote:
> While I can see the issue, on a personal basis I'd accept it: import and
> except don't do this and they happily use "as". In my mind the problem lies
> with "with" (and is a perfectly acceptable inconsistency there, given what
> with does for us).
The same problem happens with 'except', only less subtly.
except Exception as e: # binds the caught exception to e
except (Exception as e): # would bind the type Exception
import doesn't put an expression on the left of 'as', so it's less
likely to cause confusion; but all three of them do something special
before binding to the target given with 'as'.
By the way: do you know which of the three support arbitrary
assignment targets and which support only names? No? Neither did I,
till I checked the grammar. So there's no consistency there, other
than a loose sense that "as" means "we're gonna toss something into
somewhere". Not nearly enough to justify using that syntax for
arbitrary name bindings, given how much hassle there is with 'with'.
More information about the Python-ideas