Remove duplicate type objects from isroutine() and isbuiltin().

Make getmodule() on a module return the module itself.
This commit is contained in:
Ka-Ping Yee 2001-04-13 09:15:08 +00:00
parent 88ad12afac
commit 202c99b2e0
1 changed files with 4 additions and 4 deletions

View File

@ -123,14 +123,12 @@ 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) in [types.BuiltinFunctionType, return type(object) is types.BuiltinFunctionType
types.BuiltinMethodType]
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."""
return type(object) in [types.FunctionType, types.LambdaType, return type(object) in [types.FunctionType, types.LambdaType,
types.MethodType, types.BuiltinFunctionType, types.MethodType, types.BuiltinFunctionType]
types.BuiltinMethodType]
def getmembers(object, predicate=None): def getmembers(object, predicate=None):
"""Return all members of an object as (name, value) pairs sorted by name. """Return all members of an object as (name, value) pairs sorted by name.
@ -231,6 +229,8 @@ modulesbyfile = {}
def getmodule(object): def getmodule(object):
"""Return the module an object was defined in, or None if not found.""" """Return the module an object was defined in, or None if not found."""
if ismodule(object):
return object
if isclass(object): if isclass(object):
return sys.modules.get(object.__module__) return sys.modules.get(object.__module__)
try: try: