Pydoc fails with the codecs module in 3.5+. All works in 3.4.
$ ./python -m pydoc codecs
Traceback (most recent call last):
File "/home/serhiy/py/cpython-3.5/Lib/runpy.py", line 170, in _run_module_as_main
"__main__", mod_spec)
File "/home/serhiy/py/cpython-3.5/Lib/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/serhiy/py/cpython-3.5/Lib/pydoc.py", line 2648, in <module>
cli()
File "/home/serhiy/py/cpython-3.5/Lib/pydoc.py", line 2613, in cli
help.help(arg)
File "/home/serhiy/py/cpython-3.5/Lib/pydoc.py", line 1895, in help
elif request: doc(request, 'Help on %s:', output=self._output)
File "/home/serhiy/py/cpython-3.5/Lib/pydoc.py", line 1632, in doc
pager(render_doc(thing, title, forceload))
File "/home/serhiy/py/cpython-3.5/Lib/pydoc.py", line 1625, in render_doc
return title % desc + '\n\n' + renderer.document(object, name)
File "/home/serhiy/py/cpython-3.5/Lib/pydoc.py", line 370, in document
if inspect.ismodule(object): return self.docmodule(*args)
File "/home/serhiy/py/cpython-3.5/Lib/pydoc.py", line 1160, in docmodule
contents.append(self.document(value, key, name))
File "/home/serhiy/py/cpython-3.5/Lib/pydoc.py", line 372, in document
if inspect.isroutine(object): return self.docroutine(*args)
File "/home/serhiy/py/cpython-3.5/Lib/pydoc.py", line 1345, in docroutine
signature = inspect.signature(object)
File "/home/serhiy/py/cpython-3.5/Lib/inspect.py", line 2988, in signature
return Signature.from_callable(obj, follow_wrapped=follow_wrapped)
File "/home/serhiy/py/cpython-3.5/Lib/inspect.py", line 2738, in from_callable
follow_wrapper_chains=follow_wrapped)
File "/home/serhiy/py/cpython-3.5/Lib/inspect.py", line 2229, in _signature_from_callable
skip_bound_arg=skip_bound_arg)
File "/home/serhiy/py/cpython-3.5/Lib/inspect.py", line 2061, in _signature_from_builtin
return _signature_fromstr(cls, func, s, skip_bound_arg)
File "/home/serhiy/py/cpython-3.5/Lib/inspect.py", line 2009, in _signature_fromstr
p(name, default)
File "/home/serhiy/py/cpython-3.5/Lib/inspect.py", line 1991, in p
default_node = RewriteSymbolics().visit(default_node)
File "/home/serhiy/py/cpython-3.5/Lib/ast.py", line 245, in visit
return visitor(node)
File "/home/serhiy/py/cpython-3.5/Lib/ast.py", line 310, in generic_visit
new_node = self.visit(old_value)
File "/home/serhiy/py/cpython-3.5/Lib/ast.py", line 245, in visit
return visitor(node)
File "/home/serhiy/py/cpython-3.5/Lib/inspect.py", line 1978, in visit_Attribute
return wrap_value(value)
File "/home/serhiy/py/cpython-3.5/Lib/inspect.py", line 1965, in wrap_value
raise RuntimeError()
RuntimeError
|
Larry, Serhiy,
After giving this some thought I think that my initial patch is a wrong approach here -- inspect module should not be touched to fix this issue.
With this patch applied, signature object for codecs.encode would have a Parameter with a bogus default value, breaking functions like 'BoundArguments.apply_defaults()' etc. In other words, whatever AC puts in 'signature.parameters['encoding'].default' must be an object that will be accepted by the function.
codecs.encode, if implemented in Python, would look like:
def encode(obj, encoding=None, errors='strict'):
if encoding is None:
encoding = sys.getdefaultencoding()
...
And that's how the signature should be defined for the C version (because that's what is actually happening in C code as well!)
The new patch changes the AC specs from
_codecs.encode
obj: object
encoding: str(c_default="NULL") = sys.getdefaultencoding()
errors: str(c_default="NULL") = "strict"
to
_codecs.encode
obj: object
encoding: str(accept={str, NoneType}) = NULL
errors: str(c_default="NULL") = "strict"
(docstring is updated too).
This change, by the way, is in accordance with PEP 436:
The values supplied for these [default] parameters must be compatible with ast.literal_eval.
|