Yes, that's reasonable, and the PEG parser supports this (just put the
`del_stmt` rule before the `expression` rule).

I'm not sponsoring your proposal though -- you're going to have to convince
other core devs (and ultimately the Steering Council) that this is worth
it. Once you have a core dev willing to sponsor, they can help you write a
PEP.

On Fri, Jun 12, 2020 at 9:36 AM Eric Wieser <wieser.eric+nu...@gmail.com>
wrote:

> Yes, it would mean that, which is particularly nasty considering the fact
> that `_` in python and `Out` in IPython would then acquire the very
> reference that was being deleted.
> I think that my proposed change would be unacceptable without
> addressing this problem.
>
> To resolve this, `del` could be made both a statement and an expression.
> The parsing rules would be very similar to how the walrus operator is
> handled today, but instead of being a SyntaxError in statement mode, it
> would simply produce a different ast node:
>
> * `del x` -> `Delete(x)`  (as `x := 0` -> SyntaxError)
> * `(del x)` -> `Expr(DeleteExpr(x))`   (as `(x := 0)` ->
> `Expr(NamedExpr(...))`)
>
> Eric
>
> On Fri, 12 Jun 2020 at 17:21, Guido van Rossum <gu...@python.org> wrote:
>
>> On Fri, Jun 12, 2020 at 4:55 AM Eric Wieser <wieser.eric+nu...@gmail.com>
>> wrote:
>>
>>> > He thought that the change of del he proposed will give him that
>>> behavior, but this is not true.
>>>
>>> Unless I'm forgetting part of the conversation, that's not true. Note
>>> that the numpy patch is merged. Today, you get the optimization with `z = a
>>> + b + c + d`. What you don't get is the same optimization if you use:
>>> ```
>>> ab = a + b
>>> abc = ab + c
>>> z = abc + d
>>> ```
>>> The language feature I propose is to allow you to _keep_ the
>>> optimization that was present in `z = a + b + c + d`, but write it as
>>> ```
>>> ab = a + b
>>> abc = (del ab) + c
>>> z = (del abc) + d
>>> ```
>>>
>>
>> But does that mean that typing `del x` at the REPL will print the value
>> of `x`? That seems wrong. If `del x` is an expression that returns the
>> value of `x` (and then unbinds it), then the REPL would seem to have no
>> choice but to print the returned value -- the REPL has no indication that
>> it came from `del`.
>>
>> --
>> --Guido van Rossum (python.org/~guido)
>> *Pronouns: he/him **(why is my pronoun here?)*
>> <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
>>
>

-- 
--Guido van Rossum (python.org/~guido)
*Pronouns: he/him **(why is my pronoun here?)*
<http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
_______________________________________________
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/AOWXLTCYVUUONM7PXKAFU5KSYBH2JI4E/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to