@@ -1041,7 +1041,6 @@ class Path(PurePath):
1041
1041
"""
1042
1042
__slots__ = (
1043
1043
'_accessor' ,
1044
- '_closed' ,
1045
1044
)
1046
1045
1047
1046
def __new__ (cls , * args , ** kwargs ):
@@ -1058,7 +1057,6 @@ def _init(self,
1058
1057
# Private non-constructor arguments
1059
1058
template = None ,
1060
1059
):
1061
- self ._closed = False
1062
1060
if template is not None :
1063
1061
self ._accessor = template ._accessor
1064
1062
else :
@@ -1071,15 +1069,18 @@ def _make_child_relpath(self, part):
1071
1069
return self ._from_parsed_parts (self ._drv , self ._root , parts )
1072
1070
1073
1071
def __enter__ (self ):
1074
- if self ._closed :
1075
- self ._raise_closed ()
1076
1072
return self
1077
1073
1078
1074
def __exit__ (self , t , v , tb ):
1079
- self ._closed = True
1080
-
1081
- def _raise_closed (self ):
1082
- raise ValueError ("I/O operation on closed path" )
1075
+ # https://bugs.python.org/issue39682
1076
+ # In previous versions of pathlib, this method marked this path as
1077
+ # closed; subsequent attempts to perform I/O would raise an IOError.
1078
+ # This functionality was never documented, and had the effect of
1079
+ # making Path objects mutable, contrary to PEP 428. In Python 3.9 the
1080
+ # _closed attribute was removed, and this method made a no-op.
1081
+ # This method and __enter__()/__exit__() should be deprecated and
1082
+ # removed in the future.
1083
+ pass
1083
1084
1084
1085
def _opener (self , name , flags , mode = 0o666 ):
1085
1086
# A stub for the opener argument to built-in open()
@@ -1090,8 +1091,6 @@ def _raw_open(self, flags, mode=0o777):
1090
1091
Open the file pointed by this path and return a file descriptor,
1091
1092
as os.open() does.
1092
1093
"""
1093
- if self ._closed :
1094
- self ._raise_closed ()
1095
1094
return self ._accessor .open (self , flags , mode )
1096
1095
1097
1096
# Public API
@@ -1125,15 +1124,11 @@ def iterdir(self):
1125
1124
"""Iterate over the files in this directory. Does not yield any
1126
1125
result for the special paths '.' and '..'.
1127
1126
"""
1128
- if self ._closed :
1129
- self ._raise_closed ()
1130
1127
for name in self ._accessor .listdir (self ):
1131
1128
if name in {'.' , '..' }:
1132
1129
# Yielding a path object for these makes little sense
1133
1130
continue
1134
1131
yield self ._make_child_relpath (name )
1135
- if self ._closed :
1136
- self ._raise_closed ()
1137
1132
1138
1133
def glob (self , pattern ):
1139
1134
"""Iterate over this subtree and yield all existing files (of any
@@ -1170,8 +1165,6 @@ def absolute(self):
1170
1165
Use resolve() to get the canonical path to a file.
1171
1166
"""
1172
1167
# XXX untested yet!
1173
- if self ._closed :
1174
- self ._raise_closed ()
1175
1168
if self .is_absolute ():
1176
1169
return self
1177
1170
# FIXME this must defer to the specific flavour (and, under Windows,
@@ -1186,8 +1179,6 @@ def resolve(self, strict=False):
1186
1179
normalizing it (for example turning slashes into backslashes under
1187
1180
Windows).
1188
1181
"""
1189
- if self ._closed :
1190
- self ._raise_closed ()
1191
1182
s = self ._flavour .resolve (self , strict = strict )
1192
1183
if s is None :
1193
1184
# No symlink resolution => for consistency, raise an error if
@@ -1227,8 +1218,6 @@ def open(self, mode='r', buffering=-1, encoding=None,
1227
1218
Open the file pointed by this path and return a file object, as
1228
1219
the built-in open() function does.
1229
1220
"""
1230
- if self ._closed :
1231
- self ._raise_closed ()
1232
1221
return io .open (self , mode , buffering , encoding , errors , newline ,
1233
1222
opener = self ._opener )
1234
1223
@@ -1278,8 +1267,6 @@ def touch(self, mode=0o666, exist_ok=True):
1278
1267
"""
1279
1268
Create this file with the given access mode, if it doesn't exist.
1280
1269
"""
1281
- if self ._closed :
1282
- self ._raise_closed ()
1283
1270
if exist_ok :
1284
1271
# First try to bump modification time
1285
1272
# Implementation note: GNU touch uses the UTIME_NOW option of
@@ -1301,8 +1288,6 @@ def mkdir(self, mode=0o777, parents=False, exist_ok=False):
1301
1288
"""
1302
1289
Create a new directory at this given path.
1303
1290
"""
1304
- if self ._closed :
1305
- self ._raise_closed ()
1306
1291
try :
1307
1292
self ._accessor .mkdir (self , mode )
1308
1293
except FileNotFoundError :
@@ -1320,26 +1305,20 @@ def chmod(self, mode):
1320
1305
"""
1321
1306
Change the permissions of the path, like os.chmod().
1322
1307
"""
1323
- if self ._closed :
1324
- self ._raise_closed ()
1325
1308
self ._accessor .chmod (self , mode )
1326
1309
1327
1310
def lchmod (self , mode ):
1328
1311
"""
1329
1312
Like chmod(), except if the path points to a symlink, the symlink's
1330
1313
permissions are changed, rather than its target's.
1331
1314
"""
1332
- if self ._closed :
1333
- self ._raise_closed ()
1334
1315
self ._accessor .lchmod (self , mode )
1335
1316
1336
1317
def unlink (self , missing_ok = False ):
1337
1318
"""
1338
1319
Remove this file or link.
1339
1320
If the path is a directory, use rmdir() instead.
1340
1321
"""
1341
- if self ._closed :
1342
- self ._raise_closed ()
1343
1322
try :
1344
1323
self ._accessor .unlink (self )
1345
1324
except FileNotFoundError :
@@ -1350,34 +1329,26 @@ def rmdir(self):
1350
1329
"""
1351
1330
Remove this directory. The directory must be empty.
1352
1331
"""
1353
- if self ._closed :
1354
- self ._raise_closed ()
1355
1332
self ._accessor .rmdir (self )
1356
1333
1357
1334
def lstat (self ):
1358
1335
"""
1359
1336
Like stat(), except if the path points to a symlink, the symlink's
1360
1337
status information is returned, rather than its target's.
1361
1338
"""
1362
- if self ._closed :
1363
- self ._raise_closed ()
1364
1339
return self ._accessor .lstat (self )
1365
1340
1366
1341
def link_to (self , target ):
1367
1342
"""
1368
1343
Create a hard link pointing to a path named target.
1369
1344
"""
1370
- if self ._closed :
1371
- self ._raise_closed ()
1372
1345
self ._accessor .link_to (self , target )
1373
1346
1374
1347
def rename (self , target ):
1375
1348
"""
1376
1349
Rename this path to the given path,
1377
1350
and return a new Path instance pointing to the given path.
1378
1351
"""
1379
- if self ._closed :
1380
- self ._raise_closed ()
1381
1352
self ._accessor .rename (self , target )
1382
1353
return self .__class__ (target )
1383
1354
@@ -1387,8 +1358,6 @@ def replace(self, target):
1387
1358
destination if it exists, and return a new Path instance
1388
1359
pointing to the given path.
1389
1360
"""
1390
- if self ._closed :
1391
- self ._raise_closed ()
1392
1361
self ._accessor .replace (self , target )
1393
1362
return self .__class__ (target )
1394
1363
@@ -1397,8 +1366,6 @@ def symlink_to(self, target, target_is_directory=False):
1397
1366
Make this path a symlink pointing to the given path.
1398
1367
Note the order of arguments (self, target) is the reverse of os.symlink's.
1399
1368
"""
1400
- if self ._closed :
1401
- self ._raise_closed ()
1402
1369
self ._accessor .symlink (target , self , target_is_directory )
1403
1370
1404
1371
# Convenience functions for querying the stat results
0 commit comments