Skip to content

Commit da7a4aa

Browse files
authored
Merge pull request #60 from jaraco/bugfix/55-isfile-missing
is_file returns False for non-existent files
2 parents 20ef7dd + e495001 commit da7a4aa

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

CHANGES.rst

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ close the same file handle.
99
#56 and bpo-41035: ``Path._next`` now honors
1010
subclasses.
1111

12+
#55: ``Path.is_file()`` now returns False for non-existent names.
13+
1214
v3.1.0
1315
======
1416

test_zipp.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ def test_iterdir_and_types(self):
107107
(i,) = h.iterdir()
108108
assert i.is_file()
109109

110+
def test_is_file_missing(self):
111+
for alpharep in self.zipfile_alpharep():
112+
root = zipp.Path(alpharep)
113+
assert not root.joinpath('missing.txt').is_file()
114+
110115
def test_iterdir_on_file(self):
111116
for alpharep in self.zipfile_alpharep():
112117
root = zipp.Path(alpharep)
@@ -175,15 +180,15 @@ def test_read(self):
175180
def test_joinpath(self):
176181
for alpharep in self.zipfile_alpharep():
177182
root = zipp.Path(alpharep)
178-
a = root.joinpath("a")
183+
a = root.joinpath("a.txt")
179184
assert a.is_file()
180185
e = root.joinpath("b").joinpath("d").joinpath("e.txt")
181186
assert e.read_text() == "content of e"
182187

183188
def test_traverse_truediv(self):
184189
for alpharep in self.zipfile_alpharep():
185190
root = zipp.Path(alpharep)
186-
a = root / "a"
191+
a = root / "a.txt"
187192
assert a.is_file()
188193
e = root / "b" / "d" / "e.txt"
189194
assert e.read_text() == "content of e"

zipp.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def is_dir(self):
263263
return not self.at or self.at.endswith("/")
264264

265265
def is_file(self):
266-
return not self.is_dir()
266+
return self.exists() and not self.is_dir()
267267

268268
def exists(self):
269269
return self.at in self.root._name_set()

0 commit comments

Comments
 (0)