Upgrade RustPython

This commit is contained in:
Charles Marsh 2022-08-21 13:51:16 -04:00
parent d7ee58c17a
commit baa8f32814
4 changed files with 257 additions and 12 deletions

242
Cargo.lock generated
View File

@ -37,6 +37,15 @@ version = "1.0.60"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c794e162a5eff65c72ef524dfe393eb923c354e350bb78b9c7383df13f3bc142" checksum = "c794e162a5eff65c72ef524dfe393eb923c354e350bb78b9c7383df13f3bc142"
[[package]]
name = "ascii-canvas"
version = "3.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8824ecca2e851cec16968d54a01dd372ef8f95b244fb84b84e70128be347c3c6"
dependencies = [
"term",
]
[[package]] [[package]]
name = "async-channel" name = "async-channel"
version = "1.7.0" version = "1.7.0"
@ -197,6 +206,21 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "bit-set"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1"
dependencies = [
"bit-vec",
]
[[package]]
name = "bit-vec"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb"
[[package]] [[package]]
name = "bitflags" name = "bitflags"
version = "1.3.2" version = "1.3.2"
@ -247,6 +271,17 @@ dependencies = [
"once_cell", "once_cell",
] ]
[[package]]
name = "bstr"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223"
dependencies = [
"lazy_static",
"memchr",
"regex-automata",
]
[[package]] [[package]]
name = "bumpalo" name = "bumpalo"
version = "3.10.0" version = "3.10.0"
@ -491,6 +526,12 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "diff"
version = "0.1.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8"
[[package]] [[package]]
name = "digest" name = "digest"
version = "0.8.1" version = "0.8.1"
@ -528,6 +569,16 @@ dependencies = [
"dirs-sys", "dirs-sys",
] ]
[[package]]
name = "dirs-next"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1"
dependencies = [
"cfg-if 1.0.0",
"dirs-sys-next",
]
[[package]] [[package]]
name = "dirs-sys" name = "dirs-sys"
version = "0.3.7" version = "0.3.7"
@ -539,12 +590,32 @@ dependencies = [
"winapi 0.3.9", "winapi 0.3.9",
] ]
[[package]]
name = "dirs-sys-next"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d"
dependencies = [
"libc",
"redox_users",
"winapi 0.3.9",
]
[[package]] [[package]]
name = "either" name = "either"
version = "1.7.0" version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f107b87b6afc2a64fd13cac55fe06d6c8859f12d4b14cbcdd2c67d0976781be" checksum = "3f107b87b6afc2a64fd13cac55fe06d6c8859f12d4b14cbcdd2c67d0976781be"
[[package]]
name = "ena"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7402b94a93c24e742487327a7cd839dc9d36fec9de9fb25b09f2dae459f36c3"
dependencies = [
"log",
]
[[package]] [[package]]
name = "event-listener" name = "event-listener"
version = "2.5.3" version = "2.5.3"
@ -587,6 +658,12 @@ dependencies = [
"windows-sys", "windows-sys",
] ]
[[package]]
name = "fixedbitset"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80"
[[package]] [[package]]
name = "fnv" name = "fnv"
version = "1.0.7" version = "1.0.7"
@ -885,6 +962,15 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "itertools"
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3"
dependencies = [
"either",
]
[[package]] [[package]]
name = "itoa" name = "itoa"
version = "1.0.3" version = "1.0.3"
@ -919,11 +1005,37 @@ dependencies = [
"log", "log",
] ]
[[package]]
name = "lalrpop"
version = "0.19.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b30455341b0e18f276fa64540aff54deafb54c589de6aca68659c63dd2d5d823"
dependencies = [
"ascii-canvas",
"atty",
"bit-set",
"diff",
"ena",
"itertools",
"lalrpop-util",
"petgraph",
"pico-args",
"regex",
"regex-syntax",
"string_cache",
"term",
"tiny-keccak",
"unicode-xid",
]
[[package]] [[package]]
name = "lalrpop-util" name = "lalrpop-util"
version = "0.19.8" version = "0.19.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bcf796c978e9b4d983414f4caedc9273aa33ee214c5b887bd55fde84c85d2dc4" checksum = "bcf796c978e9b4d983414f4caedc9273aa33ee214c5b887bd55fde84c85d2dc4"
dependencies = [
"regex",
]
[[package]] [[package]]
name = "lazy_static" name = "lazy_static"
@ -963,6 +1075,15 @@ dependencies = [
"value-bag", "value-bag",
] ]
[[package]]
name = "lz4_flex"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c038063f7a78126c539d666a0323a2032de5e7366012cd14a6eafc5ba290bbd6"
dependencies = [
"twox-hash",
]
[[package]] [[package]]
name = "memchr" name = "memchr"
version = "2.5.0" version = "2.5.0"
@ -1041,6 +1162,12 @@ dependencies = [
"winapi 0.3.9", "winapi 0.3.9",
] ]
[[package]]
name = "new_debug_unreachable"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54"
[[package]] [[package]]
name = "nix" name = "nix"
version = "0.24.2" version = "0.24.2"
@ -1089,6 +1216,17 @@ dependencies = [
"autocfg", "autocfg",
"num-integer", "num-integer",
"num-traits", "num-traits",
"serde",
]
[[package]]
name = "num-complex"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ae39348c8bc5fbd7f40c727a9925f03517afd2ab27d46702108b6a7e5414c19"
dependencies = [
"num-traits",
"serde",
] ]
[[package]] [[package]]
@ -1173,6 +1311,16 @@ dependencies = [
"windows-sys", "windows-sys",
] ]
[[package]]
name = "petgraph"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6d5014253a1331579ce62aa67443b4a658c5e7dd03d4bc6d302b94474888143"
dependencies = [
"fixedbitset",
"indexmap",
]
[[package]] [[package]]
name = "phf" name = "phf"
version = "0.8.0" version = "0.8.0"
@ -1249,6 +1397,12 @@ dependencies = [
"siphasher", "siphasher",
] ]
[[package]]
name = "pico-args"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db8bcd96cb740d03149cbad5518db9fd87126a10ab519c011893b1754134c468"
[[package]] [[package]]
name = "pin-project-lite" name = "pin-project-lite"
version = "0.2.9" version = "0.2.9"
@ -1280,6 +1434,12 @@ version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
[[package]]
name = "precomputed-hash"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
[[package]] [[package]]
name = "proc-macro-error" name = "proc-macro-error"
version = "1.0.4" version = "1.0.4"
@ -1517,6 +1677,12 @@ dependencies = [
"regex-syntax", "regex-syntax",
] ]
[[package]]
name = "regex-automata"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
[[package]] [[package]]
name = "regex-syntax" name = "regex-syntax"
version = "0.6.27" version = "0.6.27"
@ -1561,17 +1727,37 @@ dependencies = [
[[package]] [[package]]
name = "rustpython-ast" name = "rustpython-ast"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/RustPython/RustPython.git?rev=dff916d45c5d13074d21ad329a5ab68a6499426a#dff916d45c5d13074d21ad329a5ab68a6499426a" source = "git+https://github.com/RustPython/RustPython.git?rev=f1c7aebfad707526602c8162c8094a67129b6731#f1c7aebfad707526602c8162c8094a67129b6731"
dependencies = [ dependencies = [
"num-bigint", "num-bigint",
"rustpython-bytecode",
]
[[package]]
name = "rustpython-bytecode"
version = "0.1.2"
source = "git+https://github.com/RustPython/RustPython.git?rev=f1c7aebfad707526602c8162c8094a67129b6731#f1c7aebfad707526602c8162c8094a67129b6731"
dependencies = [
"bincode",
"bitflags",
"bstr",
"itertools",
"lz4_flex",
"num-bigint",
"num-complex",
"serde",
"static_assertions",
] ]
[[package]] [[package]]
name = "rustpython-parser" name = "rustpython-parser"
version = "0.1.2" version = "0.1.2"
source = "git+https://github.com/RustPython/RustPython.git?rev=dff916d45c5d13074d21ad329a5ab68a6499426a#dff916d45c5d13074d21ad329a5ab68a6499426a" source = "git+https://github.com/RustPython/RustPython.git?rev=f1c7aebfad707526602c8162c8094a67129b6731#f1c7aebfad707526602c8162c8094a67129b6731"
dependencies = [ dependencies = [
"ahash", "ahash",
"anyhow",
"itertools",
"lalrpop",
"lalrpop-util", "lalrpop-util",
"log", "log",
"num-bigint", "num-bigint",
@ -1585,6 +1771,12 @@ dependencies = [
"unicode_names2", "unicode_names2",
] ]
[[package]]
name = "rustversion"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97477e48b4cf8603ad5f7aaf897467cf42ab4218a38ef76fb14c2d6773a6d6a8"
[[package]] [[package]]
name = "ryu" name = "ryu"
version = "1.0.11" version = "1.0.11"
@ -1752,6 +1944,25 @@ dependencies = [
"thiserror", "thiserror",
] ]
[[package]]
name = "static_assertions"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "string_cache"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "213494b7a2b503146286049378ce02b482200519accc31872ee8be91fa820a08"
dependencies = [
"new_debug_unreachable",
"once_cell",
"parking_lot",
"phf_shared 0.10.0",
"precomputed-hash",
]
[[package]] [[package]]
name = "strsim" name = "strsim"
version = "0.10.0" version = "0.10.0"
@ -1789,6 +2000,17 @@ dependencies = [
"winapi 0.3.9", "winapi 0.3.9",
] ]
[[package]]
name = "term"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c59df8ac95d96ff9bede18eb7300b0fda5e5d8d90960e76f8e14ae765eedbf1f"
dependencies = [
"dirs-next",
"rustversion",
"winapi 0.3.9",
]
[[package]] [[package]]
name = "termcolor" name = "termcolor"
version = "1.1.3" version = "1.1.3"
@ -1866,6 +2088,16 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "twox-hash"
version = "1.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675"
dependencies = [
"cfg-if 0.1.10",
"static_assertions",
]
[[package]] [[package]]
name = "typenum" name = "typenum"
version = "1.15.0" version = "1.15.0"
@ -1930,6 +2162,12 @@ version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf"
[[package]]
name = "unicode-xid"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04"
[[package]] [[package]]
name = "unicode_names2" name = "unicode_names2"
version = "0.5.0" version = "0.5.0"

