GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-160427: Return None from TextIOWrapper.buffer when detached by cmaloney · Pull Request #160802 · python/cpython

Conversation

@cmaloney

@cmaloney cmaloney commented Oct 28, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

gh-154523 turned the buffer member descriptor into a getter that raises ValueError when the buffer is NULL, and the backport shipped in 3.14.9 and 3.15.1. That changed the behavior of hasattr(stream, "buffer") to raise after .detach(). Restore the old member descriptor result (None) while keeping the critical section for free-threaded safety.

  • Issue: hasattr(stream, "buffer") fails with ValueError if buffer is detached #160427

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@cmaloney
pythongh-160427: Return None from TextIOWrapper.buffer when detached
58f2c10
pythongh-154523 turned the buffer member descriptor into a getter that raises
ValueError when the buffer is NULL, and the backport shipped in 3.14.9
and 3.15.1. That made hasattr(stream, "buffer") raise after detach().
Restore the old member descriptor result (None) while keeping the
critical section.
@cmaloney cmaloney added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Oct 28, 2026
@bedevere-app bedevere-app Bot added the awaiting review label Oct 28, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Oct 28, 2026
hasattr(stream, "buffer") fails with ValueError if buffer is detached #160427
Closed
@cmaloney cmaloney linked an issue Oct 28, 2026 that may be closed by this pull request
hasattr(stream, "buffer") fails with ValueError if buffer is detached #160427
Closed
@cmaloney

cmaloney commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

cc: @kumaraditya303 , @vstinner : This attribute changed from returning None when unset to raising a ValueError. That was backported to stable branches breaking backwards compatibility.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cmaloney
cmaloney merged commit 3422197 into python:main Nov 5, 2026
62 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting review label Nov 5, 2026
@miss-islington-app

miss-islington-app Bot commented Nov 5, 2026

Copy link
Copy Markdown

Thanks @cmaloney for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cmaloney
cmaloney deleted the gh-160427-textio-buffer-none branch November 5, 2026 21:40
@miss-islington-app

miss-islington-app Bot commented Nov 5, 2026

Copy link
Copy Markdown

Sorry, @cmaloney, I could not cleanly backport this to 3.14 due to a conflict.

Please backport manually with cherry_picker, see the devguide for more information.

cherry_picker 3422197f5481ac1b3134e2633332415a02959ba4 3.14
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington-app miss-islington-app Bot assigned cmaloney Nov 5, 2026
@bedevere-app

bedevere-app Bot commented Nov 5, 2026

Copy link
Copy Markdown

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Nov 5, 2026
@bedevere-app

bedevere-app Bot commented Nov 5, 2026

Copy link
Copy Markdown

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Nov 5, 2026
cmaloney added a commit that referenced this pull request Nov 5, 2026
@miss-islington @cmaloney
[3.15] gh-160427: Return None from TextIOWrapper.buffer when detached (…
4af98bd
…GH-160802) (#161449)

gh-154523 turned the buffer member descriptor into a getter that raises
ValueError when the buffer is NULL, and the backport shipped in 3.14.9
and 3.15.1. That made hasattr(stream, "buffer") raise after detach().
Restore the old member descriptor result (None) while keeping the
critical section.
(cherry picked from commit 3422197)

Co-authored-by: Cody Maloney <[email protected]>
cmaloney added a commit that referenced this pull request Nov 5, 2026
@cmaloney
[3.14] gh-160427: Return None from TextIOWrapper.buffer when detached (…
9106913
…GH-160802) (#161450)

gh-154523 turned the buffer member descriptor into a getter that raises
ValueError when the buffer is NULL, and the backport shipped in 3.14.9
and 3.15.1. That made hasattr(stream, "buffer") raise after detach().
Restore the old member descriptor result (None) while keeping the
critical section.
(cherry picked from commit 3422197)
vstinner
vstinner approved these changes Nov 6, 2026
View reviewed changes

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Post-merge review.

Ooops, it's not good to change io module behavior in bugfix releases. Well, it happens, it should now be fixed as any other bug/regression. At least, we do now have a test checking for the expected behavior.

LGTM. _io_TextIOWrapper_buffer_get_impl() code is safe on Free Threading since it uses a critical section.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

cmaloney reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@vstinner vstinner vstinner approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@cmaloney cmaloney

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

hasattr(stream, "buffer") fails with ValueError if buffer is detached

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@cmaloney @vstinner
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.