[code-quality] __len__ but no __getitem__

Michael Foord fuzzyman at gmail.com
Mon Sep 23 23:18:39 CEST 2013


On 23 September 2013 22:14, Skip Montanaro <skip at pobox.com> wrote:

> >> 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.
>


Several times I've implemented classes with dynamic behaviour in
__getitem__, so they have no strict length (beyond "theoretically
infinite").

Michael


>
> Skip
> _______________________________________________
> code-quality mailing list
> code-quality at python.org
> https://mail.python.org/mailman/listinfo/code-quality
>



-- 

http://www.voidspace.org.uk/

May you do good and not evil
May you find forgiveness for yourself and forgive others
May you share freely, never taking more than you give.
-- the sqlite blessing http://www.sqlite.org/different.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/code-quality/attachments/20130923/36c510fd/attachment.html>


More information about the code-quality mailing list