Discussion:
[Python.NET] Operator overloading for managed objects
Oleksii Bidiuk
2011-01-21 09:25:45 UTC
Permalink
Hi,

did anybody have experience with using overloaded operators for managed
objects? I have a class that have e.g. the operator+ overloaded in C#, but
that does not seem to be picked up from the Python side. I have tried to add
overloading using the setattr(MyType, "name", method_name), but it only seem
to work for the native Python objects and not for the managed objects. In
both cases I get "TypeError: unsupported operand type(s) for +: 'MyType' and
'MyType'".

Thanks in advance!
--
oleksii
Oleksii Bidiuk
2011-02-08 09:13:08 UTC
Permalink
Hi All,

I am sorry for repeating the question, but I would like to make sure I am
not overlooking something here. Is this a known limitation that the
operators overloaded in C# are not working from CPython? So far I had
written CPython wrappers for the .NET objects that provide proper operators
implementation which is then redirected to explicit C# calls. While this
provides 'native' CPython experience and gives additional control over the
API exposed to a script (to some extend), it results in extra work, which is
mostly a problem on the long term when both C# and Python equivalents have
to be maintained in parallel.

did anybody have experience with using overloaded operators for managed
Post by Oleksii Bidiuk
objects? I have a class that have e.g. the operator+ overloaded in C#, but
that does not seem to be picked up from the Python side. I have tried to add
overloading using the setattr(MyType, "name", method_name), but it only seem
to work for the native Python objects and not for the managed objects. In
both cases I get "TypeError: unsupported operand type(s) for +: 'MyType' and
'MyType'".
Thanks in advance!
--
oleksii
Loading...