|
From: Dave V. <dv...@gr...> - 2017-09-19 13:44:40
|
On 9/19/2017 2:48 AM, William S Fulton wrote:
>
>
> On 18 September 2017 at 19:37, Dave Vitek <dv...@gr...
> <mailto:dv...@gr...>> wrote:
>
> On 9/18/2017 2:03 PM, William S Fulton wrote:
>>
>>
>> On 7 August 2017 at 22:34, Dave Vitek <dv...@gr...
>> <mailto:dv...@gr...>> wrote:
>>
>> Hi all,
>>
>> If I use %exceptionclass with python, then staticmethods
>> don't get attached to the class. I've tracked down the cause
>> of the problem.
>>
>> In python.cxx, we have:
>>
>> if (GetFlag(n, "feature:exceptionclass")) {
>> classic = 1;
>> modern = 0;
>> }
>>
>> Introduced many years ago by:
>> https://github.com/swig/swig/commit/bab11e11f4a9bbd016a15dd5abf56dd12f1368c2
>> <https://github.com/swig/swig/commit/bab11e11f4a9bbd016a15dd5abf56dd12f1368c2>
>>
>> It prevents this code from executing:
>>
>> if (!classic) {
>> if (!modern)
>> Printv(f_shadow, tab4, "if _newclass:\n", tab4, NIL);
>> Printv(f_shadow, tab4, symname, " = staticmethod(",
>> module, ".", Swig_name_member(NSPACE_TODO, class_name, symname),
>> ")\n", NIL);
>> }
>>
>> This means that Exception classes will not have static
>> methods in python. Does anyone know the intent of the
>> "classic = 1" assignment? Is there a good reason why classes
>> inheriting from Exception cannot have static methods?
>>
>>
>> I can't think why this change was put for %exceptionclass.
>> Perhaps something to do with exception classes shouldn't be
>> derived from object, but instead should be derived from
>> Exception?? classic mode removes classes being derived from
>> object. Perhaps you can try see if it works as you'd like it and
>> send a patch in to fix.
>>
>> William
> Here's the patch we've been using successfully since the day I
> sent the OP. The globals are a little nasty, but this was the
> best way to avoid changing behavior in other respects.
>
> Thanks. Thinking about it further, as we are going to drop the
> -classic and -modern options in swig-4.0.0, this should just get
> resolved without the need to add in the additional complexity this
> patch introduces.
>
> William
>
One thing I noticed about "-O" that scared me away was that when a
function is passed the wrong types of arguments, it no longer emits the
full list of overloads. Instead, the exception only describes one of
possibly many overloads. It would be nice if it were still possible to
get the full list of overloads in the next version.
|