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-94808: add test coversage for PyFile_FromFd by fatelei · Pull Request #138866 · python/cpython

Conversation

@fatelei

@fatelei fatelei commented Sep 13, 2025

Copy link
Copy Markdown
Contributor

gh-94808: add test coversage for PyFile_FromFd

What I fixed
• Corrected PyFile_FromFd in Objects/fileobject.c to accept optional NULL strings for encoding, errors, and newline by switching the call format to use optional string specifiers:
• was "isisssO"
• now "isizzzO"
This fixes the bug where passing NULL crashed or misrouted arguments.

Unit tests added
• Extended Lib/test/test_capi/test_file.py:
• Added coverage for default buffering with buffering=-1:
◦ "rb" returns a _io.BufferedReader
◦ "r" returns a _io.TextIOWrapper
• Added a closefd=True behavior test (test_pyfile_fromfd_closefd) that ensures the underlying fd is closed when the returned object is closed (verifies EBADF on a second os.close).

Sorry, something went wrong.

Uh oh!

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

All reactions
@fatelei
feat: add test coversage for PyFile_FromFd
feecbf7
@bedevere-app bedevere-app Bot added the awaiting review label Sep 13, 2025
@bedevere-app

This comment was marked as resolved.

Sign in to view
@StanFromIreland StanFromIreland changed the title feat: add test coversage for PyFile_FromFd gh-94808: add test coversage for PyFile_FromFd Sep 13, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Sep 13, 2025
Metabug: Improving C-level coverage #94808
Open
@StanFromIreland StanFromIreland added tests Tests in the Lib/test dir skip issue labels Sep 13, 2025
serhiy-storchaka
serhiy-storchaka reviewed Oct 16, 2025
View reviewed changes

@serhiy-storchaka serhiy-storchaka 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.

A PR that adds tests for existing API should not change that API.

If you want to change PyFile_FromFd(), this should be a separate issue and a separate PR.

Sorry, something went wrong.

Uh oh!

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

vstinner and efimov-mikhail reacted with thumbs up emoji
All reactions
  • 👍 2 reactions
vstinner
vstinner reviewed Oct 16, 2025
View reviewed changes
Comment thread Objects/fileobject.c Resolved

Uh oh!

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

@vstinner vstinner added the skip news label Oct 16, 2025
@fatelei
chore: revert change
0f88a00
efimov-mikhail
efimov-mikhail reviewed Oct 18, 2025
View reviewed changes
Comment thread Lib/test/test_capi/test_file.py
finally:
obj.close()

# Default buffering in binary mode (-1): BufferedReader

@efimov-mikhail efimov-mikhail Oct 18, 2025

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.

Why you're checking this here?
There's already tests on BufferedReader and TextIOWrapper below in this function.
Also, it's strange to open fd2 and fd3 under already existing with section for fp.

I need to ask if this PR was generated by LLM?

Sorry, something went wrong.

Uh oh!

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

All reactions
@fatelei fatelei closed this Oct 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@vstinner vstinner vstinner left review comments
@serhiy-storchaka serhiy-storchaka serhiy-storchaka left review comments
@efimov-mikhail efimov-mikhail efimov-mikhail left review comments

Uh oh!

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

Assignees

No one assigned

Labels

awaiting review skip issue skip news tests Tests in the Lib/test dir

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

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

5 participants

@fatelei @vstinner @serhiy-storchaka @efimov-mikhail @StanFromIreland
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.