Skip to content

Commit

Permalink
- fixed deprecation warning;
Browse files Browse the repository at this point in the history
  • Loading branch information
jaltmayerpizzorno committed Oct 26, 2024
1 parent a9f5869 commit 1ecd993
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/slipcover/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@
import sys
import sysconfig

from importlib.abc import MetaPathFinder, Loader, ResourceReader
from importlib.abc import MetaPathFinder, Loader
from importlib import machinery

if sys.version_info >= (3, 12):
from importlib.resources.abc import TraversableResources
elif sys.version_info >= (3, 11):
from importlib.resources.abc import ResourceReader as TraversableResources
else:
from importlib.abc import ResourceReader as TraversableResources


if sys.version_info[0:2] < (3,9):
# Path.is_relative_to is new in Python 3.9
Expand All @@ -29,8 +36,7 @@ def __init__(self, sci: Slipcover, orig_loader: Loader, origin: str):
delattr(self, "get_resource_reader")

# for compability with loaders supporting resources, used e.g. by sklearn
def get_resource_reader(self, fullname: str) -> Optional[ResourceReader]:
# FIXME deprecated in Python 3.12
def get_resource_reader(self, fullname: str) -> Optional[TraversableResources]:
if hasattr(self.orig_loader, 'get_resource_reader'):
return self.orig_loader.get_resource_reader(fullname)
return None
Expand Down
5 changes: 4 additions & 1 deletion tests/test_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,10 @@ def test_loader_supports_resources(tmp_path):
import imported
def test():
assert list(r.contents('imported')) != []
if sys.version_info >= (3, 12):
assert list(r.files('imported').iterdir()) != []
else:
assert list(r.contents('imported')) != []
""")

p = subprocess.run([sys.executable, "-m", "slipcover", "--silent", "-m", "pytest", "-qq", cmdfile])
Expand Down

0 comments on commit 1ecd993

Please sign in to comment.