Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve identification of bytes-like objects
  • Loading branch information
mhsmith committed Apr 24, 2024
commit 41736d6a9487dfe94c057178068e37e2da8fef6d
11 changes: 7 additions & 4 deletions Lib/_android_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,14 @@ def writable(self):
return True

def write(self, b):
if hasattr(b, "__buffer__"):
b_out = bytes(b)
else:
try:
memoryview(b)
except TypeError:
raise TypeError(
f"write() argument must be bytes-like, not {type(b).__name__}")
f"write() argument must be bytes-like, not {type(b).__name__}"
) from None
else:
b_out = bytes(b)

# Encode null bytes using "modified UTF-8" to avoid truncating the
# message.
Expand Down
3 changes: 1 addition & 2 deletions Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -2738,8 +2738,7 @@ android_log_write_impl(PyObject *self, PyObject *args)
int prio = 0;
char *tag = NULL;
char *text = NULL;
Py_ssize_t *text_len = 0;
if (!PyArg_ParseTuple(args, "iss#", &prio, &tag, &text, &text_len))
if (!PyArg_ParseTuple(args, "isy", &prio, &tag, &text))
return NULL;

// Despite its name, this function is part of the public API
Expand Down