Last active
June 22, 2022 01:49
-
-
Save metatoaster/c2d6757963df13f7e5584f36a4e9f49f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SomeClassToMock(object): | |
def __init__(self, key=None): | |
self.key = key | |
old_new, SomeClassToMock.__new__ = SomeClassToMock.__new__, lambda: None | |
SomeClassToMock.__new__ = old_new | |
SomeClassToMock(key='value') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python2.7 python_dunder_new_assignmment_bug.py && echo $? | |
0 | |
$ python3.2 python_dunder_new_assignmment_bug.py && echo $? | |
0 | |
$ python3.3 python_dunder_new_assignmment_bug.py && echo $? | |
Traceback (most recent call last): | |
File "python_dunder_new_assignmment_bug.py", line 7, in <module> | |
SomeClassToMock(key='value') | |
TypeError: object() takes no parameters | |
$ python3.6 python_dunder_new_assignmment_bug.py && echo $? | |
Traceback (most recent call last): | |
File "python_dunder_new_assignmment_bug.py", line 7, in <module> | |
SomeClassToMock(key='value') | |
TypeError: object() takes no parameters | |
$ python3.7 python_dunder_new_assignmment_bug.py && echo $? | |
Traceback (most recent call last): | |
File "python_dunder_new_assignmment_bug.py", line 7, in <module> | |
SomeClassToMock(key='value') | |
TypeError: object.__new__() takes exactly one argument (the type to instantiate) | |
$ python3.10 python_dunder_new_assignmment_bug.py && echo $? | |
Traceback (most recent call last): | |
File "python_dunder_new_assignmment_bug.py", line 7, in <module> | |
SomeClassToMock(key='value') | |
TypeError: object.__new__() takes exactly one argument (the type to instantiate) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment