mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
GH-83863: Drop support for using pathlib.Path
objects as context managers (GH-104807)
In Python 3.8 and prior, `pathlib.Path.__exit__()` marked a path as closed; some subsequent attempts to perform I/O would raise an IOError. This functionality was never documented, and had the effect of making `Path` objects mutable, contrary to PEP 428. In Python 3.9 we made `__exit__()` a no-op, and in 3.11 `__enter__()` began raising deprecation warnings. Here we remove both methods.
This commit is contained in:
parent
e0b3078705
commit
6b1510cf11
4 changed files with 7 additions and 39 deletions
|
@ -2080,26 +2080,6 @@ class _BasePathTest(object):
|
|||
finally:
|
||||
os.chdir(old_cwd)
|
||||
|
||||
def test_with(self):
|
||||
p = self.cls(BASE)
|
||||
it = p.iterdir()
|
||||
it2 = p.iterdir()
|
||||
next(it2)
|
||||
# bpo-46556: path context managers are deprecated in Python 3.11.
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
with p:
|
||||
pass
|
||||
# Using a path as a context manager is a no-op, thus the following
|
||||
# operations should still succeed after the context manage exits.
|
||||
next(it)
|
||||
next(it2)
|
||||
p.exists()
|
||||
p.resolve()
|
||||
p.absolute()
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
with p:
|
||||
pass
|
||||
|
||||
@os_helper.skip_unless_working_chmod
|
||||
def test_chmod(self):
|
||||
p = self.cls(BASE) / 'fileA'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue