[issue35692] pathlib.Path.exists() on non-existent drive raises WinError instead of returning False

Eryk Sun report at bugs.python.org
Tue Jan 15 20:36:13 EST 2019


Eryk Sun <eryksun at gmail.com> added the comment:

> There's no reason a non-existing drive should fail differently than 
> a non-existing parent directory.

The drive exists (or should) if we're getting ERROR_NOT_READY (21). It's likely a removable media device, such as an optical disc or card reader, and there's no media in the device. 

If a logical drive isn't defined at all, we should get ERROR_PATH_NOT_FOUND (from the NT status value STATUS_OBJECT_PATH_NOT_FOUND). This gets mapped to the errno value ENOENT, which is already handled. For example:

    >>> os.stat('Q:/')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    FileNotFoundError: [WinError 3] The system cannot find the path specified: 'Q:/'

    >>> pathlib.Path('Q:/whatever/blah.txt').exists()
    False

Similarly if a UNC 'drive' doesn't exist, we should get ERROR_BAD_NET_NAME (from NT STATUS_BAD_NETWORK_NAME), which is also mapped to ENOENT:

    >>> os.stat('//some/where')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    FileNotFoundError: [WinError 67] The network name cannot be found: '//some/where'

    >>> pathlib.Path('//some/where/whatever/blah.txt').exists()
    False

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35692>
_______________________________________


More information about the Python-bugs-list mailing list