[Python-Dev] operator.is*Type (original) (raw)
Raymond Hettinger python at rcn.com
Wed Feb 22 12:59:59 CET 2006
- Previous message: [Python-Dev] operator.is*Type
- Next message: [Python-Dev] operator.is*Type
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
>>> from operator import isSequenceType, isMappingType >>> class anything(object): ... def getitem(self, index): ... pass ... >>> something = anything() >>> isMappingType(something) True >>> isSequenceType(something) True
I suggest we either deprecate these functions as worthless, or we define the protocols slightly more clearly for user defined classes.
They are not worthless. They do a damned good job of differentiating anything that CAN be differentiated.
Your example simply highlights the consequences of one of Python's most basic, original design choices (using getitem for both sequences and mappings). That choice is now so fundamental to the language that it cannot possibly change. Get used to it.
In your example, the results are correct. The "anything" class can be viewed as either a sequence or a mapping.
In this and other posts, you seem to be focusing your design around notions of strong typing and mandatory interfaces. I would suggest that that approach is futile unless you control all of the code being run.
Raymond
- Previous message: [Python-Dev] operator.is*Type
- Next message: [Python-Dev] operator.is*Type
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]