[New-bugs-announce] [issue5322] Python 2.6 object.__new__ argument calling autodetection faulty
Armin Ronacher
report at bugs.python.org
Thu Feb 19 21:34:25 CET 2009
New submission from Armin Ronacher <armin.ronacher at active-4.com>:
In 2.6 a deprecation warning was added if `object.__new__` was called
with arguments. Per se this is fine, but the detection seems to be faulty.
The following code shows the problem:
>>> class A(object):
... def __new__(self):
... raise TypeError('i do not exist')
...
>>> class B(A):
... __new__ = object.__new__
... def __init__(self, x):
... self.x = x
...
>>> B(1)
__main__:1: DeprecationWarning: object.__new__() takes no parameters
<__main__.B object at 0x88dd0>
In the `B` case `__new__` is not overridden (in the sense that it
differs from object.__new__) but `__init__` is. Which is the default
behaviour. Nonetheless a warning is raised.
I used the pattern with the "__new__ switch" to achieve a
cStringIO.StringIO behavior that supports typechecks: IterIO() returns
either a IterI or IterO object, both instances of IterIO so that
typechecks can be performed.
Real-world use case here:
http://dev.pocoo.org/projects/werkzeug/browser/werkzeug/contrib/iterio.py
----------
messages: 82497
nosy: aronacher
severity: normal
status: open
title: Python 2.6 object.__new__ argument calling autodetection faulty
type: behavior
versions: Python 2.6
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5322>
_______________________________________
More information about the New-bugs-announce
mailing list