@@ -697,26 +697,22 @@ def _parse_args(cls, args):
697
697
return cls ._flavour .parse_parts (parts )
698
698
699
699
@classmethod
700
- def _from_parts (cls , args , init = True ):
700
+ def _from_parts (cls , args ):
701
701
# We need to call _parse_args on the instance, so as to get the
702
702
# right flavour.
703
703
self = object .__new__ (cls )
704
704
drv , root , parts = self ._parse_args (args )
705
705
self ._drv = drv
706
706
self ._root = root
707
707
self ._parts = parts
708
- if init :
709
- self ._init ()
710
708
return self
711
709
712
710
@classmethod
713
- def _from_parsed_parts (cls , drv , root , parts , init = True ):
711
+ def _from_parsed_parts (cls , drv , root , parts ):
714
712
self = object .__new__ (cls )
715
713
self ._drv = drv
716
714
self ._root = root
717
715
self ._parts = parts
718
- if init :
719
- self ._init ()
720
716
return self
721
717
722
718
@classmethod
@@ -726,10 +722,6 @@ def _format_parsed_parts(cls, drv, root, parts):
726
722
else :
727
723
return cls ._flavour .join (parts )
728
724
729
- def _init (self ):
730
- # Overridden in concrete Path
731
- pass
732
-
733
725
def _make_child (self , args ):
734
726
drv , root , parts = self ._parse_args (args )
735
727
drv , root , parts = self ._flavour .join_parsed_parts (
@@ -1069,29 +1061,18 @@ class Path(PurePath):
1069
1061
object. You can also instantiate a PosixPath or WindowsPath directly,
1070
1062
but cannot instantiate a WindowsPath on a POSIX system or vice versa.
1071
1063
"""
1072
- __slots__ = (
1073
- '_accessor' ,
1074
- )
1064
+ _accessor = _normal_accessor
1065
+ __slots__ = ()
1075
1066
1076
1067
def __new__ (cls , * args , ** kwargs ):
1077
1068
if cls is Path :
1078
1069
cls = WindowsPath if os .name == 'nt' else PosixPath
1079
- self = cls ._from_parts (args , init = False )
1070
+ self = cls ._from_parts (args )
1080
1071
if not self ._flavour .is_supported :
1081
1072
raise NotImplementedError ("cannot instantiate %r on your system"
1082
1073
% (cls .__name__ ,))
1083
- self ._init ()
1084
1074
return self
1085
1075
1086
- def _init (self ,
1087
- # Private non-constructor arguments
1088
- template = None ,
1089
- ):
1090
- if template is not None :
1091
- self ._accessor = template ._accessor
1092
- else :
1093
- self ._accessor = _normal_accessor
1094
-
1095
1076
def _make_child_relpath (self , part ):
1096
1077
# This is an optimization used for dir walking. `part` must be
1097
1078
# a single part relative to this path.
@@ -1192,9 +1173,7 @@ def absolute(self):
1192
1173
return self
1193
1174
# FIXME this must defer to the specific flavour (and, under Windows,
1194
1175
# use nt._getfullpathname())
1195
- obj = self ._from_parts ([os .getcwd ()] + self ._parts , init = False )
1196
- obj ._init (template = self )
1197
- return obj
1176
+ return self ._from_parts ([os .getcwd ()] + self ._parts )
1198
1177
1199
1178
def resolve (self , strict = False ):
1200
1179
"""
@@ -1210,9 +1189,7 @@ def resolve(self, strict=False):
1210
1189
s = str (self .absolute ())
1211
1190
# Now we have no symlinks in the path, it's safe to normalize it.
1212
1191
normed = self ._flavour .pathmod .normpath (s )
1213
- obj = self ._from_parts ((normed ,), init = False )
1214
- obj ._init (template = self )
1215
- return obj
1192
+ return self ._from_parts ((normed ,))
1216
1193
1217
1194
def stat (self ):
1218
1195
"""
@@ -1284,9 +1261,7 @@ def readlink(self):
1284
1261
Return the path to which the symbolic link points.
1285
1262
"""
1286
1263
path = self ._accessor .readlink (self )
1287
- obj = self ._from_parts ((path ,), init = False )
1288
- obj ._init (template = self )
1289
- return obj
1264
+ return self ._from_parts ((path ,))
1290
1265
1291
1266
def touch (self , mode = 0o666 , exist_ok = True ):
1292
1267
"""
0 commit comments