gh-111101: Refactor test_restored_object_new in test_descr#111102
gh-111101: Refactor test_restored_object_new in test_descr#111102sobolevn wants to merge 1 commit intopython:mainfrom
test_restored_object_new in test_descr#111102Conversation
| b = B(3) | ||
| self.assertEqual(b.foo, 3) | ||
| self.assertEqual(b.__class__, B) | ||
| def __init__(self): |
There was a problem hiding this comment.
Ok, I see. This needs to be allowed.
There was a problem hiding this comment.
The point of the test is that if __init__ have 1 parameter and __new__ accept arbitrary arguments, it should be possible to call the constructor with 1 argument.
There was a problem hiding this comment.
Yes, I followed the issue you've linked. Now I understand that __new__ = object.__new__ should not matter 👍
serhiy-storchaka
left a comment
There was a problem hiding this comment.
The test is valid. Python has a bug.
| def __new__(cls, *args, **kwargs): | ||
| raise AssertionError | ||
| self.assertRaises(AssertionError, A) | ||
| raise TypeError('A') |
There was a problem hiding this comment.
It is better to use anything other than TypeError, because TypeError can be indirectly raised by many other reasons. AssertionError was used because it is only indirectly raised in assert.
| b = B(3) | ||
| self.assertEqual(b.foo, 3) | ||
| self.assertEqual(b.__class__, B) | ||
| def __init__(self): |
There was a problem hiding this comment.
The point of the test is that if __init__ have 1 parameter and __new__ accept arbitrary arguments, it should be possible to call the constructor with 1 argument.


Refs:
test_restored_object_newintest_descris silently ignored #111101