Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Ad hint about missed __exit__ method.
  • Loading branch information
serhiy-storchaka committed Jun 21, 2021
commit 4b994fc7a088c1fd17ddfbb352aeed9b132f3fa7
4 changes: 2 additions & 2 deletions Lib/test/test_contextlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ def __unter__(self):
def __exit__(self, *exc):
pass

with self.assertRaisesRegex(TypeError, "context manager"):
with self.assertRaisesRegex(TypeError, 'context manager'):
with mycontext():
pass

Expand All @@ -503,7 +503,7 @@ def __enter__(self):
def __uxit__(self, *exc):
pass

with self.assertRaisesRegex(TypeError, "context manager"):
with self.assertRaisesRegex(TypeError, 'context manager.*__exit__'):
with mycontext():
pass

Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_coroutines.py
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ async def foo():
async with CM():
body_executed = True

with self.assertRaisesRegex(TypeError, 'asynchronous context manager'):
with self.assertRaisesRegex(TypeError, 'asynchronous context manager.*__aexit__'):
run_async(foo())
self.assertFalse(body_executed)

Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_with.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def __enter__(self):
def fooLacksExit():
foo = LacksExit()
with foo: pass
self.assertRaisesRegex(TypeError, 'context manager', fooLacksExit)
self.assertRaisesRegex(TypeError, 'context manager.*__exit__', fooLacksExit)

def assertRaisesSyntaxError(self, codestr):
def shouldRaiseSyntaxError(s):
Expand Down
6 changes: 4 additions & 2 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -3856,7 +3856,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
if (!_PyErr_Occurred(tstate)) {
_PyErr_Format(tstate, PyExc_TypeError,
"'%.200s' object does not support the "
"asynchronous context manager protocol",
"asynchronous context manager protocol "
"(missed __aexit__ method)",
Py_TYPE(mgr)->tp_name);
}
Py_DECREF(enter);
Expand Down Expand Up @@ -3893,7 +3894,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
if (!_PyErr_Occurred(tstate)) {
_PyErr_Format(tstate, PyExc_TypeError,
"'%.200s' object does not support the "
"context manager protocol",
"context manager protocol "
"(missed __exit__ method)",
Py_TYPE(mgr)->tp_name);
}
Py_DECREF(enter);
Expand Down