Python -flatstaticmethod corrections
Correct logic for suppressing static methods. Previous logic was missing director disown methods. Add changes file entry for -flatstaticmethod. Closes #2137
This commit is contained in:
parent
b8f10a55f9
commit
21c2e47661
3 changed files with 21 additions and 5 deletions
|
|
@ -7,6 +7,20 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
|
|||
Version 4.1.0 (in progress)
|
||||
===========================
|
||||
|
||||
2022-03-21: jschueller, jim-easterbrook, wsfulton
|
||||
[Python] #2137 C++ static member functions no longer generate a "flattened"
|
||||
name in the Python module. For example:
|
||||
|
||||
s = example.Spam()
|
||||
s.foo() # Spam::foo() via an instance
|
||||
example.Spam.foo() # Spam::foo() using class method
|
||||
example.Spam_foo() # Spam::foo() "flattened" name
|
||||
|
||||
The "flattened" name is no longer generated, but can be generated
|
||||
by using the new -flatstaticmethod option.
|
||||
|
||||
*** POTENTIAL INCOMPATIBILITY ***
|
||||
|
||||
2022-03-17: olly
|
||||
[Python] #1779 SWIG's Python test-suite and examples are now
|
||||
run with Python 3 by default. To run them with Python 2, set
|
||||
|
|
|
|||
|
|
@ -957,7 +957,7 @@ swig -python -help
|
|||
<tr><td>-doxygen </td><td>Convert C++ doxygen comments to pydoc comments in proxy classes</td></tr>
|
||||
<tr><td>-extranative </td><td>Return extra native wrappers for C++ std containers wherever possible</td></tr>
|
||||
<tr><td>-fastproxy </td><td>Use fast proxy mechanism for member methods</td></tr>
|
||||
<tr><td>-flatstaticmethod </td><td>Generate Foo_bar for static method Foo::bar</td></tr>
|
||||
<tr><td>-flatstaticmethod </td><td>Generate additional flattened Python methods for C++ static methods</td></tr>
|
||||
<tr><td>-globals <name> </td><td>Set <name> used to access C global variable (default: 'cvar')</td></tr>
|
||||
<tr><td>-interface <mod></td><td>Set low-level C/C++ module name to <mod> (default: module name prefixed by '_')</td></tr>
|
||||
<tr><td>-keyword </td><td>Use keyword arguments</td></tr>
|
||||
|
|
@ -1626,6 +1626,8 @@ In Python, the static member can be accessed in three different ways:
|
|||
|
||||
<p>
|
||||
The last technique is only available when using the <tt>-flatstaticmethod</tt> option.
|
||||
This option is not recommended, it is only available for backwards compatibility
|
||||
as ancient versions of Python did not have Python class methods.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ Python Options (available with -python)\n\
|
|||
-doxygen - Convert C++ doxygen comments to pydoc comments in proxy classes\n\
|
||||
-extranative - Return extra native wrappers for C++ std containers wherever possible\n\
|
||||
-fastproxy - Use fast proxy mechanism for member methods\n\
|
||||
-flatstaticmethod - Generate Foo_bar for static method Foo::bar\n\
|
||||
-flatstaticmethod - Generate additional flattened Python methods for C++ static methods\n\
|
||||
-globals <name> - Set <name> used to access C global variable (default: 'cvar')\n\
|
||||
-interface <mod>- Set low-level C/C++ module name to <mod> (default: module name prefixed by '_')\n\
|
||||
-keyword - Use keyword arguments\n";
|
||||
|
|
@ -2645,7 +2645,7 @@ public:
|
|||
add_method(symname, wname, 0, p);
|
||||
|
||||
/* Create a shadow for this function (if enabled and not in a member function) */
|
||||
if (!builtin && (shadow) && (!(shadow & PYSHADOW_MEMBER)) && (use_static_method)) {
|
||||
if (!builtin && shadow && (!(shadow & PYSHADOW_MEMBER)) && use_static_method) {
|
||||
emitFunctionShadowHelper(n, in_class ? f_shadow_stubs : f_shadow, symname, 0);
|
||||
}
|
||||
DelWrapper(f);
|
||||
|
|
@ -3312,14 +3312,14 @@ public:
|
|||
Wrapper_print(f, f_wrappers);
|
||||
}
|
||||
|
||||
bool use_static_method = flat_static_method || !in_class || constructor || (Cmp(storage, "friend") == 0);
|
||||
bool use_static_method = flat_static_method || !Swig_storage_isstatic_custom(n, "staticmemberfunctionHandler:storage");
|
||||
/* Now register the function with the interpreter. */
|
||||
if (!Getattr(n, "sym:overloaded")) {
|
||||
if (!builtin_self && (use_static_method || !builtin))
|
||||
add_method(iname, wname, allow_kwargs, n, funpack, num_required, num_arguments);
|
||||
|
||||
/* Create a shadow for this function (if enabled and not in a member function) */
|
||||
if (!builtin && (shadow) && (!(shadow & PYSHADOW_MEMBER)) && (use_static_method)) {
|
||||
if (!builtin && shadow && (!(shadow & PYSHADOW_MEMBER)) && use_static_method) {
|
||||
emitFunctionShadowHelper(n, in_class ? f_shadow_stubs : f_shadow, iname, allow_kwargs);
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue