[Python-ideas] Re: Have del return a value

2023-09-12 Thread Daniel Walker
Makes sense.

On Tue, Sep 12, 2023 at 2:55 AM Rob Cliffe via Python-ideas <
python-ideas@python.org> wrote:

>
>
> On 08/09/2023 22:19, Christopher Barker wrote:
>
> On Fri, Sep 8, 2023 at 11:00 AM Barry Scott 
> wrote:
>
>> I see no need for del to return anything, you already have the reference
>> in foo.
>> The times that foo is dropped at module level are rare enough to not need
>> special syntax.
>>
>
> I agree - using del is very rare in my code. The use case of passing a
> name into a function (or somewhere else?)  and then immediately deleting it
> is rare indeed -- not worth new syntax.
>
> -Chris
>
>
> +1.  The only time I can remember using del to delete a variable is after
> creating a structure with a large memory footprint that is only needed
> temporarily.
> Best wishes
> Rob Cliffe
> ___
> 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/RMS3RID2R2NO4V5A3AOKJCUUOCMHXB4Z/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
___
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/LTPC4FNQFAWYNZEV5F63TOKU2H3ISUYH/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Have del return a value

2023-09-07 Thread Daniel Walker
Ah!  I like that!

On Thu, Sep 7, 2023 at 5:24 PM Tiago Illipronti Girardi <
tiagoigira...@gmail.com> wrote:

> You would be deleting the name, not the value. `unbind` would be a better
> keyword.
> ___
> 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/EJBLQBZYZ2WL6SZJBWBMQF2NCNWRK7RD/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
___
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/QREKRR7TIBXNDVQ6LHD6L4EQMAA62HRK/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Have del return a value

2023-09-07 Thread Daniel Walker
Maybe a new keyword like `delvalue`?

On Thu, Sep 7, 2023 at 10:02 AM Chris Angelico  wrote:

> On Thu, 7 Sept 2023 at 23:51, Daniel Walker  wrote:
> >
> > Perhaps this is a solution in search of a problem but I recently
> encountered this situation in one of my projects.
> >
> > I have an object, foo, which, due to the references it contains, I'd
> rather not keep around longer than necessary.
> >
> > I use foo to instantiate another object:
> >
> > bar = Bar(foo)
> >
> > bar is free to manipulate foo however it wants and even del it if
> necessary.  However, since the foo name is still around, those resources
> won't get cleaned up even if bar is done with them.  The simple solution is
> >
> > bar = Bar(foo)
> > del foo
> > bar.do_stuff()
> >
> > I think it would be a nice (and, I hope, painless) addition to the
> Python grammar to have del return a reference to the underlying object.
> That way, I could simply do
> >
> > bar = Bar(del foo)
> >
> > What do y'all think?  Juice not worth the squeeze?
> >
>
> If you consider that a namespace is very much like a dictionary, what
> you're really doing is a dict.pop() operation - a destructive read. So
> it definitely does make sense. However, "del" is a statement, so it
> would be a bit awkward to retrofit. Maybe it'd work? It certainly is a
> sensible thing to do.
>
> ChrisA
> ___
> 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/5EZ5APBGMJO55CCXWAIGOYW4QTRY2ZC7/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
___
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/UPKFJHPOCWOGP27GPGZNKSTSXRMPO4IG/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Have del return a value

2023-09-07 Thread Daniel Walker
Perhaps this is a solution in search of a problem but I recently
encountered this situation in one of my projects.

I have an object, foo, which, due to the references it contains, I'd rather
not keep around longer than necessary.

I use foo to instantiate another object:

bar = Bar(foo)

bar is free to manipulate foo however it wants and even del it if
necessary.  However, since the foo name is still around, those resources
won't get cleaned up even if bar is done with them.  The simple solution is

bar = Bar(foo)
del foo
bar.do_stuff()

I think it would be a nice (and, I hope, painless) addition to the Python
grammar to have del return a reference to the underlying object.  That way,
I could simply do

bar = Bar(del foo)

What do y'all think?  Juice not worth the squeeze?

Dan
___
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/YRG4J4R3DDEMIFLROWMGEDBIVPM4ZUQ4/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] else without except

2023-06-30 Thread Daniel Walker
As most of you probably know, you can use else with try blocks:

try:
do_stuff()
except SomeExceptionClass:
   handle_error()
else:
   no_error_occurred()

Here, no_error_occurred will only be called if do_stuff() didn't raise an
exception.

However, the following is invalid syntax:

try:
   do_stuff()
else:
   no_error_occurred()

Now you might say that this isn't needed as you can achieve the same result
with

do_stuff()
no_error_occurred()

However, what if I want to use finally as well:

try:
   do_stuff()
else:
   no_error_occurred()
finally:
   cleanup()

and I need no_error_occurred to be called before cleanup?  For my actual
use case, I've done

try:
   do_stuff()
except Exception:
raise
else:
   no_error_occurred()
finally:
   cleanup()

This seems very non-Pythonic.  Is there a reason why else without except
has to be invalid syntax?
___
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/VSXRFQ7OEZJIOCGHWIT225XMGIARFH5J/
Code of Conduct: http://python.org/psf/codeofconduct/