[Python-checkins] cpython: inspect: Validate that __signature__ is None or an instance of Signature.

yury.selivanov python-checkins at python.org
Mon Jun 23 19:24:03 CEST 2014


http://hg.python.org/cpython/rev/fa5b985f0920
changeset: 91349:fa5b985f0920
parent: 91347:3fffe9681f60
user: Yury Selivanov <yselivanov at sprymix.com>
date: Mon Jun 23 10:23:50 2014 -0700
summary:
 inspect: Validate that __signature__ is None or an instance of Signature.
Closes #21801.
files:
 Lib/inspect.py | 4 ++++
 Lib/test/test_inspect.py | 7 +++++++
 Misc/NEWS | 3 +++
 3 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/Lib/inspect.py b/Lib/inspect.py
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -1939,6 +1939,10 @@
 pass
 else:
 if sig is not None:
+ if not isinstance(sig, Signature):
+ raise TypeError(
+ 'unexpected object {!r} in __signature__ '
+ 'attribute'.format(sig))
 return sig
 
 try:
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -3136,6 +3136,13 @@
 self.assertEqual(lines[:-1], inspect.getsource(module).splitlines())
 self.assertEqual(err, b'')
 
+ def test_custom_getattr(self):
+ def foo():
+ pass
+ foo.__signature__ = 42
+ with self.assertRaises(TypeError):
+ inspect.signature(foo)
+
 @unittest.skipIf(ThreadPoolExecutor is None,
 'threads required to test __qualname__ for source files')
 def test_qualname_source(self):
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -498,6 +498,9 @@
 - Issue #11571: Ensure that the turtle window becomes the topmost window
 when launched on OS X.
 
+- Issue #21801: Validate that __signature__ is None or an instance of Signature.
+
+
 Extension Modules
 -----------------
 
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /