Avoid slicing `sys.version_info` in version conditionals

It is unnecessary, and some static analyzers don't handle it.
This commit is contained in:
Ran Benita 2024-04-27 01:11:21 +03:00
parent 93c2cdf6d6
commit 1a332802ff
7 changed files with 8 additions and 8 deletions

View File

@ -52,7 +52,7 @@ from _pytest.pathlib import absolutepath
from _pytest.pathlib import bestrelpath
if sys.version_info[:2] < (3, 11):
if sys.version_info < (3, 11):
from exceptiongroup import BaseExceptionGroup
_TracebackStyle = Literal["long", "short", "line", "no", "native", "value", "auto"]
@ -703,7 +703,7 @@ class ExceptionInfo(Generic[E]):
# Workaround for https://github.com/python/cpython/issues/98778 on
# Python <= 3.9, and some 3.10 and 3.11 patch versions.
HTTPError = getattr(sys.modules.get("urllib.error", None), "HTTPError", ())
if sys.version_info[:2] <= (3, 11) and isinstance(exc, HTTPError):
if sys.version_info < (3, 12) and isinstance(exc, HTTPError):
notes = []
else:
raise

View File

@ -448,7 +448,7 @@ class MyOptionParser(argparse.ArgumentParser):
getattr(parsed, FILE_OR_DIR).extend(unrecognized)
return parsed
if sys.version_info[:2] < (3, 9): # pragma: no cover
if sys.version_info < (3, 9): # pragma: no cover
# Backport of https://github.com/python/cpython/pull/14316 so we can
# disable long --argument abbreviations without breaking short flags.
def _parse_optional(

View File

@ -69,7 +69,7 @@ from _pytest.scope import HIGH_SCOPES
from _pytest.scope import Scope
if sys.version_info[:2] < (3, 11):
if sys.version_info < (3, 11):
from exceptiongroup import BaseExceptionGroup

View File

@ -39,7 +39,7 @@ from _pytest.outcomes import Skipped
from _pytest.outcomes import TEST_OUTCOME
if sys.version_info[:2] < (3, 11):
if sys.version_info < (3, 11):
from exceptiongroup import BaseExceptionGroup
if TYPE_CHECKING:

View File

@ -28,7 +28,7 @@ import pytest
if TYPE_CHECKING:
from _pytest._code.code import _TracebackStyle
if sys.version_info[:2] < (3, 11):
if sys.version_info < (3, 11):
from exceptiongroup import ExceptionGroup

View File

@ -23,7 +23,7 @@ from _pytest.pytester import Pytester
import pytest
if sys.version_info[:2] < (3, 11):
if sys.version_info < (3, 11):
from exceptiongroup import ExceptionGroup

View File

@ -1146,7 +1146,7 @@ def test_errors_in_xfail_skip_expressions(pytester: Pytester) -> None:
if pypy_version_info is not None and pypy_version_info < (6,):
markline = markline[1:]
if sys.version_info[:2] >= (3, 10):
if sys.version_info >= (3, 10):
expected = [
"*ERROR*test_nameerror*",
"*asd*",