Changing return of type(obj)

Terry Reedy tjreedy at udel.edu
Fri Feb 6 13:30:57 EST 2009


Ken Elkabany wrote:
> Hello,
> 
> I am attempting to fully-simulate an 'int' object with a custom object 
> type. It is part of a library I am creating for python futures and 
> promises. Is there anyway such that type(my_object) can return <type 
> 'int'>? Or for that matter, any other primitive? I do not care how dirty 
> the solution might possibly be; Could there be a way through the C API? 
> Though I predict it will cause a mess with the interpreter.

type(o) == o.__class__

o.__class__ can only be rebound if and only if it is a user-class (heap 
type) and then only to another (compatible) user-class (heap type).




More information about the Python-list mailing list