Commit 28bc59f1 authored by Tim Peters's avatar Tim Peters

In a world with a growing number of subclassable types, replace

    type(x) is T
tests with
    isinstance(x, T)
Also got rid of a future-generators import, left over from code that
wasn't intended to get checked in.
parent a2e2dbe8
...@@ -24,8 +24,6 @@ Here are some of the useful functions provided by this module: ...@@ -24,8 +24,6 @@ Here are some of the useful functions provided by this module:
# This module is in the public domain. No warranties. # This module is in the public domain. No warranties.
from __future__ import generators
__author__ = 'Ka-Ping Yee <ping@lfw.org>' __author__ = 'Ka-Ping Yee <ping@lfw.org>'
__date__ = '1 Jan 2001' __date__ = '1 Jan 2001'
...@@ -38,7 +36,7 @@ def ismodule(object): ...@@ -38,7 +36,7 @@ def ismodule(object):
Module objects provide these attributes: Module objects provide these attributes:
__doc__ documentation string __doc__ documentation string
__file__ filename (missing for built-in modules)""" __file__ filename (missing for built-in modules)"""
return type(object) is types.ModuleType return isinstance(object, types.ModuleType)
def isclass(object): def isclass(object):
"""Return true if the object is a class. """Return true if the object is a class.
...@@ -46,7 +44,7 @@ def isclass(object): ...@@ -46,7 +44,7 @@ def isclass(object):
Class objects provide these attributes: Class objects provide these attributes:
__doc__ documentation string __doc__ documentation string
__module__ name of module in which this class was defined""" __module__ name of module in which this class was defined"""
return type(object) is types.ClassType or hasattr(object, '__bases__') return isinstance(object, types.ClassType) or hasattr(object, '__bases__')
def ismethod(object): def ismethod(object):
"""Return true if the object is an instance method. """Return true if the object is an instance method.
...@@ -57,7 +55,7 @@ def ismethod(object): ...@@ -57,7 +55,7 @@ def ismethod(object):
im_class class object in which this method belongs im_class class object in which this method belongs
im_func function object containing implementation of method im_func function object containing implementation of method
im_self instance to which this method is bound, or None""" im_self instance to which this method is bound, or None"""
return type(object) is types.MethodType return isinstance(object, types.MethodType)
def isfunction(object): def isfunction(object):
"""Return true if the object is a user-defined function. """Return true if the object is a user-defined function.
...@@ -70,7 +68,7 @@ def isfunction(object): ...@@ -70,7 +68,7 @@ def isfunction(object):
func_doc (same as __doc__) func_doc (same as __doc__)
func_globals global namespace in which this function was defined func_globals global namespace in which this function was defined
func_name (same as __name__)""" func_name (same as __name__)"""
return type(object) in [types.FunctionType, types.LambdaType] return isinstance(object, types.FunctionType)
def istraceback(object): def istraceback(object):
"""Return true if the object is a traceback. """Return true if the object is a traceback.
...@@ -80,7 +78,7 @@ def istraceback(object): ...@@ -80,7 +78,7 @@ def istraceback(object):
tb_lasti index of last attempted instruction in bytecode tb_lasti index of last attempted instruction in bytecode
tb_lineno current line number in Python source code tb_lineno current line number in Python source code
tb_next next inner traceback object (called by this level)""" tb_next next inner traceback object (called by this level)"""
return type(object) is types.TracebackType return isinstance(object, types.TracebackType)
def isframe(object): def isframe(object):
"""Return true if the object is a frame object. """Return true if the object is a frame object.
...@@ -98,7 +96,7 @@ def isframe(object): ...@@ -98,7 +96,7 @@ def isframe(object):
f_locals local namespace seen by this frame f_locals local namespace seen by this frame
f_restricted 0 or 1 if frame is in restricted execution mode f_restricted 0 or 1 if frame is in restricted execution mode
f_trace tracing function for this frame, or None""" f_trace tracing function for this frame, or None"""
return type(object) is types.FrameType return isinstance(object, types.FrameType)
def iscode(object): def iscode(object):
"""Return true if the object is a code object. """Return true if the object is a code object.
...@@ -116,7 +114,7 @@ def iscode(object): ...@@ -116,7 +114,7 @@ def iscode(object):
co_nlocals number of local variables co_nlocals number of local variables
co_stacksize virtual machine stack space required co_stacksize virtual machine stack space required
co_varnames tuple of names of arguments and local variables""" co_varnames tuple of names of arguments and local variables"""
return type(object) is types.CodeType return isinstance(object, types.CodeType)
def isbuiltin(object): def isbuiltin(object):
"""Return true if the object is a built-in function or method. """Return true if the object is a built-in function or method.
...@@ -125,7 +123,7 @@ def isbuiltin(object): ...@@ -125,7 +123,7 @@ def isbuiltin(object):
__doc__ documentation string __doc__ documentation string
__name__ original name of this function or method __name__ original name of this function or method
__self__ instance to which a method is bound, or None""" __self__ instance to which a method is bound, or None"""
return type(object) is types.BuiltinFunctionType return isinstance(object, types.BuiltinFunctionType)
def isroutine(object): def isroutine(object):
"""Return true if the object is any kind of function or method.""" """Return true if the object is any kind of function or method."""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment