[Python-ideas] Re: Have del return a value
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
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] Re: Have del return a value
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] Re: Have del return a value
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] Have del return a value
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/