Skip to content

Conversation

@b9788213
Copy link
Contributor

@b9788213 b9788213 commented Jan 15, 2026

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 b9788213 requested a review from barneygale as a code owner January 15, 2026 14:29
@bedevere-app bedevere-app bot added the tests Tests in the Lib/test dir label Jan 15, 2026
@bedevere-app
Copy link

bedevere-app bot commented Jan 15, 2026

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.

@bedevere-app
Copy link

bedevere-app bot commented Jan 15, 2026

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.

@b9788213
Copy link
Contributor Author

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

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
Member

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes i will

Copy link
Member

Choose a reason for hiding this comment

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

This will fix the CI.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My push from another device isnt synced.

@b9788213
Copy link
Contributor Author

Why its failing?

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

picnixz commented Jan 18, 2026

Some flakiness I think.

@b9788213
Copy link
Contributor Author

How?

@sobolevn 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 sobolevn merged commit cb6a662 into python:main Jan 19, 2026
53 checks passed
@miss-islington-app
Copy link

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>
@miss-islington-app
Copy link

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
Copy link

bedevere-app bot commented Jan 19, 2026

GH-144029 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 Jan 19, 2026
@sobolevn
Copy link
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs backport to 3.13 bugs and security fixes 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