]> granicus.if.org Git - python/commitdiff
bpo-33009: Fix inspect.signature() for single-parameter partialmethods. (GH-6004)
authorYury Selivanov <yury@magic.io>
Tue, 6 Mar 2018 17:59:45 +0000 (12:59 -0500)
committerGitHub <noreply@github.com>
Tue, 6 Mar 2018 17:59:45 +0000 (12:59 -0500)
Lib/inspect.py
Lib/test/test_inspect.py
Misc/NEWS.d/next/Library/2018-03-06-11-54-59.bpo-33009.-Ekysb.rst [new file with mode: 0644]

index 57c04877c743d2947c6bdb5b027578e558c79e65..512785f9237ea26aedb896aedac72535e4fa91e6 100644 (file)
@@ -2254,7 +2254,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)
 
index 1a856f6387e8adaae67d166fb6fe0b9b71cc7eae..3481a57ec833607b8d9a9e1044edb1573976e3e5 100644 (file)
@@ -2580,6 +2580,16 @@ class TestSignatureObject(unittest.TestCase):
                            ('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 (file)
index 0000000..96bc70a
--- /dev/null
@@ -0,0 +1 @@
+Fix inspect.signature() for single-parameter partialmethods.