MCPcopy Create free account
hub / github.com/bslatkin/effectivepython / to_str

Function to_str

example_code/item_108/testing/utils.py:17–23  ·  view source on GitHub ↗
(data)

Source from the content-addressed store, hash-verified

15# limitations under the License.
16
17def to_str(data):
18 if isinstance(data, str):
19 return data
20 elif isinstance(data, bytes):
21 return data.decode("utf-8")
22 else:
23 raise TypeError(f"Must supply str or bytes, found: {data}")

Callers 7

test_goodMethod · 0.90
test_badMethod · 0.90
test_to_str_badMethod · 0.90
test_to_str_bytesMethod · 0.90
test_to_str_strMethod · 0.90
test_failingMethod · 0.90

Calls

no outgoing calls

Tested by 7

test_goodMethod · 0.72
test_badMethod · 0.72
test_to_str_badMethod · 0.72
test_to_str_bytesMethod · 0.72
test_to_str_strMethod · 0.72
test_failingMethod · 0.72