mirror of
https://github.com/python/cpython.git
synced 2025-08-22 09:45:06 +00:00
PEP 415: Implement suppression of __context__ display with an exception attribute
This replaces the original PEP 409 implementation. See #14133.
This commit is contained in:
parent
d91dc62379
commit
d5a1c44455
12 changed files with 80 additions and 79 deletions
|
@ -388,18 +388,18 @@ class ExceptionTests(unittest.TestCase):
|
|||
def testChainingAttrs(self):
|
||||
e = Exception()
|
||||
self.assertIsNone(e.__context__)
|
||||
self.assertIs(e.__cause__, Ellipsis)
|
||||
self.assertIsNone(e.__cause__)
|
||||
|
||||
e = TypeError()
|
||||
self.assertIsNone(e.__context__)
|
||||
self.assertIs(e.__cause__, Ellipsis)
|
||||
self.assertIsNone(e.__cause__)
|
||||
|
||||
class MyException(EnvironmentError):
|
||||
pass
|
||||
|
||||
e = MyException()
|
||||
self.assertIsNone(e.__context__)
|
||||
self.assertIs(e.__cause__, Ellipsis)
|
||||
self.assertIsNone(e.__cause__)
|
||||
|
||||
def testChainingDescriptors(self):
|
||||
try:
|
||||
|
@ -408,15 +408,16 @@ class ExceptionTests(unittest.TestCase):
|
|||
e = exc
|
||||
|
||||
self.assertIsNone(e.__context__)
|
||||
self.assertIs(e.__cause__, Ellipsis)
|
||||
self.assertIsNone(e.__cause__)
|
||||
self.assertFalse(e.__suppress_context__)
|
||||
|
||||
e.__context__ = NameError()
|
||||
e.__cause__ = None
|
||||
self.assertIsInstance(e.__context__, NameError)
|
||||
self.assertIsNone(e.__cause__)
|
||||
|
||||
e.__cause__ = Ellipsis
|
||||
self.assertIs(e.__cause__, Ellipsis)
|
||||
self.assertTrue(e.__suppress_context__)
|
||||
e.__suppress_context__ = False
|
||||
self.assertFalse(e.__suppress_context__)
|
||||
|
||||
def testKeywordArgs(self):
|
||||
# test that builtin exception don't take keyword args,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue