[3.14] gh-150484: Fix mock_open __exit__ with contextlib.ExitStack#151829
Merged
serhiy-storchaka merged 2 commits intoJun 21, 2026
Conversation
mock_open's _exit_side_effect had a fixed 3-arg signature, but contextlib.ExitStack calls __exit__ with 4 args (self + 3 exc info). Use *args to accept any number of arguments. Fixes python#150484
serhiy-storchaka
approved these changes
Jun 21, 2026
|
Thanks @factnn for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13. |
|
GH-151861 is a backport of this pull request to the 3.13 branch. |
Member
|
Thank you @factnn. |
Author
|
My pleasure. |
serhiy-storchaka
pushed a commit
that referenced
this pull request
Jun 21, 2026
…H-151829) (GH-151861) mock_open's _exit_side_effect had a fixed 3-arg signature, but contextlib.ExitStack calls __exit__ with 4 args (self + 3 exc info). Use *args to accept any number of arguments. (cherry picked from commit 85fa295) Co-authored-by: Zang Peiyu <166481866+factnn@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #150484.
mock_open()'s__exit__raisesTypeErrorwhen used withcontextlib.ExitStackbecause_exit_side_effecthad a fixed 3-arg signature(exctype, excinst, exctb), butExitStack.__exit__calls it with 4 args(self, exctype, excinst, exctb). Since the function body only callshandle.close()and doesn't use the arguments, the fix changes the signature to*args.This is the 3.14 backport of #150521 (opened per request).