Index: Modules/posixmodule.c =================================================================== --- Modules/posixmodule.c (revision 66545) +++ Modules/posixmodule.c (working copy) @@ -2326,7 +2326,7 @@ PyObject *d, *v; DIR *dirp; struct dirent *ep; - int arg_is_unicode = 1; + int arg_is_unicode = 1, problems = 0; errno = 0; if (!PyArg_ParseTuple(args, "U:listdir", &v)) { @@ -2378,9 +2378,9 @@ v = w; } else { - /* fall back to the original byte string, as - discussed in patch #683592 */ PyErr_Clear(); + problems = 1; + continue; } } if (PyList_Append(d, v) != 0) { @@ -2394,6 +2394,13 @@ closedir(dirp); PyMem_Free(name); + if (problems && PyErr_WarnEx(PyExc_UnicodeWarning, + "Some file names could not be decoded " + "and were ignored.", 2)) { + Py_DECREF(d); + return NULL; + } + return d; #endif /* which OS */