MCPcopy Index your code
hub / github.com/python/mypy / safe_print

Function safe_print

mypy/stubtest.py:2497–2507  ·  view source on GitHub ↗

Print a text replacing chars not representable in stdout encoding.

(text: str)

Source from the content-addressed store, hash-verified

2495
2496
2497def safe_print(text: str) -> None:
2498 """Print a text replacing chars not representable in stdout encoding."""
2499 # If `sys.stdout` encoding is not the same as out (usually UTF8) string,
2500 # if may cause painful crashes. I don't want to reconfigure `sys.stdout`
2501 # to do `errors = "replace"` as that sounds scary.
2502 out_encoding = sys.stdout.encoding
2503 if out_encoding is not None:
2504 # Can be None if stdout is replaced (including our own tests). This should be
2505 # safe to omit if the actual stream doesn't care about encoding.
2506 text = text.encode(out_encoding, errors="replace").decode(out_encoding, errors="replace")
2507 print(text)
2508
2509
2510def parse_options(args: list[str]) -> _Arguments:

Callers 1

test_stubsFunction · 0.85

Calls 3

printFunction · 0.85
encodeMethod · 0.80
decodeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…