[Python-Dev] PendingDeprecationWarning

Guido van Rossum guido@python.org
Thu, 30 May 2002 08:35:02 -0400

> It looks like many of the names in the types module already have substitutes 
> in __builtins__:  

This was all covered a few days ago. :-)

> Some of these are new in 2.2 (like object, dict and file).  Some of
> them used to be functions before Python 2.2 (like str, int and
> list).  Three of them are still builtin functions in Python 2.2:
> xrange, buffer and slice.  Perhaps they should also be converted to
> types for consistency.

You can help by contributing patches for these three.  (Let us know if
you plan to do this, so others can relax.)

> Some more factory functions that could be unified with the type of the 
> objects they create module can be found in the new module.  They, too can 
> be used as substitutes for names in the types module.
> >>> import new
> >>> for name, t in types.__dict__.items():
> ...   if type(t) is type and hasattr(new, t.__name__):
> ...     print 'types.%s -> new.%s -> %s' % (name, t.__name__, t.__name__)
> types.CodeType -> new.code -> code
> types.ModuleType -> new.module -> module
> types.LambdaType -> new.function -> function
> types.InstanceType -> new.instance -> instance
> types.FunctionType -> new.function -> function

Except that the new module has the wrong name.  But making all these
types proper factories would be a first step that's useful anyway.
Patch please?

> There are two that almost made it to this list but the name of the
> factory function in module new is not exactly the same as the type's
> __name__:
> types.MethodType -> new.instancemethod -> instancemethod ('instance method')

So change the type's __name__.

> types.ClassType -> new.classobj -> classobj ('class')

Hopefully the classic class will disappear at the same time as
types.py is removed (in 3.0).

> For instancemethod it's easy to remove the space from the type's __name__.
> The word class is a reserved word.  The type's __name__ could be changed 
> to 'classobj' to match the factory function's name. Some other alternatives 
> I can think of are 'class_', 'ClassType' or 'classtype'.

Or 'classic_class'.

> Now how should that module be named? Ummm... maybe 'types'? :-)

This may be the best solution after all.

--Guido van Rossum (home page: http://www.python.org/~guido/)