Author Stanisław Skonieczny (Uosiu)
Recipients Stanisław Skonieczny (Uosiu)
Date 2015-11-25.12:29:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1448454590.41.0.350843358205.issue25731@psf.upfronthosting.co.za>
In-reply-to
Content
When moving from python 2.7 to 3.5 I have found a problem with patching __new__ method on the class. It was done this way:
'''
patch('foo.bar.MyClass.__new__', return_value=mocked_instance)
'''
In works with python 2.7, but in 3.5 it fails with:
'''
TypeError: object() takes no parameters
'''

I have created minimal scenario that ilustrates this bug cause:
'''
class X:
    def __init__(self, a):
        pass


def new(cls, a):
    pass


X(1)
X.__new__ = new
X(1)
del X.__new__
X(1)
'''
Setting __new__ attribute and then deleting it has some side effect.
History
Date User Action Args
2015-11-25 12:29:50Stanisław Skonieczny (Uosiu)setrecipients: + Stanisław Skonieczny (Uosiu)
2015-11-25 12:29:50Stanisław Skonieczny (Uosiu)setmessageid: <1448454590.41.0.350843358205.issue25731@psf.upfronthosting.co.za>
2015-11-25 12:29:50Stanisław Skonieczny (Uosiu)linkissue25731 messages
2015-11-25 12:29:49Stanisław Skonieczny (Uosiu)create