Skip to content

Commit

Permalink
Upgrade RustPython to support parenthesized context managers (#1228)
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh authored Dec 13, 2022
1 parent f3e11a3 commit a58b9b5
Show file tree
Hide file tree
Showing 48 changed files with 371 additions and 338 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ regex = { version = "1.6.0" }
ropey = { version = "1.5.0", features = ["cr_lines", "simd"], default-features = false }
ruff_macros = { version = "0.0.178", path = "ruff_macros" }
rustc-hash = { version = "1.1.0" }
rustpython-ast = { features = ["unparse"], git = "https://github.com/RustPython/RustPython.git", rev = "2edd0d264c50c7807bcff03a52a6509e8b7f187f" }
rustpython-common = { git = "https://github.com/RustPython/RustPython.git", rev = "2edd0d264c50c7807bcff03a52a6509e8b7f187f" }
rustpython-parser = { features = ["lalrpop"], git = "https://github.com/RustPython/RustPython.git", rev = "2edd0d264c50c7807bcff03a52a6509e8b7f187f" }
rustpython-ast = { features = ["unparse"], git = "https://github.com/RustPython/RustPython.git", rev = "8d879a53197f9c73062f6160410bdba796a71cbf" }
rustpython-common = { git = "https://github.com/RustPython/RustPython.git", rev = "8d879a53197f9c73062f6160410bdba796a71cbf" }
rustpython-parser = { features = ["lalrpop"], git = "https://github.com/RustPython/RustPython.git", rev = "8d879a53197f9c73062f6160410bdba796a71cbf" }
serde = { version = "1.0.147", features = ["derive"] }
serde_json = { version = "1.0.87" }
strum = { version = "0.24.1", features = ["strum_macros"] }
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1073,8 +1073,7 @@ conflicts with the `isort` rules, like `I001`).
Beyond the rule set, Ruff suffers from the following limitations vis-à-vis Flake8:
1. Ruff does not yet support a few Python 3.9 and 3.10 language features, including structural
pattern matching and parenthesized context managers.
1. Ruff does not yet support structural pattern matching.
2. Flake8 has a plugin architecture and supports writing custom lint rules. (Instead, popular Flake8
plugins are re-implemented in Rust as part of Ruff itself.)
Expand Down
8 changes: 4 additions & 4 deletions flake8_to_ruff/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 28 additions & 12 deletions resources/test/fixtures/pyflakes/F841_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
print(e)


def f1():
def f():
x = 1
y = 2
z = x + y


def f2():
def f():
foo = (1, 2)
(a, b) = (1, 2)

Expand All @@ -26,12 +26,12 @@ def f2():
(x, y) = baz = bar


def f3():
def f():
locals()
x = 1


def f4():
def f():
_ = 1
__ = 1
_discarded = 1
Expand All @@ -40,33 +40,49 @@ def f4():
a = 1


def f5():
def f():
global a

# Used in `f7` via `nonlocal`.
# Used in `c` via `nonlocal`.
b = 1

def f6():
def c():
# F841
b = 1

def f7():
def d():
nonlocal b


def f6():
def f():
annotations = []
assert len([annotations for annotations in annotations])


def f7():
def f():
def connect():
return None, None

with connect() as (connection, cursor):
cursor.execute("SELECT * FROM users")


def f8():
with open("file") as f, open("") as ((a, b)):
def f():
def connect():
return None, None

with (connect() as (connection, cursor)):
cursor.execute("SELECT * FROM users")


def f():
with open("file") as my_file, open("") as ((this, that)):
print("hello")


