summaryrefslogtreecommitdiffstats
path: root/Lib/inspect.py
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-09-16 08:40:16 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-09-16 08:40:16 (GMT)
commit28bc59f1169298470f7c80ed54810a330d68b3c8 (patch)
tree199d8aae3a0047088d9bd932716148d36264acce /Lib/inspect.py
parenta2e2dbe8cda41d5c612d41acad2fe5cfb841402e (diff)
downloadcpython-28bc59f1169298470f7c80ed54810a330d68b3c8.zip
cpython-28bc59f1169298470f7c80ed54810a330d68b3c8.tar.gz
cpython-28bc59f1169298470f7c80ed54810a330d68b3c8.tar.bz2
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.
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r--Lib/inspect.py18
1 files changed, 8 insertions, 10 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py
index f57ba37..5bb6a83 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -24,8 +24,6 @@ Here are some of the useful functions provided by this module:
# This module is in the public domain. No warranties.
-from __future__ import generators
-
__author__ = 'Ka-Ping Yee <ping@lfw.org>'
__date__ = '1 Jan 2001'
@@ -38,7 +36,7 @@ def ismodule(object):
Module objects provide these attributes:
__doc__ documentation string
__file__ filename (missing for built-in modules)"""
- return type(object) is types.ModuleType
+ return isinstance(object, types.ModuleType)
def isclass(object):
"""Return true if the object is a class.
@@ -46,7 +44,7 @@ def isclass(object):
Class objects provide these attributes:
__doc__ documentation string
__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):
"""Return true if the object is an instance method.
@@ -57,7 +55,7 @@ def ismethod(object):
im_class class object in which this method belongs
im_func function object containing implementation of method
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):
"""Return true if the object is a user-defined function.
@@ -70,7 +68,7 @@ def isfunction(object):
func_doc (same as __doc__)
func_globals global namespace in which this function was defined
func_name (same as __name__)"""
- return type(object) in [types.FunctionType, types.LambdaType]
+ return isinstance(object, types.FunctionType)
def istraceback(object):
"""Return true if the object is a traceback.
@@ -80,7 +78,7 @@ def istraceback(object):
tb_lasti index of last attempted instruction in bytecode
tb_lineno current line number in Python source code
tb_next next inner traceback object (called by this level)"""
- return type(object) is types.TracebackType
+ return isinstance(object, types.TracebackType)
def isframe(object):
"""Return true if the object is a frame object.
@@ -98,7 +96,7 @@ def isframe(object):
f_locals local namespace seen by this frame
f_restricted 0 or 1 if frame is in restricted execution mode
f_trace tracing function for this frame, or None"""
- return type(object) is types.FrameType
+ return isinstance(object, types.FrameType)
def iscode(object):
"""Return true if the object is a code object.
@@ -116,7 +114,7 @@ def iscode(object):
co_nlocals number of local variables
co_stacksize virtual machine stack space required
co_varnames tuple of names of arguments and local variables"""
- return type(object) is types.CodeType
+ return isinstance(object, types.CodeType)
def isbuiltin(object):
"""Return true if the object is a built-in function or method.
@@ -125,7 +123,7 @@ def isbuiltin(object):
__doc__ documentation string
__name__ original name of this function or method
__self__ instance to which a method is bound, or None"""
- return type(object) is types.BuiltinFunctionType
+ return isinstance(object, types.BuiltinFunctionType)
def isroutine(object):
"""Return true if the object is any kind of function or method."""