Maybe a new keyword like `delvalue`?

On Thu, Sep 7, 2023 at 10:02 AM Chris Angelico <ros...@gmail.com> wrote:

> On Thu, 7 Sept 2023 at 23:51, Daniel Walker <nickel...@gmail.com> 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/

Reply via email to