Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit db118f5

Browse files
committed
Close #22370: Windows detection in pathlib is now more robust.
1 parent 81f68a7 commit db118f5

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

Lib/pathlib.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,15 @@
1515

1616

1717
supports_symlinks = True
18-
try:
18+
if os.name == 'nt':
1919
import nt
20-
except ImportError:
21-
nt = None
22-
else:
2320
if sys.getwindowsversion()[:2] >= (6, 0):
2421
from nt import _getfinalpathname
2522
else:
2623
supports_symlinks = False
2724
_getfinalpathname = None
25+
else:
26+
nt = None
2827

2928

3029
__all__ = [
@@ -110,7 +109,7 @@ class _WindowsFlavour(_Flavour):
110109
has_drv = True
111110
pathmod = ntpath
112111

113-
is_supported = (nt is not None)
112+
is_supported = (os.name == 'nt')
114113

115114
drive_letters = (
116115
set(chr(x) for x in range(ord('a'), ord('z') + 1)) |

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ Core and Builtins
3636
Library
3737
-------
3838

39+
- Issue #22370: Windows detection in pathlib is now more robust.
40+
3941
- Issue #22841: Reject coroutines in asyncio add_signal_handler().
4042
Patch by Ludovic.Gasc.
4143

0 commit comments

Comments
 (0)