-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
CliRunner prompt input echos twice on Python 2 #1101
Comments
Taking a look at this |
So this feature has proven to be a little more complex than it would seem. The reason behind this bug is that the EchoingStdin was not being set up properly for Python 3 as it's intended functionality of printing anything being read is being overrode by io.TextIOWrapper: if self.echo_stdin:
input = EchoingStdin(input, bytes_output)
input = io.TextIOWrapper(input, encoding=self.charset) So some re-ordering of this can reproduce the double print for 3.7 as well: input = io.TextIOWrapper(input, encoding=self.charset)
output = io.TextIOWrapper(
bytes_output, encoding=self.charset)
if self.echo_stdin:
input = EchoingStdin(input, output)
sys.stdout = output Then removing the forced print will lead to what I would believe to the the expected functionality: def visible_input(prompt=None):
sys.stdout.write(prompt or '')
val = input.readline().rstrip('\r\n')
- sys.stdout.write(val + '\n')
+ sys.stdout.write('\n')
sys.stdout.flush()
return val With echo_stdin=True both Python 2 and Python 3 output:
and echo_stdin=False outputs:
Assuming this is the desired functionality, this causes some breaks in unit tests, which to be honest are a little confusing as to what their intentions are based on how they are structured. Further investigation leads to a question of the actual purpose to the echo_stdin flag is, as there are also a hide_input and prompt options available to commands. |
This can be closed, support for py2 was removed. |
It revealed another issue with the Python 3 implementation. |
Python 3 output (correct):
Python 2 output:
I went back and this appears to be the case in every version since 1.x. The issue seems to be with the
visible_input
function inCliRunner.isolation
. It usesinput
after that has been wrapped inEchoingStdin
. It appears to work in Python 3 due to some weird lookup behavior, but that appears to be an accident. There are no tests forecho_stdin
andprompt
at the same time.It didn't show up in the docs because the docs runner overrode
isolation
with different code that hadvisible_input
pull from the original input and only replacedsys.stdin
with the EchoingStdin wrapper, rather than both with the wrapper. While porting the docs runner to pallets-sphinx-themes, I removed that code in favor of simpler subclassing, and noticed that the docs had double input, which led me to discover the full issue.The text was updated successfully, but these errors were encountered: