prep my types for 2.2?

Michael Hudson mwh at
Mon Nov 26 13:21:48 CET 2001

Pete Shinners <pete at> writes:

> > Python will look at the type of your_type (which will be the type
> > type), and then look at its tp_call slot
> > (i.e. typeobject.c:type_call). That, in turn, will use tp_new.
> this is where i start to get confused?
> isn't the "Type type" the same for all type objects? for example..
> 	>>> type(int) is type(float)
> 	1
> since this is both the same thing, how can i change the tp_call for
> only one of the types?

class C:
 def foo(self):
  print 1, id(self)

c = C()
d = C()

But how can these calls be different?  c.__class__ is d.__class__!

Same thing.

In less obscure terms: when you call <type-object>(stuff), the first
argument to the C function that implements this
(Objects/typeobject.c:type_call) is <type-object>.  It's this type
object's tp_new that is called.

If you were calling type(int)(1), then you'd have a point.

> i was guessing there was some sort of new function slot for this, but
> the docs on all this are a little sparse.

This is true.


  In general, I'd recommend injecting LSD directly into your temples,
  Syd-Barret-style, before mucking with Motif's resource framework.
  The former has far lower odds of leading directly to terminal
  insanity.                                            -- Dan Martinez

More information about the Python-list mailing list