deprecating the types module ? (was: problems with the types module)

Michael Hudson mwh at python.net
Thu Dec 12 10:10:00 EST 2002


mis6 at pitt.edu (Michele Simionato) writes:

> I was mislead from the standard documentation. 

Poor gullible fool :)  Seriously, this looks quite bad.

> When you look for the builtin-in function "type", you obtain
> 
> type(object) 
>       Return the type of an object. The return value is a type object. 
>       The standard module types defines names for all built-in types. 
>       For instance: 
> 
>             >>> import types
>             >>> if type(x) == types.StringType: print "It's a string"

Oh dear, that's wrong on so many levels...

> If really the types module has to be deprecated (which I now think it
> would be a good idea) the example should be changed to 
> 
>             >>> if type(x) is str:  print "It's a string"
> 
> which is much much better. 

Of course, the way to write that is

         >>> if isinstance(x, str): print "It's not a moose!"

but that doesn't involve the type builtin...

> Are really there plans to deprecated the types 
> module

Unlikely.  You shouldn't use it for things like StringType, but for
things like TracebackType there's nowhere else to go.

> and will be the documentation changed for Python 2.3 ?

I hope so.  Filing a bug report would make it more likely, I guess.

Cheers,
M.

-- 
  The ultimate laziness is not using Perl.  That saves you so much
  work you wouldn't believe it if you had never tried it.
                                        -- Erik Naggum, comp.lang.lisp



More information about the Python-list mailing list