Path: csiph.com!x330-a1.tempe.blueboxinc.net!feeder1.hal-mli.net!news.linkpendium.com!news.linkpendium.com!panix!roy From: Roy Smith Newsgroups: comp.lang.python Subject: list equal to subclass of list? Date: Thu, 12 May 2011 08:23:04 -0400 Organization: PANIX Public Access Internet and UNIX, NYC Lines: 37 Message-ID: NNTP-Posting-Host: localhost X-Trace: reader1.panix.com 1305202986 264 127.0.0.1 (12 May 2011 12:23:06 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Thu, 12 May 2011 12:23:06 +0000 (UTC) User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:5230 I have a vague feeling this may have been discussed a long time ago, but I can't find the thread, so I'll bring it up again. I recently observed in the "checking if a list is empty" thread that a list and a subclass of list can compare equal: ---------------------------- class MyList(list): "I'm a subclass" l1 = [] l2 = MyList() print type(l1), type(l2) print type(l1) == type(l2) print l1 == l2 ---------------------------- when run, prints: False True The docs say: [http://docs.python.org/library/stdtypes.html] Objects of different types, except different numeric types and different string types, never compare equal [http://docs.python.org/release/2.7/reference/expressions.html#notin] objects of different types (emphasis)always compare unequal In the test code above, l1 an l2 are different types, at least in the sense that type() returns something different for each of them. What's the intended behavior here? Either the code is wrong or the docs are wrong.