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

[pyupgrade]: Remove outdated sys.version_info blocks #2099

Merged
merged 62 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
5ed3521
Began basic exploration
colin99d Jan 23, 2023
2da82a8
About to start actually changing code
colin99d Jan 23, 2023
7e54969
Progressed a small amount
colin99d Jan 23, 2023
27a96a9
Progressed a small amount
colin99d Jan 23, 2023
ebd80ba
In progress on 2x code blocks
colin99d Jan 24, 2023
7875822
Added some unit tests
colin99d Jan 25, 2023
19f3331
Running into a blocker
colin99d Jan 25, 2023
8914c4a
Merge branch 'main' into OldCodeBlocks
colin99d Jan 25, 2023
6cfc493
Merge branch 'main' into OldCodeBlocks
colin99d Jan 26, 2023
53b5e67
Fixed issues from merge
colin99d Jan 26, 2023
7a6a190
Fixed issues from merge
colin99d Jan 26, 2023
831130e
Got the sixes working
colin99d Jan 26, 2023
f209021
Added more tests
colin99d Jan 27, 2023
16c52de
Reformated to new standard
colin99d Jan 27, 2023
7e23673
GOT PYTHON 2 BLOCK WORKING, Progressed on python 3 block
colin99d Jan 27, 2023
7f9a4c3
Merge branch 'main' into OldCodeBlocks
colin99d Jan 27, 2023
424aa48
Made check_tokens way more efficient
colin99d Jan 27, 2023
18d3971
Complete the py3_elif handler
colin99d Jan 27, 2023
e8face2
Going to try only one python3 function
colin99d Jan 28, 2023
6ac2f88
Got all clippy stuff fixed
colin99d Jan 28, 2023
ceedf67
Added some tests
colin99d Jan 28, 2023
595cea4
Used libcst to make fixes more accurate
colin99d Jan 28, 2023
e0f15d6
Got some work done
colin99d Jan 29, 2023
c558290
Got some work done
colin99d Jan 29, 2023
5cacd1b
Fixed a bug, simplified code
colin99d Jan 29, 2023
f9a1404
Added more test cases
colin99d Jan 29, 2023
76e0316
Added more test cases
colin99d Jan 29, 2023
d8b9481
Made progress
colin99d Jan 29, 2023
c60dc5d
Added handling for another set of edge cases
colin99d Jan 29, 2023
f106787
Refactored tests
colin99d Jan 29, 2023
6540247
Handled another edge case
colin99d Jan 29, 2023
0092cd0
Added more test cases
colin99d Jan 29, 2023
c9a5464
Added more test cases
colin99d Jan 29, 2023
2b3da27
Added second set of tests
colin99d Jan 29, 2023
2746abb
Added second set of tests
colin99d Jan 29, 2023
98a0dac
Finished set three of tests
colin99d Jan 29, 2023
294bf72
Paddded the tests
colin99d Jan 29, 2023
f153fde
Added some negative tests
colin99d Jan 29, 2023
f5e874e
added fixes
colin99d Jan 29, 2023
dd42e58
Added some more complex tests
colin99d Jan 29, 2023
3ffbbae
Added fixes
colin99d Jan 29, 2023
64ea0c8
Merge branch 'main' into OldCodeBlocks
colin99d Jan 29, 2023
3e69b22
Added fixes
colin99d Jan 30, 2023
65678a6
Fixed tests
colin99d Jan 30, 2023
bff6fdd
Fixed clippy
colin99d Jan 30, 2023
d67a232
Merge branch 'main' into OldCodeBlocks
charliermarsh Jan 31, 2023
699364d
Recode to UP036
charliermarsh Jan 31, 2023
a4f82b9
Fixed tests
colin99d Feb 1, 2023
d7c89ed
Merge branch 'OldCodeBlocks' of https://github.com/colin99d/ruff into…
colin99d Feb 1, 2023
a3bea47
Merge branch 'main' into OldCodeBlocks
charliermarsh Feb 1, 2023
2610c02
Refactor
charliermarsh Feb 1, 2023
f2139ab
Handle another case
charliermarsh Feb 1, 2023
3bb9c62
deletions
charliermarsh Feb 1, 2023
c2b4dd8
Merge branch 'main' into OldCodeBlocks
charliermarsh Feb 1, 2023
a5c1446
Try display
charliermarsh Feb 1, 2023
a085e63
Handle body
charliermarsh Feb 1, 2023
fc2fe3f
Use to_string_lossy again
charliermarsh Feb 1, 2023
7a7be91
Fix dedentation
charliermarsh Feb 1, 2023
8b868e3
Merge branch 'main' into OldCodeBlocks
charliermarsh Feb 1, 2023
705b1a1
Handle inline
charliermarsh Feb 1, 2023
6a93690
Try downgrading insta
charliermarsh Feb 1, 2023
a977576
Bump insta
charliermarsh Feb 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -77,7 +77,7 @@ wasm-bindgen = { version = "0.2.83" }
is_executable = "1.0.1"

