]> granicus.if.org Git - python/commitdiff
bpo-37108: Support super with methods that use positional-only arguments (GH-13695)
authorPablo Galindo <Pablogsal@gmail.com>
Fri, 31 May 2019 11:07:56 +0000 (12:07 +0100)
committerGitHub <noreply@github.com>
Fri, 31 May 2019 11:07:56 +0000 (12:07 +0100)
Lib/test/test_positional_only_arg.py
Objects/typeobject.c

index d4d259ef2693c414012c3dea2a8a54219d64ef89..0aaad84cb3bfcd6ff99ae485bbed4517d5721b81 100644 (file)
@@ -398,6 +398,20 @@ class PositionalOnlyTestCase(unittest.TestCase):
         gen = f()
         self.assertEqual(next(gen), (1, 2))
 
+    def test_super(self):
+
+        sentinel = object()
+
+        class A:
+            def method(self):
+                return sentinel
+
+        class C(A):
+            def method(self, /):
+                return super().method()
+
+        self.assertEqual(C().method(), sentinel)
+
 
 if __name__ == "__main__":
     unittest.main()
index b6d925c1442e782179b7164a61e09e6bbcbe0cad..da249b569ad2bb397b767f1dfd001d5e24af9ccd 100644 (file)
@@ -7807,7 +7807,7 @@ super_init(PyObject *self, PyObject *args, PyObject *kwds)
                             "super(): no code object");
             return -1;
         }
-        if (co->co_argcount == 0) {
+        if (co->co_posonlyargcount + co->co_argcount == 0) {
             PyErr_SetString(PyExc_RuntimeError,
                             "super(): no arguments");
             return -1;