def f():
with (
open("file") as my_file,
open("") as ((this, that)),
):
print("hello")
6 changes: 3 additions & 3 deletions ruff_dev/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ itertools = { version = "0.10.5" }
libcst = { git = "https://github.com/charliermarsh/LibCST", rev = "f2f0b7a487a8725d161fe8b3ed73a6758b21e177" }
once_cell = { version = "1.16.0" }
ruff = { path = ".." }
rustpython-ast = { features = ["unparse"], git = "https://github.com/RustPython/RustPython.git", rev = "2edd0d264c50c7807bcff03a52a6509e8b7f187f" }
rustpython-common = { git = "https://github.com/RustPython/RustPython.git", rev = "2edd0d264c50c7807bcff03a52a6509e8b7f187f" }
rustpython-parser = { features = ["lalrpop"], git = "https://github.com/RustPython/RustPython.git", rev = "2edd0d264c50c7807bcff03a52a6509e8b7f187f" }
rustpython-ast = { features = ["unparse"], git = "https://github.com/RustPython/RustPython.git", rev = "8d879a53197f9c73062f6160410bdba796a71cbf" }
rustpython-common = { git = "https://github.com/RustPython/RustPython.git", rev = "8d879a53197f9c73062f6160410bdba796a71cbf" }
rustpython-parser = { features = ["lalrpop"], git = "https://github.com/RustPython/RustPython.git", rev = "8d879a53197f9c73062f6160410bdba796a71cbf" }
strum = { version = "0.24.1", features = ["strum_macros"] }
strum_macros = { version = "0.24.3" }
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ expression: checks
row: 29
column: 4
end_location:
row: 35
column: 0
row: 30
column: 16
fix: ~

Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ expression: checks
row: 4
column: 0
end_location:
row: 9
column: 0
row: 5
column: 8
fix: ~
- kind:
MissingTypeFunctionArgument: a
Expand All @@ -35,8 +35,8 @@ expression: checks
row: 9
column: 0
end_location:
row: 14
column: 0
row: 10
column: 8
fix: ~
- kind:
MissingTypeFunctionArgument: b
Expand All @@ -62,17 +62,17 @@ expression: checks
row: 19
column: 0
end_location:
row: 24
column: 0
row: 20
column: 8
fix: ~
- kind:
MissingReturnTypePublicFunction: foo
location:
row: 24
column: 0
end_location:
row: 29
column: 0
row: 25
column: 8
fix: ~
- kind:
DynamicallyTypedExpression: a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ expression: checks
row: 5
column: 4
end_location:
row: 10
column: 0
row: 6
column: 11
fix: ~
- kind:
MissingReturnTypeMagicMethod: __init__
location:
row: 11
column: 4
end_location:
row: 16
column: 0
row: 12
column: 11
fix: ~
- kind:
MissingReturnTypePrivateFunction: __init__
location:
row: 40
column: 0
end_location:
row: 42
column: 0
row: 41
column: 7
fix: ~

Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ expression: checks
row: 45
column: 0
end_location:
row: 50
column: 0
row: 46
column: 15
fix: ~
- kind:
MissingReturnTypePublicFunction: foo
location:
row: 50
column: 0
end_location:
row: 56
column: 0
row: 55
column: 14
fix: ~

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ expression: checks
row: 22
column: 8
end_location:
row: 25
column: 4
row: 23
column: 42
fix: ~

Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,52 @@ expression: checks
row: 17
column: 0
end_location:
row: 22
column: 0
row: 19
column: 13
fix: ~
- kind:
AbstractBaseClassWithoutAbstractMethod: MetaBase_1
location:
row: 58
column: 0
end_location:
row: 63
column: 0
row: 60
column: 13
fix: ~
- kind:
AbstractBaseClassWithoutAbstractMethod: abc_Base_1
location:
row: 69
column: 0
end_location:
row: 74
column: 0
row: 71
column: 13
fix: ~
- kind:
AbstractBaseClassWithoutAbstractMethod: abc_Base_2
location:
row: 74
column: 0
end_location:
row: 79
column: 0
row: 76
column: 13
fix: ~
- kind:
AbstractBaseClassWithoutAbstractMethod: notabc_Base_1
location:
row: 79
column: 0
end_location:
row: 84
column: 0
row: 81
column: 13
fix: ~
- kind:
AbstractBaseClassWithoutAbstractMethod: abc_set_class_variable_4
location:
row: 128
column: 0
end_location:
row: 130
column: 0
row: 129
column: 7
fix: ~

Loading

0 comments on commit a58b9b5

Please sign in to comment.