[code-quality] __len__ but no __getitem__

Skip Montanaro skip at pobox.com
Mon Sep 23 23:14:27 CEST 2013


>> Should pylint really be this strict? Or am I expected to implement
>> everything necessary for an array-like containiner and just raise
>> exceptions in those methods the user really shouldn't access?
>
> No I'ld say you're right. While it sounded a good idea when proposed, you're not
> the first one being confused by this message, so I tend to think this check
> should be either removed or kept for well defined and all-or-nothing protocols
> (the only one coming to my mind being the context manager __enter__ / __exit__,
> but there may be others). I would be glad to have others'opinion though.

It occurs to me that the reverse case is likely still correct.  That
is, if __getitem__ is defined, omitting __len__ should happen only
rarely, and probably require an explicit suppression somewhere,
probably in the class definition.

Skip


More information about the code-quality mailing list