Skip to content

docs: document wrap_file behavior with sync file objects - #3599

Closed
swastiktawate wants to merge 1 commit into
python-trio:mainfrom
swastiktawate:fix-3379-wrap-file-docs
Closed

swastiktawate wants to merge 1 commit into
python-trio:mainfrom
swastiktawate:fix-3379-wrap-file-docs

Conversation

@swastiktawate

Copy link
Copy Markdown

This fixes #3379.

The docs for trio.wrap_file did not say what happens to the sync file object you pass in. The docstring now says three things:

  • Closing the wrapped file also closes the sync file.
  • Dropping the wrapped file without closing it does not close the sync file, because the wrapper has no destructor.
  • You can keep using the sync file while it is wrapped.

I checked all three by running a small script first, and added a test (test_wrap_file_close_and_gc in test_file_io.py) that covers all three so the docs stay correct.

@A5rocks A5rocks closed this Nov 18, 2026
@codecov

codecov Bot commented Nov 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00000%. Comparing base (76d58d1) to head (436bc10).

Additional details and impacted files
@@               Coverage Diff               @@
##                 main        #3599   +/-   ##
===============================================
  Coverage   100.00000%   100.00000%           
===============================================
  Files             128          128           
  Lines           19586        19606   +20     
  Branches         1334         1334           
===============================================
+ Hits            19586        19606   +20     
Files with missing lines Coverage Δ
src/trio/_file_io.py 100.00000% <ø> (ø)
src/trio/_tests/test_file_io.py 100.00000% <100.00000%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

trio.wrap_file() undocumented behavior wrt to sync file object

2 participants