From 0b95995b02371f6f73bb7dbdebcdd83393d12592 Mon Sep 17 00:00:00 2001 From: vidhya <96202776+Vidhyavinu@users.noreply.github.com> Date: Tue, 1 Mar 2022 10:46:45 -0500 Subject: [PATCH 01/11] BPO - 28516 contextlib.ExitStack.__enter__ has trivial but undocumented behavior The enter_context is updated with following information: 'The :meth:`__enter__` method returns the ExitStack instance, and performs no additional operations.' --- Doc/library/contextlib.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/library/contextlib.rst b/Doc/library/contextlib.rst index bb93088b3429e2..c7b3e53f04f188 100644 --- a/Doc/library/contextlib.rst +++ b/Doc/library/contextlib.rst @@ -529,7 +529,8 @@ Functions and classes provided: Enters a new context manager and adds its :meth:`__exit__` method to the callback stack. The return value is the result of the context - manager's own :meth:`__enter__` method. + manager's own :meth:`__enter__` method.The :meth:`__enter__` method + returns the ExitStack instance, and performs no additional operations. These context managers may suppress exceptions just as they normally would if used directly as part of a :keyword:`with` statement. From 598f420046c559b4f265a04e3c31fed786c468fa Mon Sep 17 00:00:00 2001 From: vidhya <96202776+Vidhyavinu@users.noreply.github.com> Date: Tue, 1 Mar 2022 16:21:24 -0500 Subject: [PATCH 02/11] Update contextlib.rst Added space after period and link to ExitStack. --- Doc/library/contextlib.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/contextlib.rst b/Doc/library/contextlib.rst index c7b3e53f04f188..89199b393ddb1f 100644 --- a/Doc/library/contextlib.rst +++ b/Doc/library/contextlib.rst @@ -529,8 +529,8 @@ Functions and classes provided: Enters a new context manager and adds its :meth:`__exit__` method to the callback stack. The return value is the result of the context - manager's own :meth:`__enter__` method.The :meth:`__enter__` method - returns the ExitStack instance, and performs no additional operations. + manager's own :meth:`__enter__` method. The :meth:`__enter__` method + returns the :class:`ExitStack` instance, and performs no additional operations. These context managers may suppress exceptions just as they normally would if used directly as part of a :keyword:`with` statement. From 61fae609eb9ce8fef32c9ab268fbf5871d04a0c2 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Tue, 1 Mar 2022 17:44:48 -0800 Subject: [PATCH 03/11] clear trailing whitespace --- Doc/library/contextlib.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/contextlib.rst b/Doc/library/contextlib.rst index 89199b393ddb1f..d3b88772276864 100644 --- a/Doc/library/contextlib.rst +++ b/Doc/library/contextlib.rst @@ -529,7 +529,7 @@ Functions and classes provided: Enters a new context manager and adds its :meth:`__exit__` method to the callback stack. The return value is the result of the context - manager's own :meth:`__enter__` method. The :meth:`__enter__` method + manager's own :meth:`__enter__` method. The :meth:`__enter__` method returns the :class:`ExitStack` instance, and performs no additional operations. These context managers may suppress exceptions just as they normally From 7638af38a85269e1d35e101e83ae4bbf9c714d43 Mon Sep 17 00:00:00 2001 From: vidhya <96202776+Vidhyavinu@users.noreply.github.com> Date: Wed, 2 Mar 2022 13:34:52 -0500 Subject: [PATCH 04/11] Update contextlib.rst --- Doc/library/contextlib.rst | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Doc/library/contextlib.rst b/Doc/library/contextlib.rst index d3b88772276864..7a70efe74c78a1 100644 --- a/Doc/library/contextlib.rst +++ b/Doc/library/contextlib.rst @@ -502,11 +502,14 @@ Functions and classes provided: # the with statement, even if attempts to open files later # in the list raise an exception + The :meth:`__enter__` method returns the :class:`ExitStack` instance, and + performs no additional operations. + Each instance maintains a stack of registered callbacks that are called in reverse order when the instance is closed (either explicitly or implicitly at the end of a :keyword:`with` statement). Note that callbacks are *not* invoked implicitly when the context stack instance is garbage collected. - + This stack model is used so that context managers that acquire their resources in their ``__init__`` method (such as file objects) can be handled correctly. @@ -529,8 +532,7 @@ Functions and classes provided: Enters a new context manager and adds its :meth:`__exit__` method to the callback stack. The return value is the result of the context - manager's own :meth:`__enter__` method. The :meth:`__enter__` method - returns the :class:`ExitStack` instance, and performs no additional operations. + manager's own :meth:`__enter__` method. These context managers may suppress exceptions just as they normally would if used directly as part of a :keyword:`with` statement. @@ -545,7 +547,7 @@ Functions and classes provided: As ``__enter__`` is *not* invoked, this method can be used to cover part of an :meth:`__enter__` implementation with a context manager's own - :meth:`__exit__` method. + :meth:`__exit__` method. If passed an object that is not a context manager, this method assumes it is a callback with the same signature as a context manager's From 6c70f1dd8d9a1bc5316f3eb92deeaf5c2f3fbd29 Mon Sep 17 00:00:00 2001 From: vidhya <96202776+Vidhyavinu@users.noreply.github.com> Date: Wed, 2 Mar 2022 13:38:06 -0500 Subject: [PATCH 05/11] Update contextlib.rst --- Doc/library/contextlib.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/contextlib.rst b/Doc/library/contextlib.rst index 7a70efe74c78a1..4f87eb5ea5fa4c 100644 --- a/Doc/library/contextlib.rst +++ b/Doc/library/contextlib.rst @@ -532,7 +532,7 @@ Functions and classes provided: Enters a new context manager and adds its :meth:`__exit__` method to the callback stack. The return value is the result of the context - manager's own :meth:`__enter__` method. + manager's own :meth:`__enter__` method. These context managers may suppress exceptions just as they normally would if used directly as part of a :keyword:`with` statement. @@ -547,7 +547,7 @@ Functions and classes provided: As ``__enter__`` is *not* invoked, this method can be used to cover part of an :meth:`__enter__` implementation with a context manager's own - :meth:`__exit__` method. + :meth:`__exit__` method. If passed an object that is not a context manager, this method assumes it is a callback with the same signature as a context manager's From e1a1161a267894eb88ebaced3d58d930c78af6ac Mon Sep 17 00:00:00 2001 From: vidhya <96202776+Vidhyavinu@users.noreply.github.com> Date: Wed, 2 Mar 2022 13:41:33 -0500 Subject: [PATCH 06/11] Update contextlib.rst --- Doc/library/contextlib.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/contextlib.rst b/Doc/library/contextlib.rst index 4f87eb5ea5fa4c..c2188b091fa645 100644 --- a/Doc/library/contextlib.rst +++ b/Doc/library/contextlib.rst @@ -509,7 +509,7 @@ Functions and classes provided: reverse order when the instance is closed (either explicitly or implicitly at the end of a :keyword:`with` statement). Note that callbacks are *not* invoked implicitly when the context stack instance is garbage collected. - + This stack model is used so that context managers that acquire their resources in their ``__init__`` method (such as file objects) can be handled correctly. From 0476d7469cc23fbb1f62bfbc9dc8ff6c18a7607d Mon Sep 17 00:00:00 2001 From: vidhya <96202776+Vidhyavinu@users.noreply.github.com> Date: Wed, 2 Mar 2022 13:42:48 -0500 Subject: [PATCH 07/11] Update contextlib.rst --- Doc/library/contextlib.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/contextlib.rst b/Doc/library/contextlib.rst index c2188b091fa645..0859e00e577e25 100644 --- a/Doc/library/contextlib.rst +++ b/Doc/library/contextlib.rst @@ -504,12 +504,12 @@ Functions and classes provided: The :meth:`__enter__` method returns the :class:`ExitStack` instance, and performs no additional operations. - + Each instance maintains a stack of registered callbacks that are called in reverse order when the instance is closed (either explicitly or implicitly at the end of a :keyword:`with` statement). Note that callbacks are *not* invoked implicitly when the context stack instance is garbage collected. - + This stack model is used so that context managers that acquire their resources in their ``__init__`` method (such as file objects) can be handled correctly. From bcbaece60aac7e7873fe065b980d50333dfe9c51 Mon Sep 17 00:00:00 2001 From: vidhya <96202776+Vidhyavinu@users.noreply.github.com> Date: Wed, 2 Mar 2022 13:45:16 -0500 Subject: [PATCH 08/11] Update contextlib.rst --- Doc/library/contextlib.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/Doc/library/contextlib.rst b/Doc/library/contextlib.rst index 0859e00e577e25..1176f40d83c330 100644 --- a/Doc/library/contextlib.rst +++ b/Doc/library/contextlib.rst @@ -509,7 +509,6 @@ Functions and classes provided: reverse order when the instance is closed (either explicitly or implicitly at the end of a :keyword:`with` statement). Note that callbacks are *not* invoked implicitly when the context stack instance is garbage collected. - This stack model is used so that context managers that acquire their resources in their ``__init__`` method (such as file objects) can be handled correctly. From d5cbd4d979a14b092b831724441a959c0ebe624b Mon Sep 17 00:00:00 2001 From: vidhya <96202776+Vidhyavinu@users.noreply.github.com> Date: Wed, 9 Mar 2022 06:01:32 -0500 Subject: [PATCH 09/11] Update contextlib.rst --- Doc/library/contextlib.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/contextlib.rst b/Doc/library/contextlib.rst index 1176f40d83c330..c12cfcd573b355 100644 --- a/Doc/library/contextlib.rst +++ b/Doc/library/contextlib.rst @@ -508,8 +508,8 @@ Functions and classes provided: Each instance maintains a stack of registered callbacks that are called in reverse order when the instance is closed (either explicitly or implicitly at the end of a :keyword:`with` statement). Note that callbacks are *not* - invoked implicitly when the context stack instance is garbage collected. - This stack model is used so that context managers that acquire their + invoked implicitly when the context stack instance is garbage collected. This + stack model is used so that context managers that acquire their resources in their ``__init__`` method (such as file objects) can be handled correctly. From 0958ed537dd5e060515ca612376afccd0acfdf75 Mon Sep 17 00:00:00 2001 From: vidhya <96202776+Vidhyavinu@users.noreply.github.com> Date: Wed, 9 Mar 2022 06:07:45 -0500 Subject: [PATCH 10/11] Update contextlib.rst --- Doc/library/contextlib.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Doc/library/contextlib.rst b/Doc/library/contextlib.rst index c12cfcd573b355..0859e00e577e25 100644 --- a/Doc/library/contextlib.rst +++ b/Doc/library/contextlib.rst @@ -508,8 +508,9 @@ Functions and classes provided: Each instance maintains a stack of registered callbacks that are called in reverse order when the instance is closed (either explicitly or implicitly at the end of a :keyword:`with` statement). Note that callbacks are *not* - invoked implicitly when the context stack instance is garbage collected. This - stack model is used so that context managers that acquire their + invoked implicitly when the context stack instance is garbage collected. + + This stack model is used so that context managers that acquire their resources in their ``__init__`` method (such as file objects) can be handled correctly. From c411078c273862ec2df4d58ce3e3f73140c279ae Mon Sep 17 00:00:00 2001 From: vidhya <96202776+Vidhyavinu@users.noreply.github.com> Date: Thu, 10 Mar 2022 09:05:44 -0500 Subject: [PATCH 11/11] Update contextlib.rst Removed trailing whitespace. --- Doc/library/contextlib.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/contextlib.rst b/Doc/library/contextlib.rst index 0859e00e577e25..38134c1f14319f 100644 --- a/Doc/library/contextlib.rst +++ b/Doc/library/contextlib.rst @@ -502,7 +502,7 @@ Functions and classes provided: # the with statement, even if attempts to open files later # in the list raise an exception - The :meth:`__enter__` method returns the :class:`ExitStack` instance, and + The :meth:`__enter__` method returns the :class:`ExitStack` instance, and performs no additional operations. Each instance maintains a stack of registered callbacks that are called in