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

Function bytes_from_str

mypyc/irbuild/util.py:298–305  ·  view source on GitHub ↗

Convert a string representing bytes into actual bytes. This is needed because the literal characters of BytesExpr (the characters inside b'') are stored in BytesExpr.value, whose type is 'str' not 'bytes'.

(value: str)

Source from the content-addressed store, hash-verified

296
297
298def bytes_from_str(value: str) -> bytes:
299 """Convert a string representing bytes into actual bytes.
300
301 This is needed because the literal characters of BytesExpr (the
302 characters inside b'') are stored in BytesExpr.value, whose type is
303 'str' not 'bytes'.
304 """
305 return bytes(value, "utf8").decode("unicode-escape").encode("raw-unicode-escape")

Callers 2

constant_fold_exprFunction · 0.90

Calls 3

bytesClass · 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…