[Python-bugs-list] [ python-Bugs-535170 ] new.instance() breaks with new classes

noreply@sourceforge.net noreply@sourceforge.net
Thu, 04 Apr 2002 09:08:11 -0800


Bugs item #535170, was opened at 2002-03-26 07:49
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=535170&group_id=5470

Category: Python Interpreter Core
Group: None
>Status: Closed
>Resolution: Wont Fix
Priority: 5
Submitted By: Anthony Baxter (anthonybaxter)
>Assigned to: Guido van Rossum (gvanrossum)
Summary: new.instance() breaks with new classes

Initial Comment:
>>> class a1: pass
... 
>>> a2 = type('a2', (), {})
>>> class a3(object): pass
... 
>>> a1
<class __main__.a1 at 0x815111c>
>>> a2
<class '__main__.a2'>
>>> a3
<class '__main__.a3'>
>>> import new
>>> new.instance(a1)
<__main__.a1 instance at 0x8148a04>
>>> new.instance(a2)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: instance() argument 1 must be class, not type
>>> new.instance(a3)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: instance() argument 1 must be class, not type

2.2 branch and current CVS...  _so_ not a 2.2 bugfix
necessity, tho :)

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

>Comment By: Guido van Rossum (gvanrossum)
Date: 2002-04-04 12:08

Message:
Logged In: YES 
user_id=6380

There's no need to use new.instance() for new-style classes.

You should be able to do this using the __new__ method of
the new-style class.

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

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