New submission from Alexey Izbyshev <>:

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')
>>> os.path.isdir('a')

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 

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 <>
Python-bugs-list mailing list

Reply via email to