Fuzzyman wrote:
> Hello all,
> 
> Feel free to shoot this down, but a suggestion.
> 
> The operator module defines two functions :
> 
>     isMappingType
>     isSquenceType
> 
> 
> These return a guesstimation as to whether an object passed in supports 
> the mapping and sequence protocols.
> 
> These protocols are loosely defined. Any object which has a 
> ``__getitem__`` method defined could support either protocol.

The docs contain clear warnings about that.

> I suggest we either deprecate these functions as worthless, *or* we 
> define the protocols slightly more clearly for user defined classes.

I have no problems deprecating them since I've never used one of these
functions.  If I want to know if something is a string I use isinstance(),
for string-like objects I would use

  try: obj + ""
  except TypeError:

and so on.

> 
> An object prima facie supports the mapping protocol if it defines a 
> ``__getitem__`` method, and a ``keys`` method.
> 
> An object prima facie supports the sequence protocol if it defines a 
> ``__getitem__`` method, and *not* a ``keys`` method.
> 
> As a result code which needs to be able to tell the difference can use 
> these functions and can sensibly refer to the definition of the mapping 
> and sequence protocols when documenting what sort of objects an API call 
> can accept.

Thomas

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to