New submission from Stanisław Skonieczny (Uosiu):

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.

----------
components: Interpreter Core
files: new_patch_fails.py
messages: 255337
nosy: Stanisław Skonieczny (Uosiu)
priority: normal
severity: normal
status: open
title: Assigning and deleting __new__ attr on the class does not allow to 
create instances of this class
type: behavior
versions: Python 3.5
Added file: http://bugs.python.org/file41161/new_patch_fails.py

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue25731>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to