bpo-44471: Change error type for bad objects in ExitStack.enter_context() (GH-26820)

A TypeError is now raised instead of an AttributeError in
ExitStack.enter_context() and AsyncExitStack.enter_async_context()
for objects which do not support the context manager or
asynchronous context manager protocols correspondingly.
This commit is contained in:
Serhiy Storchaka 2021-06-29 11:28:15 +03:00 committed by GitHub
parent 20a88004ba
commit 6cb145d23f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 91 additions and 8 deletions

View file

@ -515,6 +515,10 @@ Functions and classes provided:
These context managers may suppress exceptions just as they normally
would if used directly as part of a :keyword:`with` statement.
... versionchanged:: 3.11
Raises :exc:`TypeError` instead of :exc:`AttributeError` if *cm*
is not a context manager.
.. method:: push(exit)
Adds a context manager's :meth:`__exit__` method to the callback stack.
@ -585,6 +589,10 @@ Functions and classes provided:
Similar to :meth:`enter_context` but expects an asynchronous context
manager.
... versionchanged:: 3.11
Raises :exc:`TypeError` instead of :exc:`AttributeError` if *cm*
is not an asynchronous context manager.
.. method:: push_async_exit(exit)
Similar to :meth:`push` but expects either an asynchronous context manager