File warning instead of fail if stdout does not have encoding
See original GitHub issueAccording to Python manual sys.stdout
should have encoding
.
Unfortunatelly, nose
monekypatches it with StringIO
with out of encoding.
See: https://github.com/nose-devs/nose/issues/1065
Its nose fault, not win-unicode-console fault. But can we please do
def check_encodings():
try:
if sys.stdin.encoding != sys.stdout.encoding:
# raise RuntimeError("sys.stdin.encoding != sys.stdout.encoding, readline hook doesn't know, which one to use to decode prompt")
warnings.warn("sys.stdin.encoding == {!r}, whereas sys.stdout.encoding == {!r}, readline hook consumer may assume they are the same".format(sys.stdin.encoding, sys.stdout.encoding),
RuntimeWarning, stacklevel=3)
except AttributeError:
warnings.warn("stdin or stdout does not have encoding")
?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Setting the correct encoding when piping stdout in Python
Your code works when run in an script because Python encodes the output to whatever encoding your terminal application is using.
Read more >Command output not displayed in Windows #201 - GitHub
Under Python 3, if you don't specify an encoding when opening a file, you will get os.device_encoding(fd.fileno()) if the file is a terminal ......
Read more >subprocess — Subprocess management — Python 3.11.1 ...
If encoding or errors are specified, or text is true, the file objects stdin, stdout and stderr are opened in text mode with...
Read more >Encoding of Python stdout - Exterior Memory - MacFreek
Python determines the encoding of stdout and stderr based on the value of the LC_CTYPE variable, but only if the stdout is a...
Read more >Python 3 Support — Click Documentation (4.x)
This causes problems if the terminal is incorrectly set and Python does not figure out the encoding. In that case, the Unicode string...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Does the solution of #36 work for you? Also thank you for the pull request, but I’ll probably add something like
So,
stdin
andstdout
cases are distinguished. Also, there is probably a reason to use stacklevel=3 in the warn, so I would use it here also.@Drekin A clear warning is always better than a crash.