[docs] Remove support of bytes paths in os.scandir() (issue 27998)

eryksun+pybugs at gmail.com eryksun+pybugs at gmail.com
Sat Oct 8 10:08:04 EDT 2016


http://bugs.python.org/review/27998/diff/18802/Modules/posixmodule.c
File Modules/posixmodule.c (right):

http://bugs.python.org/review/27998/diff/18802/Modules/posixmodule.c#newcode11159
Modules/posixmodule.c:11159: PyObject *unicode = self->path;
How about consolidating this function as follows?

    static PyObject *
    path_object_error(PyObject *path)
    {
    #ifdef MS_WINDOWS
        return PyErr_SetExcFromWindowsErrWithFilenameObject(
                    PyExc_OSError, 0, path);
    #else
        return PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError,
path);
    #endif
    }

    static PyObject *
    DirEntry_fetch_stat(DirEntry *self, int follow_symlinks)
    {
        int result;
        STRUCT_STAT st;
        PyObject *ub;

    #ifdef MS_WINDOWS
        if (PyUnicode_FSDecoder(self->path, &ub)) {
            const wchar_t *path = PyUnicode_AsUnicode(ub);
    #else /* POSIX */
        if (PyUnicode_FSConverter(self->path, &ub)) {
            const char *path = PyBytes_AS_STRING(ub);
    #endif
            if (follow_symlinks)
                result = STAT(path, &st);
            else
                result = LSTAT(path, &st);
            Py_DECREF(ub);
        } else
            return NULL;
        
        if (result != 0)
            return path_object_error(self->path);

        return _pystat_fromstructstat(&st);
    }

http://bugs.python.org/review/27998/


More information about the docs mailing list