New submission from Alexey Izbyshev <izbys...@ispras.ru>: os.path.isdir() violates its own documentation by returning True for broken directory symlinks or junctions, for which os.path.exists() returns False:
>>> os.mkdir('b') >>> import _winapi >>> _winapi.CreateJunction('b', 'a') >>> os.rmdir('b') >>> os.path.exists('a') False >>> os.path.isdir('a') True The underlying problem is that os.path.isdir() uses GetFileAttributes, which is documented not to follow symlinks. Eryk, is there a cheaper way to check FILE_ATTRIBUTE_DIRECTORY on a path while following reparse points apart from CreateFile/GetFileInformationByHandleEx/CloseFile? Also, does it make sense to use GetFileAttributes as a fast path and use something like above as a fallback only if FILE_ATTRIBUTE_REPARSE_POINT is set, or does GetFileAttributes do something equivalently expensive under the hood? ---------- components: Extension Modules, Windows messages: 313314 nosy: eryksun, izbyshev, paul.moore, steve.dower, tim.golden, zach.ware priority: normal severity: normal status: open title: os.path.isdir() returns True for broken directory symlinks or junctions type: behavior versions: Python 3.6, Python 3.7, Python 3.8 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue33010> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com