Skip to content

gh-151443: Fix documented default of read_data in unittest.mock.mock_open#151444

Merged
StanFromIreland merged 3 commits into
python:mainfrom
iamsharduld:fix-mock-open-read-data-doc
Jun 13, 2026
Merged

gh-151443: Fix documented default of read_data in unittest.mock.mock_open#151444
StanFromIreland merged 3 commits into
python:mainfrom
iamsharduld:fix-mock-open-read-data-doc

Conversation

@iamsharduld

@iamsharduld iamsharduld commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

The documented signature of unittest.mock.mock_open shows read_data=None, but the real default is the empty string '':

  • Lib/unittest/mock.py: def mock_open(mock=None, read_data=''):
  • the function's own docstring ("This is an empty string by default")
  • inspect.signature(mock_open) -> (mock=None, read_data='')

The default was changed from None to '' in 2012 (0dccf657b51); the documentation was never updated. This corrects the signature in the docs.

Documentation-only change, so no Misc/NEWS.d entry is included.

@python-cla-bot

python-cla-bot Bot commented Jun 13, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

The documented signature showed read_data=None, but the actual default is the empty string -- Lib/unittest/mock.py, the function's docstring, and inspect.signature all agree. The code default changed from None to '' in 2012 (0dccf65); the docs were never updated.
@iamsharduld iamsharduld force-pushed the fix-mock-open-read-data-doc branch from 265d073 to 39cebae Compare June 13, 2026 16:56
@read-the-docs-community

read-the-docs-community Bot commented Jun 13, 2026

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33126962 | 📁 Comparing 9dfc211 against main (e933987)

  🔍 Preview build  

2 files changed
± library/unittest.mock.html
± whatsnew/changelog.html

@StanFromIreland

Copy link
Copy Markdown
Member

Please sign the CLA.

@StanFromIreland StanFromIreland left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@iamsharduld

Copy link
Copy Markdown
Contributor Author

Done, CLA signed

@StanFromIreland

Copy link
Copy Markdown
Member

Just for the future, please do not use the Update Branch button unless necessary (e.g. fixing conflicts, jogging the CI, or very old PRs) as it uses valuable resources. For more information see the devguide.

@StanFromIreland StanFromIreland added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Jun 13, 2026
@StanFromIreland StanFromIreland enabled auto-merge (squash) June 13, 2026 18:30
@StanFromIreland StanFromIreland merged commit 9ad6ba0 into python:main Jun 13, 2026
36 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in Docs PRs Jun 13, 2026
@miss-islington-app

Copy link
Copy Markdown

Thanks @iamsharduld for the PR, and @StanFromIreland for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Jun 13, 2026

Copy link
Copy Markdown

GH-151450 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Jun 13, 2026
@bedevere-app

bedevere-app Bot commented Jun 13, 2026

Copy link
Copy Markdown

GH-151451 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Jun 13, 2026
@bedevere-app

bedevere-app Bot commented Jun 13, 2026

Copy link
Copy Markdown

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

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Jun 13, 2026
@iamsharduld

Copy link
Copy Markdown
Contributor Author

Just for the future, please do not use the Update Branch button unless necessary (e.g. fixing conflicts, jogging the CI, or very old PRs) as it uses valuable resources. For more information see the devguide.

I see, thanks for the heads up and quick merge!

@StanFromIreland

Copy link
Copy Markdown
Member

Thanks for the PR!

StanFromIreland pushed a commit that referenced this pull request Jun 13, 2026
…'s `read_data` parameter (GH-151444)

(cherry picked from commit 9ad6ba0)

Co-authored-by: Shardul Deshpande <iamsharduld@users.noreply.github.com>
StanFromIreland pushed a commit that referenced this pull request Jun 13, 2026
…'s `read_data` parameter (GH-151444) (#151451)

(cherry picked from commit 9ad6ba0)

Co-authored-by: Shardul Deshpande <iamsharduld@users.noreply.github.com>
StanFromIreland pushed a commit that referenced this pull request Jun 13, 2026
…'s `read_data` parameter (GH-151444) (#151450)

(cherry picked from commit 9ad6ba0)

Co-authored-by: Shardul Deshpande <iamsharduld@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir skip news

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants