@@ -110,7 +110,7 @@ class PurePath(_abc.PurePathBase):
110
110
# path. It's set when `__hash__()` is called for the first time.
111
111
'_hash' ,
112
112
)
113
- pathmod = os .path
113
+ parser = os .path
114
114
115
115
def __new__ (cls , * args , ** kwargs ):
116
116
"""Construct a PurePath from one or several strings and or existing
@@ -126,7 +126,7 @@ def __init__(self, *args):
126
126
paths = []
127
127
for arg in args :
128
128
if isinstance (arg , PurePath ):
129
- if arg .pathmod is ntpath and self .pathmod is posixpath :
129
+ if arg .parser is ntpath and self .parser is posixpath :
130
130
# GH-103631: Convert separators for backwards compatibility.
131
131
paths .extend (path .replace ('\\ ' , '/' ) for path in arg ._raw_paths )
132
132
else :
@@ -187,7 +187,7 @@ def _str_normcase(self):
187
187
try :
188
188
return self ._str_normcase_cached
189
189
except AttributeError :
190
- if _abc ._is_case_sensitive (self .pathmod ):
190
+ if _abc ._is_case_sensitive (self .parser ):
191
191
self ._str_normcase_cached = str (self )
192
192
else :
193
193
self ._str_normcase_cached = str (self ).lower ()
@@ -203,34 +203,34 @@ def __hash__(self):
203
203
def __eq__ (self , other ):
204
204
if not isinstance (other , PurePath ):
205
205
return NotImplemented
206
- return self ._str_normcase == other ._str_normcase and self .pathmod is other .pathmod
206
+ return self ._str_normcase == other ._str_normcase and self .parser is other .parser
207
207
208
208
@property
209
209
def _parts_normcase (self ):
210
210
# Cached parts with normalized case, for comparisons.
211
211
try :
212
212
return self ._parts_normcase_cached
213
213
except AttributeError :
214
- self ._parts_normcase_cached = self ._str_normcase .split (self .pathmod .sep )
214
+ self ._parts_normcase_cached = self ._str_normcase .split (self .parser .sep )
215
215
return self ._parts_normcase_cached
216
216
217
217
def __lt__ (self , other ):
218
- if not isinstance (other , PurePath ) or self .pathmod is not other .pathmod :
218
+ if not isinstance (other , PurePath ) or self .parser is not other .parser :
219
219
return NotImplemented
220
220
return self ._parts_normcase < other ._parts_normcase
221
221
222
222
def __le__ (self , other ):
223
- if not isinstance (other , PurePath ) or self .pathmod is not other .pathmod :
223
+ if not isinstance (other , PurePath ) or self .parser is not other .parser :
224
224
return NotImplemented
225
225
return self ._parts_normcase <= other ._parts_normcase
226
226
227
227
def __gt__ (self , other ):
228
- if not isinstance (other , PurePath ) or self .pathmod is not other .pathmod :
228
+ if not isinstance (other , PurePath ) or self .parser is not other .parser :
229
229
return NotImplemented
230
230
return self ._parts_normcase > other ._parts_normcase
231
231
232
232
def __ge__ (self , other ):
233
- if not isinstance (other , PurePath ) or self .pathmod is not other .pathmod :
233
+ if not isinstance (other , PurePath ) or self .parser is not other .parser :
234
234
return NotImplemented
235
235
return self ._parts_normcase >= other ._parts_normcase
236
236
@@ -247,10 +247,10 @@ def __str__(self):
247
247
@classmethod
248
248
def _format_parsed_parts (cls , drv , root , tail ):
249
249
if drv or root :
250
- return drv + root + cls .pathmod .sep .join (tail )
251
- elif tail and cls .pathmod .splitdrive (tail [0 ])[0 ]:
250
+ return drv + root + cls .parser .sep .join (tail )
251
+ elif tail and cls .parser .splitdrive (tail [0 ])[0 ]:
252
252
tail = ['.' ] + tail
253
- return cls .pathmod .sep .join (tail )
253
+ return cls .parser .sep .join (tail )
254
254
255
255
def _from_parsed_parts (self , drv , root , tail ):
256
256
path_str = self ._format_parsed_parts (drv , root , tail )
@@ -265,11 +265,11 @@ def _from_parsed_parts(self, drv, root, tail):
265
265
def _parse_path (cls , path ):
266
266
if not path :
267
267
return '' , '' , []
268
- sep = cls .pathmod .sep
269
- altsep = cls .pathmod .altsep
268
+ sep = cls .parser .sep
269
+ altsep = cls .parser .altsep
270
270
if altsep :
271
271
path = path .replace (altsep , sep )
272
- drv , root , rel = cls .pathmod .splitroot (path )
272
+ drv , root , rel = cls .parser .splitroot (path )
273
273
if not root and drv .startswith (sep ) and not drv .endswith (sep ):
274
274
drv_parts = drv .split (sep )
275
275
if len (drv_parts ) == 4 and drv_parts [2 ] not in '?.' :
@@ -290,7 +290,7 @@ def _raw_path(self):
290
290
elif len (paths ) == 1 :
291
291
path = paths [0 ]
292
292
else :
293
- path = self .pathmod .join (* paths )
293
+ path = self .parser .join (* paths )
294
294
return path
295
295
296
296
@property
@@ -360,8 +360,8 @@ def name(self):
360
360
361
361
def with_name (self , name ):
362
362
"""Return a new path with the file name changed."""
363
- m = self .pathmod
364
- if not name or m .sep in name or (m .altsep and m .altsep in name ) or name == '.' :
363
+ p = self .parser
364
+ if not name or p .sep in name or (p .altsep and p .altsep in name ) or name == '.' :
365
365
raise ValueError (f"Invalid name { name !r} " )
366
366
tail = self ._tail .copy ()
367
367
if not tail :
@@ -413,13 +413,13 @@ def is_relative_to(self, other, /, *_deprecated):
413
413
def is_absolute (self ):
414
414
"""True if the path is absolute (has both a root and, if applicable,
415
415
a drive)."""
416
- if self .pathmod is posixpath :
416
+ if self .parser is posixpath :
417
417
# Optimization: work with raw paths on POSIX.
418
418
for path in self ._raw_paths :
419
419
if path .startswith ('/' ):
420
420
return True
421
421
return False
422
- return self .pathmod .isabs (self )
422
+ return self .parser .isabs (self )
423
423
424
424
def is_reserved (self ):
425
425
"""Return True if the path contains one of the special names reserved
@@ -428,8 +428,8 @@ def is_reserved(self):
428
428
"for removal in Python 3.15. Use os.path.isreserved() to "
429
429
"detect reserved paths on Windows." )
430
430
warnings .warn (msg , DeprecationWarning , stacklevel = 2 )
431
- if self .pathmod is ntpath :
432
- return self .pathmod .isreserved (self )
431
+ if self .parser is ntpath :
432
+ return self .parser .isreserved (self )
433
433
return False
434
434
435
435
def as_uri (self ):
@@ -462,7 +462,7 @@ def _pattern_stack(self):
462
462
raise NotImplementedError ("Non-relative patterns are unsupported" )
463
463
elif not parts :
464
464
raise ValueError ("Unacceptable pattern: {!r}" .format (pattern ))
465
- elif pattern [- 1 ] in (self .pathmod .sep , self .pathmod .altsep ):
465
+ elif pattern [- 1 ] in (self .parser .sep , self .parser .altsep ):
466
466
# GH-65238: pathlib doesn't preserve trailing slash. Add it back.
467
467
parts .append ('' )
468
468
parts .reverse ()
@@ -487,7 +487,7 @@ class PurePosixPath(PurePath):
487
487
On a POSIX system, instantiating a PurePath should return this object.
488
488
However, you can also instantiate it directly on any system.
489
489
"""
490
- pathmod = posixpath
490
+ parser = posixpath
491
491
__slots__ = ()
492
492
493
493
@@ -497,7 +497,7 @@ class PureWindowsPath(PurePath):
497
497
On a Windows system, instantiating a PurePath should return this object.
498
498
However, you can also instantiate it directly on any system.
499
499
"""
500
- pathmod = ntpath
500
+ parser = ntpath
501
501
__slots__ = ()
502
502
503
503
@@ -607,7 +607,7 @@ def _make_child_relpath(self, name):
607
607
path_str = str (self )
608
608
tail = self ._tail
609
609
if tail :
610
- path_str = f'{ path_str } { self .pathmod .sep } { name } '
610
+ path_str = f'{ path_str } { self .parser .sep } { name } '
611
611
elif path_str != '.' :
612
612
path_str = f'{ path_str } { name } '
613
613
else :
@@ -675,7 +675,7 @@ def absolute(self):
675
675
drive , root , rel = os .path .splitroot (cwd )
676
676
if not rel :
677
677
return self ._from_parsed_parts (drive , root , self ._tail )
678
- tail = rel .split (self .pathmod .sep )
678
+ tail = rel .split (self .parser .sep )
679
679
tail .extend (self ._tail )
680
680
return self ._from_parsed_parts (drive , root , tail )
681
681
0 commit comments