Fix bug in Python builtin support for keyword args
The fix is when using kwargs feature or -keyword. The fix is in the argument error checking when wrapping zero argument constructors only. Supplied keyword args were silently ignored. Issue #1595
This commit is contained in:
parent
e4c38f0f67
commit
cb5d7398b5
4 changed files with 86 additions and 7 deletions
|
|
@ -100,3 +100,29 @@
|
|||
|
||||
int foo_mm(int min = 1, int max = 2) {return min + max; }
|
||||
%}
|
||||
|
||||
|
||||
// Extended constructors
|
||||
%extend Extending0 {
|
||||
Extending0() { return new Extending0(); }
|
||||
}
|
||||
%extend Extending1 {
|
||||
Extending1(int one) { return new Extending1(); }
|
||||
}
|
||||
%extend Extending2 {
|
||||
Extending2(int one, const char *two) { return new Extending2(); }
|
||||
}
|
||||
%extend ExtendingOptArgs1 {
|
||||
ExtendingOptArgs1(int one = 0) { return new ExtendingOptArgs1(); }
|
||||
}
|
||||
%extend ExtendingOptArgs2 {
|
||||
ExtendingOptArgs2(int one = 0, const char* two = NULL) { return new ExtendingOptArgs2(); }
|
||||
}
|
||||
|
||||
%inline %{
|
||||
struct Extending0 {};
|
||||
struct Extending1 {};
|
||||
struct Extending2 {};
|
||||
struct ExtendingOptArgs1 {};
|
||||
struct ExtendingOptArgs2 {};
|
||||
%}
|
||||
|
|
|
|||
|
|
@ -79,3 +79,46 @@ if rfoo(n=11, x=22) != -11:
|
|||
|
||||
if rfoo(x=11, n=22) != 11:
|
||||
raise RuntimeError
|
||||
|
||||
# Extended constructors
|
||||
e = Extending0()
|
||||
e = Extending1(one=1)
|
||||
e = Extending1(1)
|
||||
e = Extending2(1, "two")
|
||||
e = Extending2(1, two="two")
|
||||
e = Extending2(two="two", one=1)
|
||||
e = ExtendingOptArgs1()
|
||||
e = ExtendingOptArgs1(1)
|
||||
e = ExtendingOptArgs2(one=1)
|
||||
e = ExtendingOptArgs2()
|
||||
e = ExtendingOptArgs2(one=1)
|
||||
e = ExtendingOptArgs2(two="two")
|
||||
e = ExtendingOptArgs2(two="two", one=1)
|
||||
|
||||
# Invalid kwargs test
|
||||
h = Hello()
|
||||
try:
|
||||
h = Hello(nonexistent=10)
|
||||
raise RuntimeError("missed exception")
|
||||
except TypeError as e:
|
||||
pass
|
||||
|
||||
f = Foo(1)
|
||||
f = Foo(a=1)
|
||||
try:
|
||||
f = Foo(nonexistent=10)
|
||||
raise RuntimeError("missed exception")
|
||||
except TypeError as e:
|
||||
pass
|
||||
|
||||
try:
|
||||
f = Foo(a=1, nonexistent=10)
|
||||
raise RuntimeError("missed exception")
|
||||
except TypeError as e:
|
||||
pass
|
||||
|
||||
try:
|
||||
f = Foo(1, nonexistent=10)
|
||||
raise RuntimeError("missed exception")
|
||||
except TypeError as e:
|
||||
pass
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue