Skip to content

Expose AsyncIOWrapper publicly - #3512

Open
arian-bozorgzad wants to merge 1 commit into
python-trio:mainfrom
arian-bozorgzad:expose-async-io-wrapper
Open

arian-bozorgzad wants to merge 1 commit into
python-trio:mainfrom
arian-bozorgzad:expose-async-io-wrapper

Conversation

@arian-bozorgzad

@arian-bozorgzad arian-bozorgzad commented Sep 14, 2026

Copy link
Copy Markdown

This makes AsyncIOWrapper available as trio.AsyncIOWrapper, so it can be used to annotate values returned by open_file(), wrap_file(), and Path.open() without importing from the private _file_io module.

I added a short section to the docs as well, like including a note about using a protocol when only part of the async file interface is needed.

i also updated export test because AsyncIOWrapper has a slightly different static and runtime interface ,The test now checks that the difference is exactly the expected dynamic file methods before continuing with the normal export checks, and added type tests for open_file() and wrap_file().
and since AsyncIOWrapper exposes some file methods dynamically, I updated the export test to check that the difference between its static and runtime interfaces is exactly the expected set of dynamic methods.
Fixes #3390

python -m pytest src/trio/_tests/test_file_io.py
17 passed - 0 fails

python -m tox -e typing
mypy (linux): passed
mypy (darwin): passed
mypy (win32): passed
pyright: 0 errors

@codecov

codecov Bot commented Sep 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00000%. Comparing base (a3d7cdd) to head (8714b03).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@               Coverage Diff               @@
##                 main        #3512   +/-   ##
===============================================
  Coverage   100.00000%   100.00000%           
===============================================
  Files             128          128           
  Lines           19454        19461    +7     
  Branches         1321         1322    +1     
===============================================
+ Hits            19454        19461    +7     
Files with missing lines Coverage Δ
src/trio/__init__.py 100.00000% <100.00000%> (ø)
src/trio/_file_io.py 100.00000% <100.00000%> (ø)
src/trio/_tests/test_exports.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.

Type annotations for trio.open_file & trio.wrap_file

1 participant