[Python.NET] Selecting an overloaded constructor + a MethodBinder.Bind patch

Dave dave.hirschfeld at gmail.com
Wed Jul 28 15:30:27 CEST 2010


Barton <barton at ...> writes:

> 
>   In case anyone is interested:
> I have added a Constructors object named '__overloads__' to the 
> ClassObject.__dict__ that has the necessary machinery to select 
> overloaded constructors using subscript notation, as in:
> from System import String, Char, Int32
> s = String.__overloads__[Char, Int32]('A', 10)
> or
> from System import Array
> CharArrType = Array[Char]
> StringFromCharArr = String.__overloads__[CharArrType]
> s = StringFromCharArr(list('hello'))
> 
> Just as in MethodObject, I implement a Descriptor __get__() in managed 
> code that returns a CtorMapper for ctor selection and invoking.
> 
> Also fixed a bug in MethodBinder.Bind() that threw an unhandled 
> InvalidCastException when calling a non-static method on a class rather 
> than on an instance of the class.  Here's the patch as it stands:
> diff --git a/src/runtime/methodbinder.cs b/src/runtime/methodbinder.cs
> index 862a110..f1bc042 100644

Thanks for posting - could be useful for in future (I'm not using PythonDotNET
much at the moment but will be again shortly.)

Not sure if you've seen this but in the spirit of posting patches I thought
I'd mention Alexey Borzenkov's patch:

http://git.kitsu.ru/patched/pythonnet.git?a=commitdiff;h=995109e3ed27d6061dde5376f2968c9fbad894b7

Which fixes the problem of errors in constructors not being passed through to
Python.

HTH,
Dave



More information about the PythonDotNet mailing list