(
x: str | bytes, encoding: str | None = None, errors: str | None = None
)
| 5 | |
| 6 | |
| 7 | def to_bytes( |
| 8 | x: str | bytes, encoding: str | None = None, errors: str | None = None |
| 9 | ) -> bytes: |
| 10 | if isinstance(x, bytes): |
| 11 | return x |
| 12 | elif not isinstance(x, str): |
| 13 | raise TypeError(f"not expecting type {type(x).__name__}") |
| 14 | if encoding or errors: |
| 15 | return x.encode(encoding or "utf-8", errors=errors or "strict") |
| 16 | return x.encode() |
| 17 | |
| 18 | |
| 19 | def to_str( |
no outgoing calls