Skip to content

Commit

Permalink
When blocking stdlib readers, avoid giving deference to degenerate re…
Browse files Browse the repository at this point in the history
…aders and instead prefer the standard readers before once again falling back to any CompatibilityFiles reader. Closes #298.
  • Loading branch information
jaraco committed Mar 19, 2024
1 parent 705a435 commit 0c3f294
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion importlib_resources/future/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ def wrapper(*args, **kwargs):
return wrapper


def _skip_degenerate(reader):
"""
Mask any degenerate reader.
"""
is_degenerate = (
isinstance(reader, _adapters.CompatibilityFiles) and not reader._reader
)
return reader if not is_degenerate else None


class TraversableResourcesLoader(_adapters.TraversableResourcesLoader):
"""
Adapt loaders to provide TraversableResources and other
Expand All @@ -51,8 +61,9 @@ class TraversableResourcesLoader(_adapters.TraversableResourcesLoader):

def get_resource_reader(self, name):
return (
_block_standard(super().get_resource_reader)(name)
_skip_degenerate(_block_standard(super().get_resource_reader)(name))
or self._standard_reader()
or super().get_resource_reader(name)
)

def _standard_reader(self):
Expand Down

0 comments on commit 0c3f294

Please sign in to comment.