View File

@ -23,7 +23,7 @@ notify = { version = "4.0.17" }
pyo3 = { version = "0.16.5", features = ["extension-module", "abi3-py37"] } pyo3 = { version = "0.16.5", features = ["extension-module", "abi3-py37"] }
rayon = { version = "1.5.3" } rayon = { version = "1.5.3" }
regex = { version = "1.6.0" } regex = { version = "1.6.0" }
rustpython-parser = { git = "https://github.com/RustPython/RustPython.git", rev = "dff916d45c5d13074d21ad329a5ab68a6499426a" } rustpython-parser = { features=["lalrpop"], git = "https://github.com/RustPython/RustPython.git", rev = "f1c7aebfad707526602c8162c8094a67129b6731" }
serde = { version = "1.0.143", features = ["derive"] } serde = { version = "1.0.143", features = ["derive"] }
serde_json = { version = "1.0.83" } serde_json = { version = "1.0.83" }
toml = { version = "0.5.9"} toml = { version = "0.5.9"}

View File

@ -67,7 +67,7 @@ impl Visitor for Checker<'_> {
.contains(CheckKind::ImportStarUsage.code()) .contains(CheckKind::ImportStarUsage.code())
{ {
for alias in names { for alias in names {
if alias.name == "*" { if alias.node.name == "*" {
self.checks.push(Check { self.checks.push(Check {
kind: CheckKind::ImportStarUsage, kind: CheckKind::ImportStarUsage,
location: stmt.location, location: stmt.location,
@ -218,7 +218,7 @@ pub fn check_ast(python_ast: &Suite, settings: &Settings) -> Vec<Check> {
mod tests { mod tests {
use std::collections::BTreeSet; use std::collections::BTreeSet;
use rustpython_parser::ast::{Alias, Location, Stmt, StmtKind}; use rustpython_parser::ast::{Alias, AliasData, Location, Stmt, StmtKind};
use crate::check_ast::Checker; use crate::check_ast::Checker;
use crate::checks::CheckKind::ImportStarUsage; use crate::checks::CheckKind::ImportStarUsage;
@ -239,11 +239,14 @@ mod tests {
custom: (), custom: (),
node: StmtKind::ImportFrom { node: StmtKind::ImportFrom {
module: Some("bar".to_string()), module: Some("bar".to_string()),
names: vec![Alias { names: vec![Alias::new(
name: "*".to_string(), Default::default(),
asname: None, AliasData {
}], name: "*".to_string(),
level: 0, asname: None,
},
)],
level: None,
}, },
}); });

View File

@ -230,6 +230,10 @@ pub fn walk_stmt<V: Visitor + ?Sized>(visitor: &mut V, stmt: &Stmt) {
visitor.visit_stmt(stmt) visitor.visit_stmt(stmt)
} }
} }
StmtKind::Match { subject, .. } => {
// TODO(charlie): Handle `cases`.
visitor.visit_expr(subject);
}
StmtKind::Raise { exc, cause } => { StmtKind::Raise { exc, cause } => {
if let Some(expr) = exc { if let Some(expr) = exc {
visitor.visit_expr(expr) visitor.visit_expr(expr)
@ -326,7 +330,7 @@ pub fn walk_expr<V: Visitor + ?Sized>(visitor: &mut V, expr: &Expr) {
visitor.visit_expr(orelse); visitor.visit_expr(orelse);
} }
ExprKind::Dict { keys, values } => { ExprKind::Dict { keys, values } => {
for expr in keys.iter().flatten() { for expr in keys {
visitor.visit_expr(expr) visitor.visit_expr(expr)
} }
for expr in values { for expr in values {
@ -505,7 +509,7 @@ pub fn walk_arguments<V: Visitor + ?Sized>(visitor: &mut V, arguments: &Argument
for arg in &arguments.kwonlyargs { for arg in &arguments.kwonlyargs {
visitor.visit_arg(arg); visitor.visit_arg(arg);
} }
for expr in arguments.kw_defaults.iter().flatten() { for expr in &arguments.kw_defaults {
visitor.visit_expr(expr) visitor.visit_expr(expr)
} }
if let Some(arg) = &arguments.kwarg { if let Some(arg) = &arguments.kwarg {