[Python-checkins] bpo-37108: Support super with methods that use positional-only arguments (GH-13695)

Pablo Galindo webhook-mailer at python.org
Fri May 31 07:08:00 EDT 2019


https://github.com/python/cpython/commit/3a46d5c293d39995dc5218bf46a7d92b16fb2a15
commit: 3a46d5c293d39995dc5218bf46a7d92b16fb2a15
branch: master
author: Pablo Galindo <Pablogsal at gmail.com>
committer: GitHub <noreply at github.com>
date: 2019-05-31T12:07:56+01:00
summary:

bpo-37108: Support super with methods that use positional-only arguments (GH-13695)

files:
M Lib/test/test_positional_only_arg.py
M Objects/typeobject.c

diff --git a/Lib/test/test_positional_only_arg.py b/Lib/test/test_positional_only_arg.py
index d4d259ef2693..0aaad84cb3bf 100644
--- a/Lib/test/test_positional_only_arg.py
+++ b/Lib/test/test_positional_only_arg.py
@@ -398,6 +398,20 @@ def f(a=1, /, b=2):
         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()
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index b6d925c1442e..da249b569ad2 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -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;



More information about the Python-checkins mailing list