summaryrefslogtreecommitdiffstats
path: root/Lib/pathlib.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2014-05-13 08:50:15 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2014-05-13 08:50:15 (GMT)
commit43e3d9409de92808b2ef5974b6a9f13eda57033f (patch)
tree1f8d1a1d379fdd3a0c76b5eae57a215df59e2854 /Lib/pathlib.py
parent38acd4c028f72a80079c27d68c8da2efd059a38d (diff)
downloadcpython-43e3d9409de92808b2ef5974b6a9f13eda57033f.zip
cpython-43e3d9409de92808b2ef5974b6a9f13eda57033f.tar.gz
cpython-43e3d9409de92808b2ef5974b6a9f13eda57033f.tar.bz2
Issue #19775: Add a samefile() method to pathlib Path objects.
Initial patch by Vajrasky Kok.
Diffstat (limited to 'Lib/pathlib.py')
-rw-r--r--Lib/pathlib.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/pathlib.py b/Lib/pathlib.py
index d3d1af8..03c5e6e 100644
--- a/Lib/pathlib.py
+++ b/Lib/pathlib.py
@@ -961,6 +961,17 @@ class Path(PurePath):
"""
return cls(os.getcwd())
+ def samefile(self, other_path):
+ """Return whether `other_file` is the same or not as this file.
+ (as returned by os.path.samefile(file, other_file)).
+ """
+ st = self.stat()
+ try:
+ other_st = other_path.stat()
+ except AttributeError:
+ other_st = os.stat(other_path)
+ return os.path.samestat(st, other_st)
+
def iterdir(self):
"""Iterate over the files in this directory. Does not yield any
result for the special paths '.' and '..'.