On Mon, May 20, 2019 at 4:46 AM Terry Reedy <tjre...@udel.edu> wrote:
>
> On 5/18/2019 10:01 PM, Chris Angelico wrote:
>
> > 2) Redefine the 'with' block or create a new syntactic form such that
> > the variable actually creates a subscope. That way, at the end of the
> > block, the name would revert to its former meaning.
> >
> > x = 1
> > with local 2 as x:
> >      print(x) # 2
> > print(x) # 1
>
> Since Python allows both multiple character names and unicode names,
> there is no shortage of names, and hence hardly any need for such
> temporary rebinding.  Function and class bodies must be sub-scoped each
> for their own reasons.
>
> > This would have definite value,
>
> Not much.  If one wants to explicitly localize the use of (new) names,
> one can explicitly delete them.
>
> x1 = 1
> ...
> x2, x3 = 2, 3
> h = hypot(x2, x3)
> del x2, x3  # Okay reader, you can forget about x2, x3.
> ...
> print(1)

Every other Python construct that represents a "grouping" of code is
delimited with indentation. Why should variables be delimited with
"del"? Yes, there's the argument that using "del" works on current
versions of Python and any proposed syntactic feature wouldn't, but
that doesn't mean that every proposed feature has no value.

Maybe it's not sufficient value to add to the language, but IMO it's
more useful than redefining the 'with' block to silently return the
value it was given.

ChrisA
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to