From b45164e098aa8836601364b9a4c9c6e44b21b2de Mon Sep 17 00:00:00 2001 From: Alec Cooper Date: Mon, 25 Jan 2016 12:28:36 -0500 Subject: [PATCH] Support python(pre|ap)pend on static methods in classic mode Adding a test that covers this case to the python_append test-suite Note: staticmethod function has been available since Python 2.2 --- Examples/test-suite/python/python_append_runme.py | 7 +++++++ Examples/test-suite/python_append.i | 3 +++ Source/Modules/python.cxx | 4 +--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Examples/test-suite/python/python_append_runme.py b/Examples/test-suite/python/python_append_runme.py index 2f6d94d9c..6675f3509 100644 --- a/Examples/test-suite/python/python_append_runme.py +++ b/Examples/test-suite/python/python_append_runme.py @@ -20,3 +20,10 @@ if grabpath() != os.path.dirname(mypath): if grabstaticpath() != os.path.basename(mypath): raise RuntimeError("grabstaticpath failed") + +clearstaticpath() +if grabstaticpath() != None: + raise RuntimeError("Resetting staticfuncpath failed") +Test.static_func() +if grabstaticpath() != os.path.basename(mypath): + raise RuntimeError("grabstaticpath failed") diff --git a/Examples/test-suite/python_append.i b/Examples/test-suite/python_append.i index f37a6c199..2a71b5784 100644 --- a/Examples/test-suite/python_append.i +++ b/Examples/test-suite/python_append.i @@ -12,6 +12,9 @@ def grabpath(): return funcpath def grabstaticpath(): return staticfuncpath +def clearstaticpath(): + global staticfuncpath + staticfuncpath = None %} %pythonappend Test::func %{ diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 7526a80fa..1c8169a36 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -4710,7 +4710,7 @@ public: } if (shadow) { - if (!classic && !Getattr(n, "feature:python:callback") && have_addtofunc(n)) { + if (!Getattr(n, "feature:python:callback") && have_addtofunc(n)) { 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); @@ -4726,8 +4726,6 @@ public: } else { Printv(f_shadow, tab8, "return ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n\n", NIL); } - if (!modern) - Printv(f_shadow, tab4, "if _newclass:\n", tab4, NIL); Printv(f_shadow, tab4, symname, " = staticmethod(", symname, ")\n", NIL); if (!modern) {