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 46 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.

@arian-bozorgzad

Copy link
Copy Markdown
Author

@A5rocks
Hi, I just wanted to check if you have any feedback or suggestions for this pr.i would really appreciate a feedback
Thanks for your time

@A5rocks A5rocks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry for the wait! Please don't mention me elsewhere to get my attention.

Comment thread docs/source/reference-io.rst Resolved
@@ -0,0 +1,3 @@
:class:`trio.AsyncIOWrapper` is now public, so values returned by
:func:`trio.open_file`, :func:`trio.wrap_file`, and :meth:`trio.Path.open` can
be annotated without importing from the private ``trio._file_io`` module.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No need for the without importing from ....

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not convinced this file tests anything beyond what src/trio/_tests/type_tests/path.py tests

Comment on lines +420 to +421
# instances. The file-I/O tests separately verify that the dynamic
# methods and the TYPE_CHECKING declarations stay in sync.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What?

Comment thread src/trio/_file_io.py
Comment on lines +229 to +231
:func:`trio.wrap_file`, or :meth:`trio.Path.open`. The generic parameter
records the type of the wrapped synchronous file object, and the available
file operations follow that wrapped type.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The paragraph before this already mentions that this class exposes the file ops

@CoolCat467 CoolCat467 added the LLM Slop Entirely generated by a large language model with little or no human oversight label Nov 10, 2026

This branch has not been deployed

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

Labels

LLM Slop Entirely generated by a large language model with little or no human oversight

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Type annotations for trio.open_file & trio.wrap_file

3 participants