Skip to content

Commit

Permalink
When constructing ZipReader, only append the name if the indicated mo…
Browse files Browse the repository at this point in the history
…dule is a package.

Fixes python/cpython#121735.
  • Loading branch information
jaraco committed Aug 14, 2024
1 parent 8ba5553 commit 23afc90
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
6 changes: 4 additions & 2 deletions importlib_resources/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ def files(self):

class ZipReader(abc.TraversableResources):
def __init__(self, loader, module):
_, _, name = module.rpartition('.')
self.prefix = loader.prefix.replace('\\', '/') + name + '/'
self.prefix = loader.prefix.replace('\\', '/')
if loader.is_package(module):
_, _, name = module.rpartition('.')
self.prefix += name + '/'
self.archive = loader.archive

def open_resource(self, resource):
Expand Down
4 changes: 0 additions & 4 deletions importlib_resources/tests/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import importlib
import contextlib

import pytest

import importlib_resources as resources
from ..abc import Traversable
from . import util
Expand Down Expand Up @@ -93,7 +91,6 @@ class ModuleFilesDiskTests(DirectSpec, util.DiskSetup, ModulesFiles, unittest.Te
pass


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

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

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

0 comments on commit 23afc90

Please sign in to comment.