-
Notifications
You must be signed in to change notification settings - Fork 2k
UP036 should identify sys.version_info[0] or other parts #12993
Copy link
Copy link
Closed
Labels
ruleImplementing or modifying a lint ruleImplementing or modifying a lint rule
Description
I found there was some leftover py2k code in a project that UP rules would not catch because it just matches sys.version_info as a tuple. If you just check for the 1st element, which is kinda common in the old days, it will not show an error.
import sys
if sys.version_info[0] < 3:
print('old')
if sys.version_info < (3, 0):
print('also old')
UP036
$ ruff check --isolated --select UP036 foo.py
foo.py:6:4: UP036 Version block is outdated for minimum Python version
|
4 | print('old')
5 |
6 | if sys.version_info < (3, 0):
| ^^^^^^^^^^^^^^^^^^^^^^^^^ UP036
7 | print('also old')
|
= help: Remove outdated version block
Found 1 error.
No fixes available (1 hidden fix can be enabled with the `--unsafe-fixes` option).
It would be helpful if both options were found. I believe this is only relevant for python 2 since python 4 is no longer going to exist, but python 3 will be the forever version with the 2nd number being the de facto python version.
If so, this rule could also catch these cases.
if sys.version_info[1] < 12: ...
In time: Ruff 0.6.1
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
ruleImplementing or modifying a lint ruleImplementing or modifying a lint rule