[Python-bugs-list] [ python-Bugs-472234 ] type(obj) calls type->tp_init (original) (raw)

noreply@sourceforge.net noreply@sourceforge.net
Wed, 17 Oct 2001 13:45:17 -0700


Bugs item #472234, was opened at 2001-10-17 13:45 You can respond by visiting: http://sourceforge.net/tracker/?func=detail&atid=105470&aid=472234&group_id=5470

Category: Type/class unification Group: Python 2.2 Status: Open Resolution: None Priority: 5 Submitted By: Roeland Rengelink (rengelink) Assigned to: Guido van Rossum (gvanrossum) Summary: type(obj) calls type->tp_init

Initial Comment: In 2.2a4 Consider:

class Meta(type): def init(self, *args): print 'Meta.init called'

class Object(object): metaclass = Meta

obj = Object()

print type(obj)

will print

Meta.init called Meta.init called

The second call to Meta.init results from the type(obj) call. This is because type(obj) is special cased in type_new(...) rather than type_call(...).

Although it's rather useless to define an init in a class derived from type (for metaclasses it's a better idea to override new). I do think the call of Meta.init in type(obj) is a bug.

Thanks,

Roeland


You can respond by visiting: http://sourceforge.net/tracker/?func=detail&atid=105470&aid=472234&group_id=5470