Skip to content

Commit 3db5d9a

Browse files
authored
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
1 parent 5c0fcd0 commit 3db5d9a

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/_pytest/assertion/rewrite.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,7 @@
4343

4444
if TYPE_CHECKING:
4545
from _pytest.assertion import AssertionState
46-
47-
if sys.version_info >= (3, 11):
48-
from importlib.resources.readers import FileReader
49-
elif sys.version_info >= (3, 10):
50-
from importlib.readers import FileReader
46+
5147

5248
assertstate_key = StashKey["AssertionState"]()
5349

@@ -280,6 +276,11 @@ def get_data(self, pathname: Union[str, bytes]) -> bytes:
280276
if sys.version_info >= (3, 10):
281277

282278
def get_resource_reader(self, name: str) -> importlib.abc.TraversableResources: # type: ignore
279+
if sys.version_info < (3, 11):
280+
from importlib.readers import FileReader
281+
else:
282+
from importlib.resources.readers import FileReader
283+
283284
return FileReader(types.SimpleNamespace(path=self._rewritten_names[name]))
284285

285286

0 commit comments

Comments
 (0)