[dev-dependencies]
insta = { version = "1.19.1", features = ["yaml", "redactions"] }
insta = { version = "1.19.0", features = ["yaml", "redactions"] }
test-case = { version = "2.2.2" }
wasm-bindgen-test = { version = "0.3.33" }

Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -849,6 +849,7 @@ For more, see [pyupgrade](https://pypi.org/project/pyupgrade/) on PyPI.
| UP033 | functools-cache | Use `@functools.cache` instead of `@functools.lru_cache(maxsize=None)` | 🛠 |
| UP034 | extraneous-parentheses | Avoid extraneous parentheses | 🛠 |
| UP035 | import-replacements | Import from `{module}` instead: {names} | 🛠 |
| UP036 | outdated-version-block | Version block is outdated for minimum Python version | 🛠 |

### flake8-2020 (YTT)

Expand Down
4 changes: 4 additions & 0 deletions foo.py
@@ -0,0 +1,4 @@
import sys

expected_error = \
[]
180 changes: 180 additions & 0 deletions resources/test/fixtures/pyupgrade/UP036_0.py
@@ -0,0 +1,180 @@
import sys

if sys.version_info < (3,0):
print("py2")
else:
print("py3")

if sys.version_info < (3,0):
if True:
print("py2!")
else:
print("???")
else:
print("py3")

if sys.version_info < (3,0): print("PY2!")
else: print("PY3!")

if True:
if sys.version_info < (3,0):
print("PY2")
else:
print("PY3")

if sys.version_info < (3,0): print(1 if True else 3)
else:
print("py3")

if sys.version_info < (3,0):
def f():
print("py2")
else:
def f():
print("py3")
print("This the next")

if sys.version_info > (3,0):
print("py3")
else:
print("py2")


x = 1

if sys.version_info > (3,0):
print("py3")
else:
print("py2")
# ohai

x = 1

if sys.version_info > (3,0): print("py3")
else: print("py2")

if sys.version_info > (3,):
print("py3")
else:
print("py2")

if True:
if sys.version_info > (3,):
print("py3")
else:
print("py2")

if sys.version_info < (3,):
print("py2")
else:
print("py3")

def f():
if sys.version_info < (3,0):
try:
yield
finally:
pass
else:
yield


class C:
def g():
pass

if sys.version_info < (3,0):
def f(py2):
pass
else:
def f(py3):
pass

def h():
pass

if True:
if sys.version_info < (3,0):
2
else:
3

# comment

if sys.version_info < (3,0):
def f():
print("py2")
def g():
print("py2")
else:
def f():
print("py3")
def g():
print("py3")

if True:
if sys.version_info > (3,):
print(3)
# comment
print(2+3)

if True:
if sys.version_info > (3,): print(3)

if True:
if sys.version_info > (3,):
print(3)


if True:
if sys.version_info <= (3, 0):
expected_error = []
else:
expected_error = [
"<stdin>:1:5: Generator expression must be parenthesized",
"max(1 for i in range(10), key=lambda x: x+1)",
" ^",
]


if sys.version_info <= (3, 0):
expected_error = []
else:
expected_error = [
"<stdin>:1:5: Generator expression must be parenthesized",
"max(1 for i in range(10), key=lambda x: x+1)",
" ^",
]


if sys.version_info > (3,0):
"""this
is valid"""

"""the indentation on
this line is significant"""

"this is" \
"allowed too"

("so is"
"this for some reason")

if sys.version_info > (3, 0): expected_error = \
[]

if sys.version_info > (3, 0): expected_error = []

if sys.version_info > (3, 0): \
expected_error = []

if True:
if sys.version_info > (3, 0): expected_error = \
[]

if True:
if sys.version_info > (3, 0): expected_error = []

if True:
if sys.version_info > (3, 0): \
expected_error = []
76 changes: 76 additions & 0 deletions resources/test/fixtures/pyupgrade/UP036_1.py
@@ -0,0 +1,76 @@
import sys

if sys.version_info == 2:
2
else:
3

if sys.version_info < (3,):
2
else:
3

if sys.version_info < (3,0):
2
else:
3

if sys.version_info == 3:
3
else:
2

if sys.version_info > (3,):
3
else:
2

if sys.version_info >= (3,):
3
else:
2

from sys import version_info

if version_info > (3,):
3
else:
2

if True:
print(1)
elif sys.version_info < (3,0):
print(2)
else:
print(3)

if True:
print(1)
elif sys.version_info > (3,):
print(3)
else:
print(2)

if True:
print(1)
elif sys.version_info > (3,):
print(3)

def f():
if True:
print(1)
elif sys.version_info > (3,):
print(3)

if True:
print(1)
elif sys.version_info < (3,0):
print(2)
else:
print(3)

def f():
if True:
print(1)
elif sys.version_info > (3,):
print(3)
62 changes: 62 additions & 0 deletions resources/test/fixtures/pyupgrade/UP036_2.py
@@ -0,0 +1,62 @@
import sys
from sys import version_info

if sys.version_info > (3, 5):
3+6
else:
3-5

if version_info > (3, 5):
3+6
else:
3-5

if sys.version_info >= (3,6):
3+6
else:
3-5

if version_info >= (3,6):
3+6
else:
3-5

if sys.version_info < (3,6):
3-5
else:
3+6

if sys.version_info <= (3,5):
3-5
else:
3+6

if sys.version_info <= (3, 5):
3-5
else:
3+6

if sys.version_info >= (3, 5):
pass

if sys.version_info < (3,0):
pass

if True:
if sys.version_info < (3,0):
pass

if sys.version_info < (3,0):
pass
elif False:
pass

if sys.version_info > (3,):
pass
elif False:
pass

if sys.version_info[0] > "2":
3
else:
2
24 changes: 24 additions & 0 deletions resources/test/fixtures/pyupgrade/UP036_3.py
@@ -0,0 +1,24 @@
import sys

if sys.version_info < (3,0):
print("py2")
for item in range(10):
print(f"PY2-{item}")
else :
print("py3")
for item in range(10):
print(f"PY3-{item}")

if False:
if sys.version_info < (3,0):
print("py2")
for item in range(10):
print(f"PY2-{item}")
else :
print("py3")
for item in range(10):
print(f"PY3-{item}")


if sys.version_info < (3,0): print("PY2!")
else : print("PY3!")