Fix handling of default arguments after ignored ones in Python.

Don't skip checking subsequent arguments just because one of them has "in"
typemap with numinputs=0 attribute.

Add a unit test showing the problem which is relatively rare as it doesn't
happen for the class methods and is hidden unless autodoc feature is used for
the global functions.

Closes #377.
This commit is contained in:
Vadim Zeitlin 2015-04-27 23:14:34 +02:00
commit 6988b00aba
4 changed files with 28 additions and 5 deletions

View file

@ -278,3 +278,17 @@ struct ConstMethods {
} Pointf;
}
%}
// Default arguments after ignored ones.
%typemap(in, numinputs=0) int square_error { $1 = 2; };
%typemap(default, noblock=1) int def17 { $1 = 17; };
// Enabling autodoc feature has a side effect of disabling the generation of
// aliases for functions that can hide problems with default arguments at
// Python level.
%feature("autodoc","0") slightly_off_square;
%inline %{
inline int slightly_off_square(int square_error, int def17) { return def17*def17 + square_error; }
%}

View file

@ -110,6 +110,13 @@ def run(module_name):
default_args.trickyvalue3(10); default_args.trickyvalue3(10, 10)
default_args.seek(); default_args.seek(10)
if default_args.slightly_off_square(10) != 102:
raise RuntimeError
if default_args.slightly_off_square() != 291:
raise RuntimeError
if __name__=="__main__":
run('default_args')