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

Function bytes_to_human_readable_repr

mypy/util.py:140–151  ·  view source on GitHub ↗

Converts bytes into some human-readable representation. Unprintable bytes such as the nul byte are escaped. For example: >>> b = bytes([102, 111, 111, 10, 0]) >>> s = bytes_to_human_readable_repr(b) >>> print(s) foo\n\x00 >>> print(repr(s)) 'foo\\

(b: bytes)

Source from the content-addressed store, hash-verified

138
139
140def bytes_to_human_readable_repr(b: bytes) -> str:
141 """Converts bytes into some human-readable representation. Unprintable
142 bytes such as the nul byte are escaped. For example:
143
144 >>> b = bytes([102, 111, 111, 10, 0])
145 >>> s = bytes_to_human_readable_repr(b)
146 >>> print(s)
147 foo\n\x00
148 >>> print(repr(s))
149 'foo\\n\\x00'
150 """
151 return repr(b)[2:-1]
152
153
154class DecodeError(Exception):

Callers 3

visit_ConstantMethod · 0.90
visit_ConstantMethod · 0.90

Calls 1

reprFunction · 0.85

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…