[Python-bugs-list] [ python-Bugs-485602 ] new module broken with new classes

noreply@sourceforge.net noreply@sourceforge.net
Tue, 27 Nov 2001 18:38:31 -0800


Bugs item #485602, was opened at 2001-11-26 06:01
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=485602&group_id=5470

Category: Type/class unification
Group: Python 2.2
>Status: Closed
>Resolution: Works For Me
Priority: 5
Submitted By: David M. Beazley (beazley)
Assigned to: Guido van Rossum (gvanrossum)
Summary: new module broken with new classes

Initial Comment:
The new module doesn't support the new-style classes.
Example:

  import new
  class foo(object):
      pass

  a = new.instance(foo,{})

I didn't really expect this to work, but I'm trying to
figure out how to emulate the behavior of this function
with new-style classes (i.e., how to bring a new-style
instance into being without calling __init__).

Does a call to PyType_GenericAlloc(PyTypeObject *type,
1) emulate this behavior?  Please advise.

Cheers,

Dave


----------------------------------------------------------------------

>Comment By: Guido van Rossum (gvanrossum)
Date: 2001-11-27 18:38

Message:
Logged In: YES 
user_id=6380

Thomas is right on the money: someclass.__new__() should do
it.

PyType_GenericAlloc() may create an instance that isn't
sufficiently initialized to be used safely (it initializes
everything to zeros, but that's not enough e.g. for dict
instances).

----------------------------------------------------------------------

Comment By: Thomas Heller (theller)
Date: 2001-11-27 12:06

Message:
Logged In: YES 
user_id=11105

Doesn't

  a = foo.__new__(foo)
  a.__dict__.update(dict)

do this?

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2001-11-27 12:03

Message:
Logged In: YES 
user_id=31435

Assigned to Guido.

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2001-11-27 09:37

Message:
Logged In: YES 
user_id=31435

Changed Category & Group.

----------------------------------------------------------------------

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