diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html
index 937672c2a..5237dfe68 100644
--- a/Doc/Manual/Python.html
+++ b/Doc/Manual/Python.html
@@ -957,6 +957,7 @@ swig -python -help
| -doxygen | Convert C++ doxygen comments to pydoc comments in proxy classes |
| -extranative | Return extra native wrappers for C++ std containers wherever possible |
| -fastproxy | Use fast proxy mechanism for member methods |
+| -flatstaticmethod | Generate Foo_bar for static method Foo::bar |
| -globals <name> | Set <name> used to access C global variable (default: 'cvar') |
| -interface <mod> | Set low-level C/C++ module name to <mod> (default: module name prefixed by '_') |
| -keyword | Use keyword arguments |
@@ -1616,16 +1617,15 @@ In Python, the static member can be accessed in three different ways:
->>> example.Spam_foo() # Spam::foo()
>>> s = example.Spam()
>>> s.foo() # Spam::foo() via an instance
->>> example.Spam.foo() # Spam::foo() using Python-2.2 and later
+>>> example.Spam.foo() # Spam::foo() using class method
+>>> example.Spam_foo() # Spam::foo() "flattened" name
-The first two methods of access are supported in all versions of Python. The
-last technique is only available in Python-2.2 and later versions.
+The last technique is only available when using the -flatstaticmethod option.
diff --git a/Examples/test-suite/python/Makefile.in b/Examples/test-suite/python/Makefile.in
index cc6adeb69..c232829f3 100644
--- a/Examples/test-suite/python/Makefile.in
+++ b/Examples/test-suite/python/Makefile.in
@@ -100,7 +100,7 @@ LIBS = -L.
VALGRIND_OPT += --suppressions=pythonswig.supp
# Custom tests - tests with additional commandline options
-#python_flatstaticmethod.cpptest: SWIGOPT += -flatstaticmethod
+python_flatstaticmethod.cpptest: SWIGOPT += -flatstaticmethod
# Rules for the different types of tests
%.cpptest:
diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx
index 69c13db48..bf2ad79c9 100644
--- a/Source/Modules/python.cxx
+++ b/Source/Modules/python.cxx
@@ -93,6 +93,7 @@ static int castmode = 0;
static int extranative = 0;
static int nortti = 0;
static int relativeimport = 0;
+static int flat_static_method = 0;
/* flags for the make_autodoc function */
namespace {
@@ -118,6 +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\
-globals - Set used to access C global variable (default: 'cvar')\n\
-interface - Set low-level C/C++ module name to (default: module name prefixed by '_')\n\
-keyword - Use keyword arguments\n";
@@ -373,6 +375,9 @@ public:
} else if (strcmp(argv[i], "-extranative") == 0) {
extranative = 1;
Swig_mark_arg(i);
+ } else if (strcmp(argv[i], "-flatstaticmethod") == 0) {
+ flat_static_method = 1;
+ Swig_mark_arg(i);
} else if (strcmp(argv[i], "-noh") == 0) {
no_header_file = 1;
Swig_mark_arg(i);
@@ -2636,11 +2641,11 @@ public:
Printv(f->code, "}\n", NIL);
Wrapper_print(f, f_wrappers);
Node *p = Getattr(n, "sym:previousSibling");
- if (!builtin_self)
+ if (!builtin_self && (flat_static_method || !in_class || !builtin))
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))) {
+ if (!builtin && (shadow) && (!(shadow & PYSHADOW_MEMBER)) && (flat_static_method || !in_class)) {
emitFunctionShadowHelper(n, in_class ? f_shadow_stubs : f_shadow, symname, 0);
}
DelWrapper(f);
@@ -3309,11 +3314,11 @@ public:
/* Now register the function with the interpreter. */
if (!Getattr(n, "sym:overloaded")) {
- if (!builtin_self)
+ if (!builtin_self && (flat_static_method || !in_class || !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))) {
+ if (!builtin && (shadow) && (!(shadow & PYSHADOW_MEMBER)) && (flat_static_method || !in_class)) {
emitFunctionShadowHelper(n, in_class ? f_shadow_stubs : f_shadow, iname, allow_kwargs);
}
} else {