mirror of
https://github.com/python/cpython.git
synced 2025-11-13 15:40:05 +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
|
||||
|
|
|
|||
|
|
@ -75,6 +75,12 @@ New Features
|
|||
Other Language Changes
|
||||
======================
|
||||
|
||||
A :exc:`TypeError` is now raised instead of an :exc:`AttributeError` in
|
||||
:meth:`contextlib.ExitStack.enter_context` and
|
||||
:meth:`contextlib.AsyncExitStack.enter_async_context` for objects which do not
|
||||
support the :term:`context manager` or :term:`asynchronous context manager`
|
||||
protocols correspondingly.
|
||||
(Contributed by Serhiy Storchaka in :issue:`44471`.)
|
||||
|
||||
* A :exc:`TypeError` is now raised instead of an :exc:`AttributeError` in
|
||||
:keyword:`with` and :keyword:`async with` statements for objects which do not
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue