trio icon indicating copy to clipboard operation
trio copied to clipboard

Publicly expose `AsyncIOWrapper`

Open CoolCat467 opened this issue 2 years ago • 8 comments

This PR exposes _file_io.AsyncIOWrapper to the public. I was working on a project of mine that has to use trio.wrap_file and calls a few functions that needed to take the returned AsyncIOWrapper object as a parameter, but when typing arguments for said functions I found that AsyncIOWrapper is not exposed publicly and the only way to type it properly would be to manually reach in to trio._file_io and get it.

CoolCat467 avatar Nov 05 '23 05:11 CoolCat467

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (05c5df2) 99.64% compared to head (f8f0018) 99.64%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2864   +/-   ##
=======================================
  Coverage   99.64%   99.64%           
=======================================
  Files         116      116           
  Lines       17503    17504    +1     
  Branches     3148     3149    +1     
=======================================
+ Hits        17441    17442    +1     
  Misses         43       43           
  Partials       19       19           
Files Coverage Δ
src/trio/__init__.py 100.00% <100.00%> (ø)
src/trio/_file_io.py 100.00% <100.00%> (ø)

codecov[bot] avatar Nov 05 '23 05:11 codecov[bot]

How do I fix the errors test_static_tool_sees_class_members has? The big blob it prints out is of no help on resolving whatever the issue is and I keep getting confused when I encounter these sorts of issues and what to even do to attempt to fix said reported issues.

CoolCat467 avatar Nov 06 '23 00:11 CoolCat467

Probably similar to what you did for the dir thing!

A5rocks avatar Nov 06 '23 01:11 A5rocks

Would it be a good idea to expose this? The way it works is kinda complicated, and I imagine we might need to change those hints at some point - exposing it means we're saying it's a more stable API. Also users using it as a type hint means they don't accept any "native" file classes. Like the synchronous IO, it'd be better to define a protocol at the place you use it, with the methods you need.

TeamSpen210 avatar Nov 06 '23 02:11 TeamSpen210

Would it be a good idea to expose this? The way it works is kinda complicated, and I imagine we might need to change those hints at some point - exposing it means we're saying it's a more stable API. Also users using it as a type hint means they don't accept any "native" file classes. Like the synchronous IO, it'd be better to define a protocol at the place you use it, with the methods you need.

Did you read my usage case? I am trying to specifically handle asynchronous file objects in a function's arguments, and I have to resort to reaching into the internals of trio to type it properly, which I think is unacceptable. I am not intending on handling native synchronous file IO at all, only the async version.

CoolCat467 avatar Nov 06 '23 02:11 CoolCat467

Yep, what I mean is that you should define a protocol, only include the methods you need, then annotate the function as accepting that. Then a class that doesn't inherit from the wrapper but does define appropriate methods will work.

TeamSpen210 avatar Nov 06 '23 03:11 TeamSpen210

Probably similar to what you did for the dir thing!

I'm blanking on this, not remembering what you are referring to by this

CoolCat467 avatar Nov 18 '23 04:11 CoolCat467

Sorry, I just misread https://github.com/python-trio/trio/pull/2864/commits/a0f58eaffbe46636716beea8b6f887dafc4e8a72

A5rocks avatar Nov 18 '23 06:11 A5rocks