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

gh-143866: Verify return value of pathlib write methods in tests by b9788213 · Pull Request #143870 · python/cpython · GitHub

/ cpython Public

gh-143866: Verify return value of pathlib write methods in tests - #143870

Merged
sobolevn merged 6 commits into
python:mainfrom
b9788213:gh-143866-pathlib-test
Jan 19, 2026
Merged

gh-143866: Verify return value of pathlib write methods in tests#143870
sobolevn merged 6 commits into
python:mainfrom
b9788213:gh-143866-pathlib-test

Conversation

b9788213 commented Jan 15, 2026
edited
Loading

Copy link
Copy Markdown
Contributor

Description

This PR adds assertions to ensure that pathlib.Path.write_text() and pathlib.Path.write_bytes() correctly return the number of bytes written.

Currently, the tests only verify the side effects (file content), which means a regression (like accidentally removing the return statement) would go unnoticed.

Linked Issue

Fixes #143866

b9788213 requested a review from barneygale as a code owner January 15, 2026 14:29
bedevere-app Bot added the tests Tests in the Lib/test dir label Jan 15, 2026

bedevere-app Bot commented Jan 15, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

Comment thread Lib/test/test_pathlib/test_write.py Outdated

bedevere-app Bot commented Jan 15, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

Copy link
Copy Markdown
Contributor Author

Ok, i am changed it. Can you add "skip news" label please?

Comment thread Lib/test/test_pathlib/test_write.py Outdated
Comment thread Lib/test/test_pathlib/test_write.py Outdated
self.assertEqual(self.ground.readbytes(p), b'abcdefg')
# check the return value
data = b'some bytes'
self.assertEqual(len(data), p.write_bytes(data))

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Can we do the same here and move the check to the line 68?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Yes i will

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This will fix the CI.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

My push from another device isnt synced.

Copy link
Copy Markdown
Contributor Author

Why its failing?

b9788213 force-pushed the gh-143866-pathlib-test branch from b727c7c to 7a8dd6f Compare January 16, 2026 17:54

picnixz commented Jan 18, 2026

Copy link
Copy Markdown
Member

Some flakiness I think.

Copy link
Copy Markdown
Contributor Author

How?

sobolevn added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Jan 19, 2026
sobolevn merged commit cb6a662 into python:main Jan 19, 2026
53 checks passed

Copy link
Copy Markdown

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

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 19, 2026
…methods in tests (pythonGH-143870)

(cherry picked from commit cb6a662)

Co-authored-by: b9788213 <b9788213@gmail.com>
Co-authored-by: sobolevn <mail@sobolevn.me>

Copy link
Copy Markdown

Sorry, @b9788213 and @sobolevn, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker cb6a662bb0f7a9da9d4ba9dda820053f8d54a9f8 3.13

bedevere-app Bot commented Jan 19, 2026

Copy link
Copy Markdown

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

bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Jan 19, 2026

Copy link
Copy Markdown
Member

@b9788213 can you please handle the 3.13 backport manually?

sobolevn added a commit that referenced this pull request Jan 19, 2026
… methods in tests (GH-143870) (#144029)

gh-143866: Verify return value of `pathlib.write_{bytes,text}` methods in tests (GH-143870)
(cherry picked from commit cb6a662)

Co-authored-by: b9788213 <b9788213@gmail.com>
Co-authored-by: sobolevn <mail@sobolevn.me>
b9788213 deleted the gh-143866-pathlib-test branch January 20, 2026 12:09

Copy link
Copy Markdown
Contributor Author

Yes, but i dont how to do.

Copy link
Copy Markdown
Member

Copy link
Copy Markdown
Contributor Author

Ok, i think i have made it succesfully.

bedevere-app Bot commented Jan 20, 2026

Copy link
Copy Markdown

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

bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Jan 20, 2026
sobolevn added a commit that referenced this pull request Jan 20, 2026
… methods in tests (GH-143870) (#144078)

(cherry picked from commit cb6a662)

Co-authored-by: sobolevn <mail@sobolevn.me>
thunder-coding pushed a commit to thunder-coding/cpython that referenced this pull request Feb 15, 2026
…methods in tests (python#143870)

Co-authored-by: sobolevn <mail@sobolevn.me>
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

skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing return value validation in pathlib's write_text and write_bytes tests

3 participants


Back | FazBrowse Home | New Git URL