Op 08-09-17 om 04:09 schreef Steve D'Aprano: > On Fri, 8 Sep 2017 04:24 am, Rustom Mody wrote: > >> On Thursday, September 7, 2017 at 6:52:04 PM UTC+5:30, Gregory Ewing wrote: >>> Rustom Mody wrote: >>> >>>> I said: In that case please restate the definition of 'is' from the manual >>>> which invokes the notion of 'memory' without bringing in memory. >>> I don't know whether it's in the manual, but at least for >>> mutable objects, there is a way to define the notion of >>> "same object" that doesn't require talking about "memory": >>> >>> Two names refer to the same object if and only if mutations >>> made through one are visible through the other. >> Seems a sensible comment! > > Except that it is wrong, or at least over-generalised. It is trivially easy to > show false positives: > > py> class K: # defines an object > ... def __init__(self, x): > ... self.x = x > ... def append(self, value): > ... self.x.append(value) > ... > py> a = [] > py> b = K(a) > py> a is b # these are not the same object (they're different types) > False > py> b.append(99) # but modifying b modifies a > py> a > [99]
I don't know if this is a False positive. Yes you have shown a mutation to one that also shows up in the other. But it is possible to mutate b in ways that doesn't show up in a. It seems you have interpreted the phrase: "if and only if mutations made through one are visible through the other." as if it said: "if and only if *some* mutations made through one are visible through the other." while it seems more natural to me to understand it as: "if and only if *all* mutations made through one are visible through the other." So since it is possible to mutate b in ways that are not reflected in a, I can't really see this as a false positive. -- Antoon Pardon -- https://mail.python.org/mailman/listinfo/python-list