On Thu, 12 Mar 2020 at 23:55, Andrew Barnert
<abarn...@yahoo.com.via.e4ward.com> wrote:
> Because Julian’s patch has nothing to do with discarding the temporary 
> references. It has to do with knowing that an array is safe to reuse.

Sorry, but I do not understand. Are you saying that the patch does not
create a new temporary ndarray, but modifies in-place the old
temporary ndarray? And that he knows that is temporary because
refcount is 1?

Anyway, I modified a little the Chris' code

class Thing:
    def __init__(self, name):
        self.name = name
        print("Creating", self)
    def __repr__(self):
        return f"{self.__class__.__name__}({self.name})"
    def __add__(self, other):
        return self.__class__(self.name + other.name)
    def __del__(self):
        print("Deleting", self, " - ID:", id(self))

a = Thing("a")
b = Thing("b")
c = Thing("c")
d = Thing("d")
print("######## Before statement")
z = a + b + c + d
print("######## After statement")


Result:

Creating Thing(a)
Creating Thing(b)
Creating Thing(c)
Creating Thing(d)
######## Before statement
Creating Thing(ab)
Creating Thing(abc)
Deleting Thing(ab)  - ID: 140185716001088
Creating Thing(abcd)
Deleting Thing(abc)  - ID: 140185715998976
######## After statement
Deleting Thing(a)  - ID: 140185717096992
Deleting Thing(b)  - ID: 140185717130192
Deleting Thing(c)  - ID: 140185717176784
Deleting Thing(d)  - ID: 140185715998880
Deleting Thing(abcd)  - ID: 140185716001088

As you can see, Thing(abcd) has the same id of Thing(ab). So what Eric
Wieser wanted is already implemented in Python, for temporary objects.
_______________________________________________
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/DE3BKV4NGMLONUJAX35QUM7ECUT35T4E/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to