Closed
Description
Environment
- Pythonnet version: 2.4.0
- Python version: 3.6.5
- Operating System: Windows 10
Details
While trying to use the add operator with two CLR classes (structs, actually), I ran into trouble. I expect the + operator to work in Python like it would in C#, but instead it raises an exception.
>>> import sys
>>> import clr
>>> sys.path.append('path/to/libs')
>>> clr.AddReference('LibreMetaverse') # Contains OpenMetaverse namespace
<System.Reflection.RuntimeAssembly object at 0x0000023EB7403CC0>
>>> from OpenMetaverse import Vector3
>>> a = Vector3(1.0, 2.0, 3.0)
>>> b = Vector3(2.0, 4.0, 6.0)
>>> a + b # Results in an error...
Traceback (most recent call last):
File "<input>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'Vector3' and 'Vector3'
>>> str(Vector3.Add(a, b)) # But this works!
'<3, 6, 9>'
The Vector3
struct contains
...
public static Vector3 Add(Vector3 value1, Vector3 value2)
{
value1.X += value2.X;
value1.Y += value2.Y;
value1.Z += value2.Z;
return value1;
}
...
public static Vector3 operator +(Vector3 value1, Vector3 value2)
{
value1.X += value2.X;
value1.Y += value2.Y;
value1.Z += value2.Z;
return value1;
}
...
Does Pythonnet not bind arithmetic operator methods in CLR to Python magic methods? Or am I missing something?
Metadata
Metadata
Assignees
Labels
No labels