This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: pathlib OS detection
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.4, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: pitrou Nosy List: Antony.Lee, pitrou, python-dev, serhiy.storchaka
Priority: normal Keywords:

Created on 2014-09-09 16:24 by Antony.Lee, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg226644 - (view) Author: Antony Lee (Antony.Lee) * Date: 2014-09-09 16:24
Currently, pathlib contains the following check for the OS in the import section:

    try:
        import nt
    except ImportError:
        nt = None
    else:
        if sys.getwindowsversion()[:2] >= (6, 0):
            from nt import _getfinalpathname
        else:
            supports_symlinks = False
            _getfinalpathname = None

I would like to suggest to switch this on testing for the value of `os.name` (as `PurePath.__new__` does), or possibly testing whether `sys.getwindowsversion` exists: the `nt` module is not publicly defined, so it wouldn't be unreasonable to have a file named `nt.py` on an Unix system (where this shouldn't cause any problems), in which case importing `pathlib` raises an AttributeError at the `getwindowsversion` line.
msg231318 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-11-18 13:27
This sounds reasonable, indeed.
msg231352 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-11-18 23:33
New changeset cb1d7eac601d by Antoine Pitrou in branch '3.4':
Close #22370: Windows detection in pathlib is now more robust.
https://hg.python.org/cpython/rev/cb1d7eac601d

New changeset 712f246da49b by Antoine Pitrou in branch 'default':
Close #22370: Windows detection in pathlib is now more robust.
https://hg.python.org/cpython/rev/712f246da49b
History
Date User Action Args
2022-04-11 14:58:07adminsetgithub: 66565
2014-11-18 23:33:26python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg231352

resolution: fixed
stage: needs patch -> resolved
2014-11-18 13:27:10pitrousetmessages: + msg231318
stage: needs patch
2014-11-18 09:49:44serhiy.storchakasetassignee: pitrou

type: behavior
nosy: + pitrou, serhiy.storchaka
2014-09-09 16:24:51Antony.Leecreate