File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -2107,11 +2107,12 @@ def safe_print(text: str) -> None:
21072107 # If `sys.stdout` encoding is not the same as out (usually UTF8) string,
21082108 # if may cause painful crashes. I don't want to reconfigure `sys.stdout`
21092109 # to do `errors = "replace"` as that sounds scary.
2110- print (
2111- text .encode (sys .stdout .encoding , errors = "replace" ).decode (
2112- sys .stdout .encoding , errors = "replace"
2113- )
2114- )
2110+ out_encoding = sys .stdout .encoding
2111+ if out_encoding is not None :
2112+ # Can be None if stdout is replaced (including our own tests). This should be
2113+ # safe to omit if the actual stream doesn't care about encoding.
2114+ text = text .encode (out_encoding , errors = "replace" ).decode (out_encoding , errors = "replace" )
2115+ print (text )
21152116
21162117
21172118def parse_options (args : list [str ]) -> _Arguments :
You can’t perform that action at this time.
0 commit comments