-
-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add async stdio files #154
Conversation
There are a handful of superfluous changes in the diff because I ran black on the whole project to format my code. |
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.
LGTM, please add a history snippet to the README.
src/aiofiles/threadpool/__init__.py
Outdated
|
||
try: | ||
stdin = wrap(sys.stdin, indirect=lambda: sys.stdin) | ||
except TypeError: |
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.
Where do the TypeErrors come from btw?
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.
sys.stdin
may have been patched to be an unusable base type prior to importing aiofiles. This happens specifically when using pytest. I figured I would add it to the rest of the stdio files just be safe.
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.
I see, alright. Do we want to document this for people somewhere?
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.
imo the best documentation would be replacing the stdin = None
with a custom class which raises a descriptive error when you try to use any of its methods. I was hoping I could convince you to do that 😅
lmk if you would like to do that or just add a note to the readme/docs
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.
Never mind, just thought of a much better solution. One sec.
Okay. new commit. This one makes it so that wrap() no longer has the option to do indirect wrapping, which makes sense - you need to specify the type of the base class if the underlying file (and its type!) can change - you need to be accountable for the contract that the interface you're wrapping provides, which may be different than its stated type. As a result, things are simplified drastically, and e.g. trying to use stdin from tests yields pytest's error with a meaningful message. |
Cool, thanks. Will merge it in soon. |
Can you please release this on pypi? |
Released! |
Closes #153
Closes #131
This adds stdin, stdout, stderr, and their binary counterparts to aiofiles. It does this by introducing two concepts:
is None
check.AsyncIndirectBase
. This is only used when opted-in explicitly, which we do for the stdio files in order to support monkeypatching, as is common in the python ecosystem.