- Notifications
You must be signed in to change notification settings - Fork749
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.
>>>importsys>>>importclr>>>sys.path.append('path/to/libs')>>>clr.AddReference('LibreMetaverse')# Contains OpenMetaverse namespace<System.Reflection.RuntimeAssemblyobjectat0x0000023EB7403CC0>>>>fromOpenMetaverseimportVector3>>>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>'
TheVector3
struct contains
...public static Vector3Add(Vector3value1,Vector3value2){value1.X+=value2.X;value1.Y+=value2.Y;value1.Z+=value2.Z;returnvalue1;}...public static Vector3operator+(Vector3value1,Vector3value2){value1.X+=value2.X; value1.Y+=value2.Y; value1.Z+=value2.Z;returnvalue1;}...
Does Pythonnet not bind arithmetic operator methods in CLR to Python magic methods? Or am I missing something?
Metadata
Metadata
Assignees
Labels
No labels