Allow importing when sys.stdout is reassigned on Python 3 #31
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes gh-30
sys.stdout.buffer
is not guaranteed to exist - e.g. ifsys.stdout
has been reassigned to anio.StringIO
instance, it won't. This is only used by the.interact()
method, so it should normally be in interactive cases with 'real' system stdout, but we need at least some fallback for when it isn't - and we certainly need to avoid relying on it at import time.We should think about the binding order. If
sys.stdout
is reassigned between importing pexpect and calling the.interact()
method, this case (spawn class on Python 3) will pick up the new stdout, but the other cases (spawnu on Python 3, either class on Python 2) won't. However, interact goes on to use direct access to stdout (and stdin) by fileno, so any redirection at the Python level won't be effective anyway.