Issue #19775: Add a samefile() method to pathlib Path objects.
Initial patch by Vajrasky Kok.
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 @@
"""
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 '..'.