[Python-3000] isinstance(., Iterable) vs lookup('iter') != None Re: *View in abc.py not inheriting Iterable Re: PEP 3119 (original) (raw)
Guido van Rossum guido at python.org
Sat Apr 28 22:30:06 CEST 2007
- Previous message: [Python-3000] isinstance(., Iterable) vs lookup('__iter__') != None Re: *View in abc.py not inheriting Iterable Re: PEP 3119 - Introducing Abstract Base Classes
- Next message: [Python-3000] isinstance(., Iterable) vs lookup('__iter__') != None Re: *View in abc.py not inheriting Iterable Re: PEP 3119 - Introducing Abstract Base Classes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 4/28/07, Samuele Pedroni <pedronis at openendsystems.com> wrote:
Guido van Rossum wrote: > On 4/28/07, Samuele Pedroni <pedronis at openendsystems.com> wrote: >> Shouldn't the various *View in abc.py be Iterables (inherit from >> Iterable) ? > > Oops, it looks like this is a mess. There are two classes > MappingView. Ignore them for the sake of the PEP. I'll clean them up > later. We probably need fewer mapping classes, nor more... > It seems that something that defines iter should also subclass Iterable, in this kind of situation where the special method is unique enough it seems quite repetitive to have to do both. It seems easy to forget to subclass.
Shouldn't now that there are isinstance hooks Iterable be defined again in terms of just checking for the presence of 'iter' lookup-wise? I suppose there are some other similar cases, of course in other situations the ABC carry an intention that goes beyond the presence of methods.
Hm, this certainly sounds like an interesting avenue. So Iterable could override isinstance and issubclass that just check for the presence of iter, and Sized could check for len, Hashable could check for hash, Container could check for contains. I think the others convey more meaning though; not everything iterable sized container is a set (counter-examples are lists and bags). So it would affect the "one trick ponies" section only. (Should Iterator just check for next and leave iter up to the imagination?)
-- --Guido van Rossum (home page: http://www.python.org/~guido/)
- Previous message: [Python-3000] isinstance(., Iterable) vs lookup('__iter__') != None Re: *View in abc.py not inheriting Iterable Re: PEP 3119 - Introducing Abstract Base Classes
- Next message: [Python-3000] isinstance(., Iterable) vs lookup('__iter__') != None Re: *View in abc.py not inheriting Iterable Re: PEP 3119 - Introducing Abstract Base Classes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]