@@ -335,7 +335,7 @@ def __new__(cls, *args):
335
335
def __reduce__ (self ):
336
336
# Using the parts tuple helps share interned path parts
337
337
# when pickling related paths.
338
- return (self . __class__ , tuple (self ._parts ))
338
+ return (type ( self ) , tuple (self ._parts ))
339
339
340
340
@classmethod
341
341
def _parse_args (cls , args ):
@@ -398,10 +398,8 @@ def _parse_parts(cls, parts):
398
398
399
399
@classmethod
400
400
def _from_parts (cls , args ):
401
- # We need to call _parse_args on the instance, so as to get the
402
- # right flavour.
401
+ drv , root , parts = cls ._parse_args (args )
403
402
self = object .__new__ (cls )
404
- drv , root , parts = self ._parse_args (args )
405
403
self ._drv = drv
406
404
self ._root = root
407
405
self ._parts = parts
@@ -428,7 +426,8 @@ def _make_child(self, args):
428
426
self ._drv , self ._root , self ._parts , drv , root , parts )
429
427
return self ._from_parsed_parts (drv , root , parts )
430
428
431
- def _join_parsed_parts (self , drv , root , parts , drv2 , root2 , parts2 ):
429
+ @classmethod
430
+ def _join_parsed_parts (cls , drv , root , parts , drv2 , root2 , parts2 ):
432
431
"""
433
432
Join the two paths represented by the respective
434
433
(drive, root, parts) tuples. Return a new (drive, root, parts) tuple.
@@ -437,7 +436,7 @@ def _join_parsed_parts(self, drv, root, parts, drv2, root2, parts2):
437
436
if not drv2 and drv :
438
437
return drv , root2 , [drv + root2 ] + parts2 [1 :]
439
438
elif drv2 :
440
- if drv2 == drv or self ._casefold (drv2 ) == self ._casefold (drv ):
439
+ if drv2 == drv or cls ._casefold (drv2 ) == cls ._casefold (drv ):
441
440
# Same drive => second path is relative to the first
442
441
return drv , root , parts + parts2 [1 :]
443
442
else :
@@ -481,7 +480,7 @@ def __bytes__(self):
481
480
return os .fsencode (self )
482
481
483
482
def __repr__ (self ):
484
- return "{}({!r})" .format (self . __class__ .__name__ , self .as_posix ())
483
+ return "{}({!r})" .format (type ( self ) .__name__ , self .as_posix ())
485
484
486
485
def as_uri (self ):
487
486
"""Return the path as a 'file' URI."""
@@ -1114,7 +1113,7 @@ def write_text(self, data, encoding=None, errors=None, newline=None):
1114
1113
"""
1115
1114
if not isinstance (data , str ):
1116
1115
raise TypeError ('data must be str, not %s' %
1117
- data . __class__ .__name__ )
1116
+ type ( data ) .__name__ )
1118
1117
encoding = io .text_encoding (encoding )
1119
1118
with self .open (mode = 'w' , encoding = encoding , errors = errors , newline = newline ) as f :
1120
1119
return f .write (data )
@@ -1197,7 +1196,7 @@ def rename(self, target):
1197
1196
Returns the new Path instance pointing to the target path.
1198
1197
"""
1199
1198
self ._accessor .rename (self , target )
1200
- return self .__class__ ( target )
1199
+ return self ._from_parts (( target ,) )
1201
1200
1202
1201
def replace (self , target ):
1203
1202
"""
@@ -1210,7 +1209,7 @@ def replace(self, target):
1210
1209
Returns the new Path instance pointing to the target path.
1211
1210
"""
1212
1211
self ._accessor .replace (self , target )
1213
- return self .__class__ ( target )
1212
+ return self ._from_parts (( target ,) )
1214
1213
1215
1214
def symlink_to (self , target , target_is_directory = False ):
1216
1215
"""
0 commit comments