mirror of
https://github.com/python/cpython.git
synced 2025-11-03 03:22:27 +00:00
bpo-30879: os.listdir() and os.scandir() now emit bytes names when (#2634)
called with bytes-like argument.
This commit is contained in:
parent
4f9a446f3f
commit
1180e5a518
4 changed files with 35 additions and 6 deletions
|
|
@ -1037,6 +1037,8 @@ path_converter(PyObject *o, void *p)
|
|||
Py_INCREF(bytes);
|
||||
}
|
||||
else if (is_buffer) {
|
||||
/* XXX Replace PyObject_CheckBuffer with PyBytes_Check in other code
|
||||
after removing suport of non-bytes buffer objects. */
|
||||
if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
|
||||
"%s%s%s should be %s, not %.200s",
|
||||
path->function_name ? path->function_name : "",
|
||||
|
|
@ -3588,8 +3590,8 @@ _posix_listdir(path_t *path, PyObject *list)
|
|||
const char *name;
|
||||
if (path->narrow) {
|
||||
name = path->narrow;
|
||||
/* only return bytes if they specified a bytes object */
|
||||
return_str = !(PyBytes_Check(path->object));
|
||||
/* only return bytes if they specified a bytes-like object */
|
||||
return_str = !PyObject_CheckBuffer(path->object);
|
||||
}
|
||||
else {
|
||||
name = ".";
|
||||
|
|
@ -11842,7 +11844,7 @@ DirEntry_from_posix_info(path_t *path, const char *name, Py_ssize_t name_len,
|
|||
goto error;
|
||||
}
|
||||
|
||||
if (!path->narrow || !PyBytes_Check(path->object)) {
|
||||
if (!path->narrow || !PyObject_CheckBuffer(path->object)) {
|
||||
entry->name = PyUnicode_DecodeFSDefaultAndSize(name, name_len);
|
||||
if (joined_path)
|
||||
entry->path = PyUnicode_DecodeFSDefault(joined_path);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue