Skip to content

Commit 170aca9

Browse files
authored
Fix ResourceReader ImportError exception on Python 3.14 (#299)
importlib.abc.ResourceReader moved to importlib.resources.abc.ResourceReader in Python 3.11. The old location was deprecated in 3.11 and removed in 3.14. TraversableResources is now the preferred API, but AIUI ResourceReader has no formal deprecation at the new location. I've chosen an if/else block because it is interpretted by MyPy, as opposed to try/except ImportError which MyPy cannot type check on Python <= 3.10.
1 parent 0c8b57e commit 170aca9

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ classifiers=[
3232
"Programming Language :: Python :: 3.11",
3333
"Programming Language :: Python :: 3.12",
3434
"Programming Language :: Python :: 3.13",
35+
"Programming Language :: Python :: 3.14",
3536
"Programming Language :: Python :: Implementation :: CPython",
3637
"Programming Language :: Python :: Implementation :: PyPy",
3738
"Programming Language :: Rust",

wasmtime/loader.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@
1414
import struct
1515
from pathlib import Path
1616
from importlib import import_module
17-
from importlib.abc import Loader, MetaPathFinder, ResourceReader
17+
from importlib.abc import Loader, MetaPathFinder
1818
from importlib.machinery import ModuleSpec
19+
if sys.version_info[:2] >= (3, 11):
20+
from importlib.resources.abc import ResourceReader
21+
else:
22+
from importlib.abc import ResourceReader
1923

2024
from wasmtime import Module, Linker, Store, WasiConfig
2125
from wasmtime import Func, Table, Global, Memory

0 commit comments

Comments
 (0)