[py3] Switched to Python 3-compatible introspection.

This commit is contained in:
Aymeric Augustin 2012-07-21 22:02:28 +02:00
parent d11d45aad9
commit f1d5dc81ac
2 changed files with 8 additions and 8 deletions

View File

@ -60,14 +60,14 @@ class Feed(object):
except AttributeError:
return default
if callable(attr):
# Check func_code.co_argcount rather than try/excepting the
# Check __code__.co_argcount rather than try/excepting the
# function and catching the TypeError, because something inside
# the function may raise the TypeError. This technique is more
# accurate.
if hasattr(attr, 'func_code'):
argcount = attr.func_code.co_argcount
if hasattr(attr, '__code__'):
argcount = attr.__code__.co_argcount
else:
argcount = attr.__call__.func_code.co_argcount
argcount = attr.__call__.__code__.co_argcount
if argcount == 2: # one argument is 'self'
return attr(obj)
else:

View File

@ -861,7 +861,7 @@ class DocTestFinder:
if module is None:
return True
elif inspect.isfunction(object):
return module.__dict__ is object.func_globals
return module.__dict__ is object.__globals__
elif inspect.isclass(object):
return module.__name__ == object.__module__
elif inspect.getmodule(object) is not None:
@ -926,7 +926,7 @@ class DocTestFinder:
if isinstance(val, staticmethod):
val = getattr(obj, valname)
if isinstance(val, classmethod):
val = getattr(obj, valname).im_func
val = getattr(obj, valname).__func__
# Recurse to methods, properties, and nested classes.
if ((inspect.isfunction(val) or inspect.isclass(val) or
@ -998,8 +998,8 @@ class DocTestFinder:
break
# Find the line number for functions & methods.
if inspect.ismethod(obj): obj = obj.im_func
if inspect.isfunction(obj): obj = obj.func_code
if inspect.ismethod(obj): obj = obj.__func__
if inspect.isfunction(obj): obj = obj.__code__
if inspect.istraceback(obj): obj = obj.tb_frame
if inspect.isframe(obj): obj = obj.f_code
if inspect.iscode(obj):