Skip to content

Provide hook to implement __repr__ #808

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

Merged
merged 17 commits into from
Oct 18, 2019
Prev Previous commit
Next Next commit
fix
  • Loading branch information
koubaa committed Sep 15, 2019
commit 00b55db17ae0e3d15d0ff2bda6ead06fac06b040
7 changes: 4 additions & 3 deletions src/runtime/classbase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,12 @@ public static IntPtr tp_str(IntPtr ob)

//First check which type in the object hierarchy provides ToString()
//ToString has two "official" overloads so loop over GetMethods to get the one without parameters
var method = type.GetMethod("ToString", new Type[]{});
if (method.DeclaringTyppe != typeof(object))
var instType = co.inst.GetType();
var method = instType.GetMethod("ToString", new Type[]{});
if (method.DeclaringType != typeof(object))
{
//match! something other than object provides a parameter-less overload of ToString
return Runtime.Pystring_FromString(co.inst.ToString());
return Runtime.PyString_FromString(co.inst.ToString());
}

//If the object defines __repr__, call it.
Expand Down