summaryrefslogtreecommitdiffstats
path: root/Lib/pathlib.py
diff options
context:
space:
mode:
authorBarney Gale <barney.gale@gmail.com>2023-05-23 22:31:59 (GMT)
committerGitHub <noreply@github.com>2023-05-23 22:31:59 (GMT)
commit6b1510cf11c16c8e4381810c15ceeda6f89e79f4 (patch)
tree12b9d8063d5c285204780980e9391bd23285f755 /Lib/pathlib.py
parente0b3078705b271ff278dfbc788c2b061c92a9aa3 (diff)
downloadcpython-6b1510cf11c16c8e4381810c15ceeda6f89e79f4.zip
cpython-6b1510cf11c16c8e4381810c15ceeda6f89e79f4.tar.gz
cpython-6b1510cf11c16c8e4381810c15ceeda6f89e79f4.tar.bz2
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.
Diffstat (limited to 'Lib/pathlib.py')
-rw-r--r--Lib/pathlib.py19
1 files changed, 0 insertions, 19 deletions
diff --git a/Lib/pathlib.py b/Lib/pathlib.py
index 3d68c16..3a7a124 100644
--- a/Lib/pathlib.py
+++ b/Lib/pathlib.py
@@ -1080,25 +1080,6 @@ class Path(PurePath):
cls = WindowsPath if os.name == 'nt' else PosixPath
return object.__new__(cls)
- def __enter__(self):
- # In previous versions of pathlib, __exit__() marked this path as
- # closed; 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 __exit__() was made a no-op.
- # In Python 3.11 __enter__() began emitting DeprecationWarning.
- # In Python 3.13 __enter__() and __exit__() should be removed.
- warnings.warn("pathlib.Path.__enter__() is deprecated and scheduled "
- "for removal in Python 3.13; Path objects as a context "
- "manager is a no-op",
- DeprecationWarning, stacklevel=2)
- return self
-
- def __exit__(self, t, v, tb):
- pass
-
- # Public API
-
@classmethod
def cwd(cls):
"""Return a new path pointing to the current working directory."""