Skip to content

Commit afe14c3

Browse files
committed
Merge branch 'issue44' into 'master'
Fix `contents()` so that it no longer returns unrelated items Closes python#44 See merge request python-devs/importlib_resources!48
2 parents a4ad4ce + 0c2c942 commit afe14c3

27 files changed

Lines changed: 103 additions & 68 deletions

importlib_resources/_py2.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ def contents(package):
255255
# However, since directories themselves don't appear in the zip
256256
# archive as a separate entry, we need to return the first path
257257
# component for any case that has > 1 subparts -- but only once!
258+
if path.parts[:len(relpath.parts)] != relpath.parts:
259+
continue
258260
subparts = path.parts[len(relpath.parts):]
259261
if len(subparts) == 1:
260262
yield subparts[0]

importlib_resources/_py3.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ def contents(package: Package) -> Iterator[str]:
281281
# However, since directories themselves don't appear in the zip
282282
# archive as a separate entry, we need to return the first path
283283
# component for any case that has > 1 subparts -- but only once!
284+
if path.parts[:len(relpath.parts)] != relpath.parts:
285+
continue
284286
subparts = path.parts[len(relpath.parts):]
285287
if len(subparts) == 1:
286288
yield subparts[0]

importlib_resources/docs/changelog.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44

55
0.2 (201X-XX-XX)
66
================
7-
* Split the ``open()`` and ``read()`` calls into separate binary and text
8-
versions, i.e. ``open_binary()``, ``open_text()``, ``read_binary()``, and
9-
``read_text()``. Closes #41
7+
* **Backward incompatible change**. Split the ``open()`` and ``read()`` calls
8+
into separate binary and text versions, i.e. ``open_binary()``,
9+
``open_text()``, ``read_binary()``, and ``read_text()``. Closes #41
10+
* Fix a bug where unrelated resources could be returned from ``contents()``.
11+
Closes #44
12+
1013

1114
0.1 (2017-12-05)
1215
================
File renamed without changes.
File renamed without changes.

importlib_resources/tests/data/subdirectory/__init__.py renamed to importlib_resources/tests/data01/subdirectory/__init__.py

File renamed without changes.

importlib_resources/tests/data/subdirectory/binary.file renamed to importlib_resources/tests/data01/subdirectory/binary.file

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)