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