[Python-checkins] bpo-33009: Fix inspect.signature() for single-parameter partialmethods. (GH-6004)

Miss Islington (bot) webhook-mailer at python.org
Tue Mar 6 13:48:11 EST 2018


https://github.com/python/cpython/commit/387a055261267f5fafd2c12eafef49759c94704f
commit: 387a055261267f5fafd2c12eafef49759c94704f
branch: 3.6
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2018-03-06T10:48:04-08:00
summary:

bpo-33009: Fix inspect.signature() for single-parameter partialmethods. (GH-6004)

(cherry picked from commit 8a387219bdfb6ee34928d6168ac42ca559f11c9a)

Co-authored-by: Yury Selivanov <yury at magic.io>

files:
A Misc/NEWS.d/next/Library/2018-03-06-11-54-59.bpo-33009.-Ekysb.rst
M Lib/inspect.py
M Lib/test/test_inspect.py

diff --git a/Lib/inspect.py b/Lib/inspect.py
index e9c2dbd5c88d..dc2aab2826af 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -2251,7 +2251,8 @@ def _signature_from_callable(obj, *,
                 return sig
             else:
                 sig_params = tuple(sig.parameters.values())
-                assert first_wrapped_param is not sig_params[0]
+                assert (not sig_params or
+                        first_wrapped_param is not sig_params[0])
                 new_params = (first_wrapped_param,) + sig_params
                 return sig.replace(parameters=new_params)
 
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py
index 55436748d6f5..126b26e49227 100644
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -2526,6 +2526,16 @@ def test(it, a, *, c) -> 'spam':
                            ('c', 1, ..., 'keyword_only')),
                           'spam'))
 
+        class Spam:
+            def test(self: 'anno', x):
+                pass
+
+            g = partialmethod(test, 1)
+
+        self.assertEqual(self.signature(Spam.g),
+                         ((('self', ..., 'anno', 'positional_or_keyword'),),
+                          ...))
+
     def test_signature_on_fake_partialmethod(self):
         def foo(a): pass
         foo._partialmethod = 'spam'
diff --git a/Misc/NEWS.d/next/Library/2018-03-06-11-54-59.bpo-33009.-Ekysb.rst b/Misc/NEWS.d/next/Library/2018-03-06-11-54-59.bpo-33009.-Ekysb.rst
new file mode 100644
index 000000000000..96bc70a8c944
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-03-06-11-54-59.bpo-33009.-Ekysb.rst
@@ -0,0 +1 @@
+Fix inspect.signature() for single-parameter partialmethods.



More information about the Python-checkins mailing list