
-----Original Message----- From: python-ideas-bounces+kristjan=ccpgames.com@python.org [mailto:python-ideas-bounces+kristjan=ccpgames.com@python.org] On Behalf Of Nick Coghlan Sent: 26. júní 2009 09:06 To: Steven D'Aprano Cc: python-ideas@python.org Subject: Re: [Python-ideas] add a list.swap() method
I think Kristján's point was that list.pop() and friends don't perform a PyList_CheckExact on themselves before following their fast path implementation so they can bypass custom get/set/del methods in subclasses.
Right. I've already agreed that my suggestion idea is too radical. I'm merely observing that our discussion has pointed out that other list member functions can be dangerous for list subclasses since they too perform "magic shortcuts" to achieve their goal. So, those that write list subclasses that maintain internal state based on their members, must be careful to override all of these magic list functions. They are list.append, list.pop, list.reverse, list.sort, list.insert, that I can see with a casual perusal of the source. In particular, append(), pop() and insert() modify the list length, which might confuse some subclasses. Cheers, K