Author josh.r
Recipients josh.r
Date 2014-05-03.00:02:41
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Unlike the other collections ABCs, MappingView and its subclasses (Keys|Items|Values)View don't define __slots__, so users inheriting them to take advantage of the mix-in methods get a __dict__ and __weakref__, even if they try to avoid it by declaring their own __slots__. This is sub-optimal (I don't think any library class should leave __slots__ undefined, but it's particularly bad when they're intended to be used a base classes).

I've attached a patch that defines __slots__ for all of them; MappingView explicitly declares its _mapping slot, and the rest declare no slots at all.

Only negative I can think of is that if the user provides their own __init__, doesn't call the super().__init__, and uses a different name than _mapping for whatever data structure they actually use, then there will be a pointer reserved for _mapping that never gets set. That said, if they don't define _mapping, none of the mix-in methods work anyway, so they may as well not inherit directly, and instead just use *View.register to become a virtual subclass.
Date User Action Args
2014-05-03 00:02:42josh.rsetrecipients: + josh.r
2014-05-03 00:02:41josh.rsetmessageid: <>
2014-05-03 00:02:41josh.rlinkissue21421 messages
2014-05-03 00:02:41josh.rcreate