Skip to content

Commit e8e8042

Browse files
committed
Fix python#9790 again. Rather than handle NotImplementedError at runtime as
before, only attempt the import where nt._getfinalpathname could actually work, i.e., Windows Vista and beyond.
1 parent 0151b8e commit e8e8042

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

Lib/ntpath.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -642,12 +642,17 @@ def relpath(path, start=curdir):
642642

643643
# determine if two files are in fact the same file
644644
try:
645-
from nt import _getfinalpathname
646-
except (NotImplementedError, ImportError):
645+
# GetFinalPathNameByHandle is available starting with Windows 6.0.
646+
# Windows XP and non-Windows OS'es will mock _getfinalpathname.
647+
if sys.getwindowsversion()[:2] >= (6, 0):
648+
from nt import _getfinalpathname
649+
else:
650+
raise ImportError
651+
except (AttributeError, ImportError):
647652
# On Windows XP and earlier, two files are the same if their absolute
648653
# pathnames are the same.
649-
# Also, on other operating systems, fake this method with a
650-
# Windows-XP approximation.
654+
# Non-Windows operating systems fake this method with an XP
655+
# approximation.
651656
def _getfinalpathname(f):
652657
return abspath(f)
653658

0 commit comments

Comments
 (0)