[Python-3000] my take on "typeclasses"
Talin
talin at acm.org
Thu May 11 19:43:50 CEST 2006
Ideally, if we get the signature API that's been discussed, then lists
and tuples and such would have a constraint on their __getitem__ method:
def __getitem__( self, index:int ):
...
Thus, the concept testing code could look to see what types are
acceptable to the __getitem__ method and make its decision based on that.
Steven Bethard wrote:
> On 5/11/06, Talin <talin at acm.org> wrote:
>
>>sequence( indexable ):
>> -- an indexable in which the indexes are successive integers
>> -- Test: isinstance( index_type, int )
>
>
> I think as of Python 2.5, this should be hasattr(index_type, '__index__'), no?
>
>
>>mapping( indexable ):
>> -- an indexable in which the indices are hashable values:
>> -- Test: hashable( index_type )
>> -- (Also test for immutable if its feasible)
>
>
> This seems all and good, but how do you figure out what "index_type"
> is? Are you suggesting that "indexables" which want to be identified
> as sequences or mappings need to provide their index type somehow? If
> so, how? (By inheriting from an abstract type?)
>
> STeVe
More information about the Python-3000
mailing list