Skip to content
Prev Previous commit
Next Next commit
Merge branch 'main' into bpo-24132-add-pathlib-abstractpath
  • Loading branch information
barneygale committed Feb 14, 2022
commit 21e0ece6810520a0b8e7ebaa9b10707455c23bbf
20 changes: 11 additions & 9 deletions Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,6 @@ class _AbstractPath(PurePath, ABC):
"""
__slots__ = ()


def samefile(self, other_path):
"""Return whether other_path is the same or not as this file
(as returned by os.path.samefile()).
Expand Down Expand Up @@ -1145,17 +1144,20 @@ def __new__(cls, *args, **kwargs):
return self

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
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.