mirror of
https://github.com/python/cpython.git
synced 2025-07-24 03:35:53 +00:00
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:
parent
20a88004ba
commit
6cb145d23f
6 changed files with 91 additions and 8 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue