[Python-Dev] re: Using lists as sets

Barry A. Warsaw bwarsaw@cnri.reston.va.us
Mon, 20 Mar 2000 17:01:00 -0500 (EST)


>>>>> "JH" == Jeremy Hylton <jeremy@cnri.reston.va.us> writes:

    JH> As far as I can tell, the problem is caused by the special way
    JH> that a for loop uses the __getitem__ protocol.  There are two
    JH> related issues that lead to confusion.

>>>>> "MZ" == Moshe Zadka <moshez@math.huji.ac.il> writes:

    MZ> Well, my look is that it is caused by the fact __getitem__ is
    MZ> used both for the sequence protocol and the mapping protocol

Right.

    MZ> Agreed though, that the whole iteration protocol should be
    MZ> revisited -- but that is a subject for another post.

Yup.

    JH> The right solution, I think, is to allow a means for stating
    JH> explicitly whether a class with an __getitem__ method is a
    JH> sequence or a mapping (or both?).

Or should the two protocol use different method names (code breakage!).

    JH> I believe this is where types-vs.-classes meets
    JH> subtyping-vs.-inheritance.

meets protocols-vs.-interfaces.