diff -r 2c124e30a324 Lib/inspect.py --- a/Lib/inspect.py Fri Aug 07 00:43:39 2015 -0700 +++ b/Lib/inspect.py Fri Aug 07 12:02:27 2015 -0400 @@ -1907,8 +1907,7 @@ try: value = eval(s, sys_module_dict) except NameError: - raise RuntimeError() - + raise RuntimeError('cannot resolve expression {!r}'.format(s)) if isinstance(value, str): return ast.Str(value) if isinstance(value, (int, float)): @@ -1917,7 +1916,11 @@ return ast.Bytes(value) if value in (True, False, None): return ast.NameConstant(value) - raise RuntimeError() + if callable(value): + raise MethodEvalNeededError(s) + raise RuntimeError('unsupported value type {!r}'.format(type(value))) + + class MethodEvalNeededError(Exception): pass class RewriteSymbolics(ast.NodeTransformer): def visit_Attribute(self, node): @@ -1947,6 +1950,11 @@ o = ast.literal_eval(default_node) except ValueError: o = invalid + except MethodEvalNeededError as ex: + # if a parameter had its default value defined as a function call, + # i.e. "encoding=sys.getdefaultencoding()", we will render its + # default as a string: "encoding=''" + o = '<{}()>'.format(ex.args[0]) if o is invalid: return None default = o if o is not invalid else default