[Python] Add missing Python kwargs builtin support

Accept keyword arguments accessing C++ static member functions when
using -builtin and kwargs feature and Python class staticmethod syntax.
The missing keyword argument support was only when using the
class staticmethod syntax, not when using the flat static method
syntax.
This commit is contained in:
William S Fulton 2022-01-11 23:33:22 +00:00
parent cf8788c411
commit 627f7214db
4 changed files with 13 additions and 2 deletions

View File

@ -7,6 +7,13 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
Version 4.1.0 (in progress)
===========================
2022-01-11: wsfulton
[Python] Accept keyword arguments accessing static member functions when
using -builtin and kwargs feature and Python class staticmethod syntax.
The missing keyword argument support was only when using the
class staticmethod syntax, such as Klass.memberfunction, and not when
using the flat static method syntax, such as Klass_memberfunction.
2022-01-04: juierror
[Go] #2045 Add support for std::array in std_array.i.

View File

@ -27,6 +27,7 @@
virtual int foo(int a = 1, int b = 0) {return a + b; }
static int statfoo(int a = 1, int b = 0) {return a + b; }
static int statfoo_onearg(int x = 10) {return x + x; }
static Foo *create(int a = 1, int b = 0)
{

View File

@ -18,6 +18,9 @@ if f.foo(b=1, a=2) != 3:
if Foo.statfoo(b=2) != 3:
raise RuntimeError
if Foo.statfoo_onearg(x=4) != 8:
raise RuntimeError
if f.efoo(b=2) != 3:
raise RuntimeError

View File

@ -4727,6 +4727,7 @@ public:
Swig_restore(n);
}
int kw = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0;
if (builtin && in_class) {
if ((GetFlagAttr(n, "feature:extend") || checkAttribute(n, "access", "public"))
&& !Getattr(class_members, symname)) {
@ -4741,7 +4742,7 @@ public:
else if (funpack && argcount == 1)
Append(pyflags, "METH_O");
else
Append(pyflags, "METH_VARARGS");
Append(pyflags, kw ? "METH_VARARGS|METH_KEYWORDS" : "METH_VARARGS");
// Cast via void(*)(void) to suppress GCC -Wcast-function-type warning.
// Python should always call the function correctly, but the Python C
// API requires us to store it in function pointer of a different type.
@ -4767,7 +4768,6 @@ public:
String *staticfunc_name = NewString(fastproxy ? "_swig_new_static_method" : "staticmethod");
bool fast = (fastproxy && !have_addtofunc(n)) || Getattr(n, "feature:callback");
if (!fast || olddefs) {
int kw = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0;
String *parms = make_pyParmList(n, false, false, kw);
String *callParms = make_pyParmList(n, false, true, kw);
Printv(f_shadow, "\n", tab4, "@staticmethod", NIL);