[Python-ideas] __iter__ implies __contains__?

Antoine Pitrou solipsis at pitrou.net
Sun Oct 2 14:07:48 CEST 2011


On Sat, 1 Oct 2011 22:30:21 -0400
Nick Coghlan <ncoghlan at gmail.com> wrote:
> On Sat, Oct 1, 2011 at 9:21 PM, Chris Rebert <pyideas at rebertia.com> wrote:
> > Actually, my suggestion was just that Sequence is one possible (but
> > clean) way to obtain the behavior; one could *of course* reimplement
> > the functionality without recourse to Sequence if they desired.
> 
> But why would that would forcing everyone implementation standard
> sequences to reimplement the wheel be an improvement over the status
> quo?

You don't reinvent the wheel if you accept to inherit from abc.Sequence.
Similarly, if you want the IO stack to provide default implementations
of some methods, you have to inherit from XXXIOBase.
If you don't want to implement all 6 ordered comparison operators, you
have to use the functools.total_ordering decorator (and this one has a
bug).

Regards

Antoine.





More information about the Python-ideas mailing list