-
Notifications
You must be signed in to change notification settings - Fork 747
How to implement __repr__ for a C# class to be used in python.net? #680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@AlexArcPy have you tried implementing pythonnet/src/runtime/pyobject.cs Line 851 in 06ded7a
pythonnet/src/runtime/pyobject.cs Line 867 in 06ded7a
|
@denfromufa , thanks for the comment. I've just tried, but to no effect.
In a Python IDE shell:
In a cmd-based Python interpreter:
Should I be implementing this method in any kind of special way? |
@AlexArcPy looks like i was wrong, i'm not sure how this is possible to implement. |
@AlexArcPy ok, i took a second look and the first step is to find out which https://github.com/pythonnet/pythonnet/search?p=1&q=tp_repr&unscoped_q=tp_repr After that we can tell if it is possible to implement |
@denfromufa , thanks a lot for digging into. This is definitely not a top priority feature to work on, so no stress! Should you find something more - please post! Thanks! |
I've got a working implementation (it uses reflection to call In standard CPython its done via Also, the behavior according to python documentation is this: Do we want this in pythonnet too? |
I was able to figure it out. I'll make a pull request with my changes (including the behavior from the python doc I mentioned above). |
@koubaa thanks for this PR, let's get the CI tests passed. |
Environment
Details
I have a C# class library which I use in Python. I have a
Point
class (a code snippet):When I work with this class library in Python (in Python shell):
Because I override the
ToString()
, when I runstr(p1)
I see my custom view of the object. However, when I just access a variablep1
, then it goes to the__repr__()
method under the hood which gives me ugly<Geometry.Point object at 0x000000000558F828>
.Is there a method in C# class that is possible to override so that
pythonnet
would use that method when getting the__repr__
?The text was updated successfully, but these errors were encountered: