From e983506e23ce85617f3c77e70da3687d7ac50455 Mon Sep 17 00:00:00 2001 From: CPython Developers <> Date: Tue, 7 Mar 2023 04:51:09 +0900 Subject: [PATCH 1/2] Update test/test_with.py from CPython 3.11.2 --- Lib/test/test_with.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_with.py b/Lib/test/test_with.py index f21bf65fed..07522bda6a 100644 --- a/Lib/test/test_with.py +++ b/Lib/test/test_with.py @@ -117,7 +117,7 @@ def __exit__(self, type, value, traceback): def fooLacksEnter(): foo = LacksEnter() with foo: pass - self.assertRaisesRegex(AttributeError, '__enter__', fooLacksEnter) + self.assertRaisesRegex(TypeError, 'the context manager', fooLacksEnter) def testEnterAttributeError2(self): class LacksEnterAndExit(object): @@ -126,7 +126,7 @@ class LacksEnterAndExit(object): def fooLacksEnterAndExit(): foo = LacksEnterAndExit() with foo: pass - self.assertRaisesRegex(AttributeError, '__enter__', fooLacksEnterAndExit) + self.assertRaisesRegex(TypeError, 'the context manager', fooLacksEnterAndExit) def testExitAttributeError(self): class LacksExit(object): @@ -136,7 +136,7 @@ def __enter__(self): def fooLacksExit(): foo = LacksExit() with foo: pass - self.assertRaisesRegex(AttributeError, '__exit__', fooLacksExit) + self.assertRaisesRegex(TypeError, 'the context manager.*__exit__', fooLacksExit) def assertRaisesSyntaxError(self, codestr): def shouldRaiseSyntaxError(s): From 51fcfe980f381cd8527086a3875ea987d27f96aa Mon Sep 17 00:00:00 2001 From: LYK Date: Tue, 7 Mar 2023 04:51:39 +0900 Subject: [PATCH 2/2] Mark failing tests of test/test_with.py A TypeError is raised instead of an AttributeError in "with" and "async with" statements for objects which do not support the context manager or asynchronous context manager protocols correspondingly. See also: https://github.com/python/cpython/pull/26809 --- Lib/test/test_with.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Lib/test/test_with.py b/Lib/test/test_with.py index 07522bda6a..41f05c2eaf 100644 --- a/Lib/test/test_with.py +++ b/Lib/test/test_with.py @@ -109,6 +109,8 @@ def fooNotDeclared(): with foo: pass self.assertRaises(NameError, fooNotDeclared) + # TODO: RUSTPYTHON + @unittest.expectedFailure def testEnterAttributeError1(self): class LacksEnter(object): def __exit__(self, type, value, traceback): @@ -119,6 +121,8 @@ def fooLacksEnter(): with foo: pass self.assertRaisesRegex(TypeError, 'the context manager', fooLacksEnter) + # TODO: RUSTPYTHON + @unittest.expectedFailure def testEnterAttributeError2(self): class LacksEnterAndExit(object): pass @@ -128,6 +132,8 @@ def fooLacksEnterAndExit(): with foo: pass self.assertRaisesRegex(TypeError, 'the context manager', fooLacksEnterAndExit) + # TODO: RUSTPYTHON + @unittest.expectedFailure def testExitAttributeError(self): class LacksExit(object): def __enter__(self):