Fix invalid importing of `importlib.reader` in Python 3.9

Fix #9608
This commit is contained in:
Bruno Oliveira 2022-02-04 18:50:48 -03:00 committed by Ran Benita
parent 15ddccf700
commit 5f1a2f33da
2 changed files with 4 additions and 4 deletions

View File

@ -0,0 +1 @@
Fix invalid importing of ``importlib.reader`` in Python 3.9.

View File

@ -44,6 +44,8 @@ from _pytest.stash import StashKey
if TYPE_CHECKING: if TYPE_CHECKING:
from _pytest.assertion import AssertionState from _pytest.assertion import AssertionState
if sys.version_info >= (3, 10):
from importlib.readers import FileReader
assertstate_key = StashKey["AssertionState"]() assertstate_key = StashKey["AssertionState"]()
@ -276,10 +278,7 @@ class AssertionRewritingHook(importlib.abc.MetaPathFinder, importlib.abc.Loader)
if sys.version_info >= (3, 10): if sys.version_info >= (3, 10):
def get_resource_reader(self, name: str) -> importlib.abc.TraversableResources: # type: ignore def get_resource_reader(self, name: str) -> importlib.abc.TraversableResources: # type: ignore
from types import SimpleNamespace return FileReader(types.SimpleNamespace(path=self._rewritten_names[name]))
from importlib.readers import FileReader
return FileReader(SimpleNamespace(path=self._rewritten_names[name]))
def _write_pyc_fp( def _write_pyc_fp(