summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/inspect.py6
-rw-r--r--Lib/test/test_inspect.py7
-rw-r--r--Misc/NEWS3
3 files changed, 14 insertions, 2 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py
index 57cb3dc..25ddd26 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -2255,9 +2255,13 @@ def _signature_from_callable(obj, *,
if type not in obj.__mro__:
# We have a class (not metaclass), but no user-defined
# __init__ or __new__ for it
- if obj.__init__ is object.__init__:
+ if (obj.__init__ is object.__init__ and
+ obj.__new__ is object.__new__):
# Return a signature of 'object' builtin.
return signature(object)
+ else:
+ raise ValueError(
+ 'no signature found for builtin type {!r}'.format(obj))
elif not isinstance(obj, _NonUserDefinedCallables):
# An object with __call__
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py
index 9f09b83..4695da8 100644
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -1980,9 +1980,14 @@ class TestSignatureObject(unittest.TestCase):
@cpython_only
def test_signature_on_builtins_no_signature(self):
import _testcapi
- with self.assertRaisesRegex(ValueError, 'no signature found for builtin'):
+ with self.assertRaisesRegex(ValueError,
+ 'no signature found for builtin'):
inspect.signature(_testcapi.docstring_no_signature)
+ with self.assertRaisesRegex(ValueError,
+ 'no signature found for builtin'):
+ inspect.signature(str)
+
def test_signature_on_non_function(self):
with self.assertRaisesRegex(TypeError, 'is not a callable object'):
inspect.signature(42)
diff --git a/Misc/NEWS b/Misc/NEWS
index 2d41812..d0223c5 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -31,6 +31,9 @@ Library
- Issue #16991: Add a C implementation of OrderedDict.
+- Issue #23934: Fix inspect.signature to fail correctly for builtin types
+ lacking signature information. Initial patch by James Powell.
+
What's New in Python 3.5.0 beta 1?
==================================