Changing return of type(obj)

Ken Elkabany Ken at
Fri Feb 6 12:49:17 CET 2009

I would simply subclass 'int', but this object needs to be general enough to
pretend to be an 'int', 'NoneType', 'str', etc... A long shot: Can I change
the base class on an instance by instance basis depending on the need? Well,
now I can imagine having a class factory that will spawn for me the class
that inherits the correct base type. Any other solutions?

Thanks Chris.

On Fri, Feb 6, 2009 at 3:42 AM, Chris Rebert <clp2 at> wrote:

> On Fri, Feb 6, 2009 at 3:03 AM, Ken Elkabany <Ken at> 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.
> Any particular reason why subclassing 'int' wouldn't be good enough?
> (You did know you can do that, right?)
> I know you can subclass int at the Python level and I would think you
> should be able to do it at the C level also (if not, the design just
> gets only slightly more involved).
> Cheers,
> Chris
> --
> Follow the path of the Iguana...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list