Repository: jaraco/zipp

Issue:
is_file should return false unless that file exists
In `importlib.resources`, I've had to add special handling for zipp.Path.is_file returning true when the name looks valid but the file doesn't exist. By contrast, `pathlib.Path.is_file` returns False for paths that don't exist, even if they represent potentially vaild file references.

Discussion:

Patch:
diff --git a/CHANGES.rst b/CHANGES.rst
index 71dd074..b0b60e1 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -9,6 +9,8 @@ close the same file handle.
 #56 and bpo-41035: ``Path._next`` now honors
 subclasses.
 
+#55: ``Path.is_file()`` now returns False for non-existent names.
+
 v3.1.0
 ======
 
diff --git a/zipp.py b/zipp.py
index 7607be2..b1a7749 100644
--- a/zipp.py
+++ b/zipp.py
@@ -263,7 +263,7 @@ class Path:
         return not self.at or self.at.endswith("/")
 
     def is_file(self):
-        return not self.is_dir()
+        return self.exists() and not self.is_dir()
 
     def exists(self):
         return self.at in self.root._name_set()


Test patch:
diff --git a/test_zipp.py b/test_zipp.py
index b63590d..3f22bdb 100644
--- a/test_zipp.py
+++ b/test_zipp.py
@@ -107,6 +107,11 @@ class TestPath(unittest.TestCase):
             (i,) = h.iterdir()
             assert i.is_file()
 
+    def test_is_file_missing(self):
+        for alpharep in self.zipfile_alpharep():
+            root = zipp.Path(alpharep)
+            assert not root.joinpath('missing.txt').is_file()
+
     def test_iterdir_on_file(self):
         for alpharep in self.zipfile_alpharep():
             root = zipp.Path(alpharep)
@@ -175,7 +180,7 @@ class TestPath(unittest.TestCase):
     def test_joinpath(self):
         for alpharep in self.zipfile_alpharep():
             root = zipp.Path(alpharep)
-            a = root.joinpath("a")
+            a = root.joinpath("a.txt")
             assert a.is_file()
             e = root.joinpath("b").joinpath("d").joinpath("e.txt")
             assert e.read_text() == "content of e"
@@ -183,7 +188,7 @@ class TestPath(unittest.TestCase):
     def test_traverse_truediv(self):
         for alpharep in self.zipfile_alpharep():
             root = zipp.Path(alpharep)
-            a = root / "a"
+            a = root / "a.txt"
             assert a.is_file()
             e = root / "b" / "d" / "e.txt"
             assert e.read_text() == "content of e"