Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix comparison when using greater than or equal in UP036 #7903

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like we need different tie-breaking logic here depending on whether it's a great-than comparison or a less-than comparison, because this condition seems correct (and the comment does too) for less-than.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this fix is incorrect — this is really hurting my brain haha

} 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
})
}
}
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
|
Expand Down Expand Up @@ -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')


Loading