diff options
author | Barney Gale <barney.gale@gmail.com> | 2022-02-08 21:01:37 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-08 21:01:37 (GMT) |
commit | 06e1701ad3956352bc0f42b8f51c2f8cc85bf378 (patch) | |
tree | 3d6177468f6e1cc7ce4fe9df0e7985a0d6bc77b7 /Lib/pathlib.py | |
parent | 81c72044a181dbbfbf689d7a977d0d99090f26a8 (diff) | |
download | cpython-06e1701ad3956352bc0f42b8f51c2f8cc85bf378.zip cpython-06e1701ad3956352bc0f42b8f51c2f8cc85bf378.tar.gz cpython-06e1701ad3956352bc0f42b8f51c2f8cc85bf378.tar.bz2 |
bpo-46556: emit `DeprecationWarning` from `pathlib.Path.__enter__()` (GH-30971)
In Python 3.9, Path.__exit__() was made a no-op and has never been documented.
Co-authored-by: Brett Cannon <brett@python.org>
Diffstat (limited to 'Lib/pathlib.py')
-rw-r--r-- | Lib/pathlib.py | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/Lib/pathlib.py b/Lib/pathlib.py index 7f4210e..4763ab5 100644 --- a/Lib/pathlib.py +++ b/Lib/pathlib.py @@ -877,17 +877,20 @@ class Path(PurePath): return self._from_parsed_parts(self._drv, self._root, parts) 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): - # https://bugs.python.org/issue39682 - # In previous versions of pathlib, this method 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 the - # _closed attribute was removed, and this method made a no-op. - # This method and __enter__()/__exit__() should be deprecated and - # removed in the future. pass # Public API |