Visitar URL original
gh-111101: Refactor `test_restored_object_new` in `test_descr` by sobolevn · Pull Request #111102 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20260312222739/https://github.com/python/cpython/pull/111102
Skip to content
/ cpython Public

gh-111101: Refactor test_restored_object_new in test_descr#111102

Closed
sobolevn wants to merge 1 commit intopython:mainfrom
sobolevn:issue-111101
Closed

gh-111101: Refactor test_restored_object_new in test_descr#111102
sobolevn wants to merge 1 commit intopython:mainfrom
sobolevn:issue-111101

Conversation

@sobolevn
Copy link
Member

@sobolevn sobolevn commented Oct 20, 2023 •

b = B(3)
self.assertEqual(b.foo, 3)
self.assertEqual(b.__class__, B)
def __init__(self):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I see. This needs to be allowed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I followed the issue you've linked. Now I understand that __new__ = object.__new__ should not matter 👍

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test is valid. Python has a bug.

def __new__(cls, *args, **kwargs):
raise AssertionError
self.assertRaises(AssertionError, A)
raise TypeError('A')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants