Skip to content

Commit

Permalink
Fix invalid importing of importlib.reader in Python 3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus authored and bluetech committed Feb 7, 2022
1 parent 15ddccf commit 5f1a2f3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog/9608.bugfix.rst
@@ -0,0 +1 @@
Fix invalid importing of ``importlib.reader`` in Python 3.9.
7 changes: 3 additions & 4 deletions src/_pytest/assertion/rewrite.py
Expand Up @@ -44,6 +44,8 @@
if TYPE_CHECKING:
from _pytest.assertion import AssertionState

if sys.version_info >= (3, 10):
from importlib.readers import FileReader

assertstate_key = StashKey["AssertionState"]()

Expand Down Expand Up @@ -276,10 +278,7 @@ def get_data(self, pathname: Union[str, bytes]) -> bytes:
if sys.version_info >= (3, 10):

def get_resource_reader(self, name: str) -> importlib.abc.TraversableResources: # type: ignore
from types import SimpleNamespace
from importlib.readers import FileReader

return FileReader(SimpleNamespace(path=self._rewritten_names[name]))
return FileReader(types.SimpleNamespace(path=self._rewritten_names[name]))


def _write_pyc_fp(
Expand Down

0 comments on commit 5f1a2f3

Please sign in to comment.