diff -r 4acdb324a430 Modules/posixmodule.c --- a/Modules/posixmodule.c Wed Apr 06 23:02:46 2016 +0300 +++ b/Modules/posixmodule.c Wed Apr 06 23:32:10 2016 +0300 @@ -905,14 +905,38 @@ path_converter(PyObject *o, void *p) return 1; } else { + PyObject *pathattr; + _Py_IDENTIFIER(path); + + pathattr = _PyObject_GetAttrId(o, &PyId_path); + if (pathattr == NULL) { + PyErr_Clear(); + } + else if (PyUnicode_Check(pathattr) || PyObject_CheckBuffer(pathattr)) { + if (!path_converter(pathattr, path)) { + Py_DECREF(pathattr); + return 0; + } + if (path->cleanup == NULL) { + path->cleanup = pathattr; + } + else { + Py_DECREF(pathattr); + } + return Py_CLEANUP_SUPPORTED; + } + else { + Py_DECREF(pathattr); + } + PyErr_Format(PyExc_TypeError, "%s%s%s should be %s, not %.200s", path->function_name ? path->function_name : "", path->function_name ? ": " : "", path->argument_name ? path->argument_name : "path", - path->allow_fd && path->nullable ? "string, bytes, integer or None" : - path->allow_fd ? "string, bytes or integer" : - path->nullable ? "string, bytes or None" : - "string or bytes", + path->allow_fd && path->nullable ? "string, bytes, Path, integer or None" : + path->allow_fd ? "string, bytes, Path or integer" : + path->nullable ? "string, bytes, Path or None" : + "string, bytes or Path", Py_TYPE(o)->tp_name); return 0; }