mirror of
https://github.com/python/cpython.git
synced 2025-11-02 14:41:33 +00:00
gh-77757: replace exception wrapping by PEP-678 notes in typeobject's __set_name__ (#103402)
This commit is contained in:
parent
e071f00aae
commit
55c99d97e1
8 changed files with 55 additions and 41 deletions
|
|
@ -134,30 +134,28 @@ class Descriptor:
|
|||
def __set_name__(self, owner, name):
|
||||
1/0
|
||||
|
||||
with self.assertRaises(RuntimeError) as cm:
|
||||
with self.assertRaises(ZeroDivisionError) as cm:
|
||||
class NotGoingToWork:
|
||||
attr = Descriptor()
|
||||
|
||||
exc = cm.exception
|
||||
self.assertRegex(str(exc), r'\bNotGoingToWork\b')
|
||||
self.assertRegex(str(exc), r'\battr\b')
|
||||
self.assertRegex(str(exc), r'\bDescriptor\b')
|
||||
self.assertIsInstance(exc.__cause__, ZeroDivisionError)
|
||||
notes = cm.exception.__notes__
|
||||
self.assertRegex(str(notes), r'\bNotGoingToWork\b')
|
||||
self.assertRegex(str(notes), r'\battr\b')
|
||||
self.assertRegex(str(notes), r'\bDescriptor\b')
|
||||
|
||||
def test_set_name_wrong(self):
|
||||
class Descriptor:
|
||||
def __set_name__(self):
|
||||
pass
|
||||
|
||||
with self.assertRaises(RuntimeError) as cm:
|
||||
with self.assertRaises(TypeError) as cm:
|
||||
class NotGoingToWork:
|
||||
attr = Descriptor()
|
||||
|
||||
exc = cm.exception
|
||||
self.assertRegex(str(exc), r'\bNotGoingToWork\b')
|
||||
self.assertRegex(str(exc), r'\battr\b')
|
||||
self.assertRegex(str(exc), r'\bDescriptor\b')
|
||||
self.assertIsInstance(exc.__cause__, TypeError)
|
||||
notes = cm.exception.__notes__
|
||||
self.assertRegex(str(notes), r'\bNotGoingToWork\b')
|
||||
self.assertRegex(str(notes), r'\battr\b')
|
||||
self.assertRegex(str(notes), r'\bDescriptor\b')
|
||||
|
||||
def test_set_name_lookup(self):
|
||||
resolved = []
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue