@@ -233,6 +233,7 @@ public static IntPtr tp_str(IntPtr ob)
233233 }
234234 try
235235 {
236+ Console . WriteLine ( "classbase tp_str" ) ;
236237 //As per python doc:
237238 //The return value must be a string object. If a class defines __repr__() but not __str__(),
238239 //then __repr__() is also used when an “informal” string representation of instances of that
@@ -245,25 +246,32 @@ public static IntPtr tp_str(IntPtr ob)
245246 var instType = co . inst . GetType ( ) ;
246247 foreach ( var method in instType . GetMethods ( ) )
247248 {
248-
249+ Console . WriteLine ( "classbase tp_str in loop" ) ;
249250 //TODO this could probably be done more cleanly with Linq
250251 if ( ! method . IsPublic ) continue ; //skip private/protected methods
251252 if ( method . Name != "ToString" ) continue ; //only look for ToString
252253 if ( method . DeclaringType == typeof ( object ) ) continue ; //ignore default from object
253254 if ( method . GetParameters ( ) . Length != 0 ) continue ; //ignore Formatter overload of ToString
254255
256+ Console . WriteLine ( "classbase tp_str in loop end" ) ;
257+
255258 //match! something other than object provides a parameter-less overload of ToString
256259 return Runtime . PyString_FromString ( co . inst . ToString ( ) ) ;
257260 }
258261
262+ Console . WriteLine ( "classbase tp_str after loop" ) ;
263+
259264 //If the object defines __repr__, call it.
260265 System . Reflection . MethodInfo reprMethodInfo = instType . GetMethod ( "__repr__" ) ;
261266 if ( reprMethodInfo != null && reprMethodInfo . IsPublic )
262267 {
268+ Console . WriteLine ( "classbase tp_str has __repr__" ) ;
263269 var reprString = reprMethodInfo . Invoke ( co . inst , null ) as string ;
264270 return Runtime . PyString_FromString ( reprString ) ;
265271 }
266272
273+ Console . WriteLine ( "classbase tp_str fallback" ) ;
274+
267275 //otherwise fallback to object's ToString() implementation
268276 return Runtime . PyString_FromString ( co . inst . ToString ( ) ) ;
269277
@@ -288,6 +296,7 @@ public static IntPtr tp_repr(IntPtr ob)
288296 }
289297 try
290298 {
299+ Console . WriteLine ( "classbase tp_repr" ) ;
291300 //if __repr__ is defined, use it
292301 var instType = co . inst . GetType ( ) ;
293302 System . Reflection . MethodInfo methodInfo = instType . GetMethod ( "__repr__" ) ;
@@ -297,6 +306,8 @@ public static IntPtr tp_repr(IntPtr ob)
297306 return Runtime . PyString_FromString ( reprString ) ;
298307 }
299308
309+ Console . WriteLine ( "classbase tp_repr fallback" ) ;
310+
300311 //otherwise use the standard object.__repr__(inst)
301312 IntPtr args = Runtime . PyTuple_New ( 1 ) ;
302313 Runtime . PyTuple_SetItem ( args , 0 , ob ) ;
0 commit comments