move function specific imports to function
re: review from @asottile that this should only get imported in the function modify the else/if logic since inside the function we already know the python version is >= 3.10, and just have to know if it is 3.11 or greater
This commit is contained in:
parent
f86a87a315
commit
d45a19cfde
|
@ -43,11 +43,7 @@ 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, 11):
|
|
||||||
from importlib.resources.readers import FileReader
|
|
||||||
elif sys.version_info >= (3, 10):
|
|
||||||
from importlib.readers import FileReader
|
|
||||||
|
|
||||||
assertstate_key = StashKey["AssertionState"]()
|
assertstate_key = StashKey["AssertionState"]()
|
||||||
|
|
||||||
|
@ -280,6 +276,11 @@ 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
|
||||||
|
if sys.version_info < (3, 11):
|
||||||
|
from importlib.readers import FileReader
|
||||||
|
else:
|
||||||
|
from importlib.resources.readers import FileReader
|
||||||
|
|
||||||
return FileReader(types.SimpleNamespace(path=self._rewritten_names[name]))
|
return FileReader(types.SimpleNamespace(path=self._rewritten_names[name]))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue