[New-bugs-announce] [issue20541] os.path.exists() gives wrong answer for Windows special files

Nick Coghlan report at bugs.python.org
Fri Feb 7 13:47:34 CET 2014

New submission from Nick Coghlan:

In trying to figure out why my fix for issue 20053 wasn't working on Windows, I eventually traced it back to the fact that "os.path.exists(os.devnull)" returns False on Windows, so pip isn't picking up my config file override in ensurepip, and reads the global default config file anyway.

However, if you do "if exist NUL (echo exists) ELSE (echo missing)" in cmd, it will print "exists", so this looks like a bug in our os.path.exists implementation.

That is currently implemented in genericpath and assumes that a file exists if-and-only-if os.stat(name) doesn't throw an exception.

It turns out this assumption isn't really correct on Windows - 'NUL' and 'CON' (and presumably other special files) can be opened, but trying to do os.stat() on them throws an exception.

components: Library (Lib), Windows
messages: 210460
nosy: ncoghlan
priority: normal
severity: normal
stage: test needed
status: open
title: os.path.exists() gives wrong answer for Windows special files
type: behavior
versions: Python 2.7, Python 3.3, Python 3.4, Python 3.5

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list