diff --git a/crates/ruff_linter/resources/test/fixtures/pyupgrade/UP036_0.py b/crates/ruff_linter/resources/test/fixtures/pyupgrade/UP036_0.py index 2cbdaf83359b4..0850214de7fb5 100644 --- a/crates/ruff_linter/resources/test/fixtures/pyupgrade/UP036_0.py +++ b/crates/ruff_linter/resources/test/fixtures/pyupgrade/UP036_0.py @@ -196,3 +196,9 @@ def g(): if sys.version_info <= (3,10000000): print("py3") + +if sys.version_info > (3, 12): + print('py3') + +if sys.version_info >= (3, 12): + print('py3') diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/outdated_version_block.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/outdated_version_block.rs index 07cb766e119a8..8f2ffc2da5c03 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/outdated_version_block.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/outdated_version_block.rs @@ -256,11 +256,11 @@ fn compare_version( Ok(if or_equal { // Ex) `sys.version_info <= 3.8`. If Python 3.8 is the minimum supported version, // the condition won't always evaluate to `false`, so we want to return `false`. - if_minor < py_minor + if_minor <= py_minor } else { // Ex) `sys.version_info < 3.8`. If Python 3.8 is the minimum supported version, // the condition _will_ always evaluate to `false`, so we want to return `true`. - if_minor <= py_minor + if_minor < py_minor }) } } @@ -464,9 +464,10 @@ mod tests { #[test_case(PythonVersion::Py37, & [3, 0], true, true; "compare-3.0-whole")] #[test_case(PythonVersion::Py37, & [3, 1], true, true; "compare-3.1")] #[test_case(PythonVersion::Py37, & [3, 5], true, true; "compare-3.5")] - #[test_case(PythonVersion::Py37, & [3, 7], true, false; "compare-3.7")] - #[test_case(PythonVersion::Py37, & [3, 7], false, true; "compare-3.7-not-equal")] - #[test_case(PythonVersion::Py37, & [3, 8], false, false; "compare-3.8")] + #[test_case(PythonVersion::Py37, & [3, 7], true, true; "compare-3.7")] + #[test_case(PythonVersion::Py37, & [3, 7], false, false; "compare-3.7-not-equal")] + #[test_case(PythonVersion::Py37, & [3, 8], true, false; "compare-3.8")] + #[test_case(PythonVersion::Py37, & [3, 8], false, false; "compare-3.8-not-equal")] #[test_case(PythonVersion::Py310, & [3, 9], true, true; "compare-3.9")] #[test_case(PythonVersion::Py310, & [3, 11], true, false; "compare-3.11")] fn test_compare_version( diff --git a/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP036_0.py.snap b/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP036_0.py.snap index 6d66d23ef17be..12151666f52df 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP036_0.py.snap +++ b/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP036_0.py.snap @@ -665,25 +665,45 @@ UP036_0.py:179:8: UP036 [*] Version block is outdated for minimum Python version 181 180 | 182 181 | if sys.version_info < (3,12): -UP036_0.py:182:4: UP036 [*] Version block is outdated for minimum Python version +UP036_0.py:185:4: UP036 [*] Version block is outdated for minimum Python version | -180 | expected_error = [] -181 | -182 | if sys.version_info < (3,12): - | ^^^^^^^^^^^^^^^^^^^^^^^^^ UP036 183 | print("py3") +184 | +185 | if sys.version_info <= (3,12): + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ UP036 +186 | print("py3") | = help: Remove outdated version block ℹ Suggested fix -179 179 | if sys.version_info > (3, 0): \ -180 180 | expected_error = [] -181 181 | -182 |-if sys.version_info < (3,12): -183 |- print("py3") -184 182 | -185 183 | if sys.version_info <= (3,12): -186 184 | print("py3") +182 182 | if sys.version_info < (3,12): +183 183 | print("py3") +184 184 | +185 |-if sys.version_info <= (3,12): +186 |- print("py3") +187 185 | +188 186 | if sys.version_info <= (3,12): +189 187 | print("py3") + +UP036_0.py:188:4: UP036 [*] Version block is outdated for minimum Python version + | +186 | print("py3") +187 | +188 | if sys.version_info <= (3,12): + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ UP036 +189 | print("py3") + | + = help: Remove outdated version block + +ℹ Suggested fix +185 185 | if sys.version_info <= (3,12): +186 186 | print("py3") +187 187 | +188 |-if sys.version_info <= (3,12): +189 |- print("py3") +190 188 | +191 189 | if sys.version_info == 10000000: +192 190 | print("py3") UP036_0.py:191:24: UP036 Version specifier is invalid | @@ -712,4 +732,22 @@ UP036_0.py:197:24: UP036 Version specifier is invalid 198 | print("py3") | +UP036_0.py:203:4: UP036 [*] Version block is outdated for minimum Python version + | +201 | print('py3') +202 | +203 | if sys.version_info >= (3, 12): + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP036 +204 | print('py3') + | + = help: Remove outdated version block + +ℹ Suggested fix +200 200 | if sys.version_info > (3, 12): +201 201 | print('py3') +202 202 | +203 |-if sys.version_info >= (3, 12): +204 |- print('py3') + 203 |+print('py3') +