2.2 features

Alex Martelli aleaxit at yahoo.com
Fri Aug 3 08:22:46 EDT 2001


"Olaf Delgado" <delgado at eva17.Mathematik.Uni-Bielefeld.DE> wrote in message
news:slrn9mknig.4g5.delgado at eva17.Mathematik.Uni-Bielefeld.DE...
> Tim Hochberg wrote:
>
> >isinstance(anInstance, aClass) => aClass.classof(anInstance)
> >isubclass(aSubclass, aBaseclass) => aBaseclass.superclassof(aSubclass)
>
> Not bad! How about
>   aClass.has_instance(anInstance)
> and
>   aBaseclass.has_subclass(aSubclass),
> then?
>
> This would resemble dictionary.has_key(...).

Yes, but it seems to be the wrong way around to me.  A dictionary D
must clearly keep track of its keys, in the mental model I have of it,
so asking D if K is a key makes sense; while a class C doesn't keep
track of its instances, much less of what other classes subclass it, so
asking C whether I is an instance or S a subclass doesn't make any
sense to me.  Rather, I could ask I if it instances C, or S if it subclasses
C, since 'clearly' (to me) an instance knows its type/class and a class
does know its bases/ancestors, but not viceversa.  Like asking K
whether K is a key into dictionary D -- how should K know except
by asking D...?!


Alex






More information about the Python-list mailing list