type() new style class instance says "class", not "ObjectType"

Bengt Richter bokr at oz.net
Fri Apr 12 19:06:12 EDT 2002


On 12 Apr 2002 21:54:17 GMT, bokr at oz.net (Bengt Richter) wrote:
[...]

>hasattr(c, '__getitem__') etc. can answer some of those questions,
>but if you had an official enumerated set of capabilities, you could
>have a __capabilities__ slot and check with a mask (e.g., against
>constants in __builtins__, e.g., INDEXING).
>
Sorry to follow myself up, but contrary to what I literally wrote, I don't
want to imply a literal integer mask for this, except maybe as part of hidden
implementation. That's too C-ish for a Python.

>For your class above people might write hascapability(c, INDEXING) or
>c.__capabilities__&INDEXING rather than type(c) is list (which fails)
Instead of __capabilities__ one could have a __hascapability__ method.

>or isinstance(c, list) which might be unnecessarily narrow for the
>generic capability (which a non-list-based custom object might support).
>
>BTW, A standard capabilities/protocol query method might be something to
>reserve a mask bit for, for custom extension of the concept.
A __hascapability__ method could serve that purpose.

Regards,
Bengt Richter



More information about the Python-list mailing list