Skip to content

Commit 23afc90

Browse files
committed
When constructing ZipReader, only append the name if the indicated module is a package.
Fixes python/cpython#121735.
1 parent 8ba5553 commit 23afc90

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

importlib_resources/readers.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ def files(self):
3434

3535
class ZipReader(abc.TraversableResources):
3636
def __init__(self, loader, module):
37-
_, _, name = module.rpartition('.')
38-
self.prefix = loader.prefix.replace('\\', '/') + name + '/'
37+
self.prefix = loader.prefix.replace('\\', '/')
38+
if loader.is_package(module):
39+
_, _, name = module.rpartition('.')
40+
self.prefix += name + '/'
3941
self.archive = loader.archive
4042

4143
def open_resource(self, resource):

importlib_resources/tests/test_files.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import importlib
55
import contextlib
66

7-
import pytest
8-
97
import importlib_resources as resources
108
from ..abc import Traversable
119
from . import util
@@ -93,7 +91,6 @@ class ModuleFilesDiskTests(DirectSpec, util.DiskSetup, ModulesFiles, unittest.Te
9391
pass
9492

9593

96-
@pytest.mark.xfail(reason="python/cpython#121735")
9794
class ModuleFilesZipTests(DirectSpec, util.ZipSetup, ModulesFiles, unittest.TestCase):
9895
pass
9996

@@ -119,7 +116,6 @@ def test_implicit_files_package(self):
119116
"""
120117
assert importlib.import_module('somepkg').val == 'resources are the best'
121118

122-
@pytest.mark.xfail(reason="python/cpython#121735")
123119
def test_implicit_files_submodule(self):
124120
"""
125121
Without any parameter, files() will infer the location as the caller.

0 commit comments

Comments
 (0)