FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.14] gh-150484: Fix mock_open __exit__ with contextlib.ExitStack by factnn · Pull Request #151829 · python/cpython · GitHub

Repository navigation

[3.14] gh-150484: Fix mock_open __exit__ with contextlib.ExitStack - #151829

Merged
serhiy-storchaka merged 2 commits into
python:3.14from
factnn:fix/mock-open-exit-signature-3.14
Jun 21, 2026
Merged

serhiy-storchaka merged 2 commits into
python:3.14from
factnn:fix/mock-open-exit-signature-3.14

Conversation

factnn commented Jun 21, 2026 •
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown

Fixes #150484.

mock_open()'s __exit__ raises TypeError when used with contextlib.ExitStack because _exit_side_effect had a fixed 3-arg signature (exctype, excinst, exctb), but ExitStack.__exit__ calls it with 4 args (self, exctype, excinst, exctb). Since the function body only calls handle.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).

factnn added 2 commits June 21, 2026 12:43
  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
factnn requested a review from cjw296 as a code owner June 21, 2026 04:46
picnixz changed the title gh-150484: Fix mock_open __exit__ with contextlib.ExitStack [3.14] gh-150484: Fix mock_open __exit__ with contextlib.ExitStack Jun 21, 2026
picnixz requested a review from serhiy-storchaka June 21, 2026 12:42
serhiy-storchaka added the needs backport to 3.13 only security fixes label Jun 21, 2026
serhiy-storchaka merged commit 85fa295 into python:3.14 Jun 21, 2026
54 of 55 checks passed

Copy link
Copy Markdown

Thanks @factnn for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

bedevere-app Bot commented Jun 21, 2026

Copy link
Copy Markdown

GH-151861 is a backport of this pull request to the 3.13 branch.

bedevere-app Bot removed the needs backport to 3.13 only security fixes label Jun 21, 2026

Copy link
Copy Markdown
Member

Thank you @factnn.

factnn commented Jun 21, 2026

Copy link
Copy Markdown
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>
factnn added a commit to factnn/cpython that referenced this pull request Oct 21, 2026
…Stack

mock_open().__exit__ only misbehaves on 3.13 and 3.14, where it was
fixed directly by pythonGH-151829 and backported as pythonGH-151861. Only the
regression test belongs on main.
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL