New submission from Nick Coghlan:
inspect.signature isn't currently handling builtin & extension types correctly
- these show up as having neither __new__ *nor* __init__ as pure Python
callables, so the inspect.signature logic falls through into a currently
unhandled case.
_testcapi isn't currently exporting an extension type as docstring
introspection fodder, only callables, so test_inspect didn't pick up the
problem. The problem can be seen with builtin types like str:
>>> import inspect
>>> inspect.signature(str)
<inspect.Signature object at 0x7fb81d44e518>
>>> print(inspect.signature(str))
()
Expected behaviour would be to throw a ValueError as with builtin callables
without a signature:
>>> import _testcapi
>>> import inspect
>>> inspect.signature(_testcapi.docstring_no_signature)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ncoghlan/devel/py3k/Lib/inspect.py", line 2830, in signature
return Signature.from_callable(obj)
File "/home/ncoghlan/devel/py3k/Lib/inspect.py", line 2586, in from_callable
return _signature_from_callable(obj, sigcls=cls)
File "/home/ncoghlan/devel/py3k/Lib/inspect.py", line 2064, in
_signature_from_callable
skip_bound_arg=skip_bound_arg)
File "/home/ncoghlan/devel/py3k/Lib/inspect.py", line 1984, in
_signature_from_builtin
raise ValueError("no signature found for builtin {!r}".format(func))
ValueError: no signature found for builtin <built-in function
docstring_no_signature>
----------
messages: 240649
nosy: james, larry, ncoghlan, yselivanov
priority: normal
severity: normal
stage: test needed
status: open
title: inspect.signature reporting "()" for all builtin & extension types
type: behavior
versions: Python 3.4, Python 3.5
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue23934>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com