Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
提交
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
372 changes: 184 additions & 188 deletions Cargo.lock

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ ruff_markdown = { path = "crates/ruff_markdown" }
ruff_memory_usage = { path = "crates/ruff_memory_usage" }
ruff_notebook = { path = "crates/ruff_notebook" }
ruff_options_metadata = { path = "crates/ruff_options_metadata" }
ruff_python_ast = { path = "crates/ruff_python_ast" }
ruff_python_ast = { package = "rustpython-ruff_python_ast", path = "crates/ruff_python_ast", version = "0.15.9" }
ruff_python_codegen = { path = "crates/ruff_python_codegen" }
ruff_python_formatter = { path = "crates/ruff_python_formatter" }
ruff_python_importer = { path = "crates/ruff_python_importer" }
ruff_python_index = { path = "crates/ruff_python_index" }
ruff_python_literal = { path = "crates/ruff_python_literal" }
ruff_python_parser = { path = "crates/ruff_python_parser" }
ruff_python_parser = { package = "rustpython-ruff_python_parser", path = "crates/ruff_python_parser", version = "0.15.9" }
ruff_python_semantic = { path = "crates/ruff_python_semantic" }
ruff_python_stdlib = { path = "crates/ruff_python_stdlib" }
ruff_python_trivia = { path = "crates/ruff_python_trivia" }
ruff_python_trivia = { package = "rustpython-ruff_python_trivia", path = "crates/ruff_python_trivia", version = "0.15.9" }
ruff_server = { path = "crates/ruff_server" }
ruff_source_file = { path = "crates/ruff_source_file" }
ruff_text_size = { path = "crates/ruff_text_size" }
ruff_source_file = { package = "rustpython-ruff_source_file", path = "crates/ruff_source_file", version = "0.15.9" }
ruff_text_size = { package = "rustpython-ruff_text_size", path = "crates/ruff_text_size", version = "0.15.9" }
ruff_workspace = { path = "crates/ruff_workspace" }

ty = { path = "crates/ty" }
Expand Down Expand Up @@ -285,9 +285,9 @@ codegen-units = 16
# Some crates don't change as much but benefit more from
# more expensive optimization passes, so we selectively
# decrease codegen-units in some cases.
[profile.release.package.ruff_python_parser]
[profile.release.package.rustpython-ruff_python_parser]
codegen-units = 1
[profile.release.package.ruff_python_ast]
[profile.release.package.rustpython-ruff_python_ast]
codegen-units = 1
[profile.release.package.salsa]
codegen-units = 1
Expand All @@ -309,7 +309,7 @@ opt-level = 3

# Reduce complexity of a parser function that would trigger a locals limit in a wasm tool.
# https://github.com/bytecodealliance/wasm-tools/blob/b5c3d98e40590512a3b12470ef358d5c7b983b15/crates/wasmparser/src/limits.rs#L29
[profile.dev.package.ruff_python_parser]
[profile.dev.package.rustpython-ruff_python_parser]
opt-level = 1

# This profile is meant to mimic the `release` profile as closely as
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_linter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ruff_db = { workspace = true, features = ["junit", "serde"] }
ruff_diagnostics = { workspace = true, features = ["serde"] }
ruff_macros = { workspace = true }
ruff_notebook = { workspace = true }
ruff_python_ast = { workspace = true, features = ["serde", "cache"] }
ruff_python_ast = { workspace = true }
ruff_python_codegen = { workspace = true }
ruff_python_importer = { workspace = true }
ruff_python_index = { workspace = true }
Expand Down
26 changes: 13 additions & 13 deletions crates/ruff_python_ast/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "ruff_python_ast"
version = "0.0.0"
publish = false
description = "Unofficial fork for RustPython"
name = "rustpython-ruff_python_ast"
version = "0.15.9"
authors = { workspace = true }
edition = { workspace = true }
rust-version = { workspace = true }
Expand All @@ -17,8 +17,8 @@ ignored = ["ruff_cache"]
[lib]

[dependencies]
ruff_cache = { workspace = true, optional = true }
ruff_macros = { workspace = true, optional = true }
# ruff_cache = { workspace = true, optional = true }
# ruff_macros = { workspace = true, optional = true }
ruff_python_trivia = { workspace = true }
ruff_source_file = { workspace = true }
ruff_text_size = { workspace = true }
Expand All @@ -30,21 +30,21 @@ get-size2 = { workspace = true, optional = true }
is-macro = { workspace = true }
memchr = { workspace = true }
rustc-hash = { workspace = true }
salsa = { workspace = true, optional = true }
# salsa = { workspace = true, optional = true }
schemars = { workspace = true, optional = true }
serde = { workspace = true, optional = true }
serde_json = { workspace = true, optional = true }
thiserror = { workspace = true }

[features]
schemars = ["dep:schemars", "dep:serde_json"]
cache = ["dep:ruff_cache", "dep:ruff_macros"]
serde = [
"dep:serde",
"ruff_text_size/serde",
"dep:ruff_cache",
"compact_str/serde",
]
# cache = ["dep:ruff_cache", "dep:ruff_macros"]
# serde = [
# "dep:serde",
# "ruff_text_size/serde",
# "dep:ruff_cache",
# "compact_str/serde",
# ]
get-size = ["dep:get-size2", "ruff_text_size/get-size"]

[lints]
Expand Down
92 changes: 82 additions & 10 deletions crates/ruff_python_ast/ast.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ doc = "See also [mod](https://docs.python.org/3/library/ast.html#ast.mod)"

[Mod.nodes.ModModule]
doc = "See also [Module](https://docs.python.org/3/library/ast.html#ast.Module)"
fields = [{ name = "body", type = "Stmt*" }]
fields = [
{ name = "body", type = "Stmt*" },
{ name = "runtime_body", type = "Vec<Option<crate::Stmt>>?", skip_visit = true },
]

[Mod.nodes.ModExpression]
doc = "See also [Module](https://docs.python.org/3/library/ast.html#ast.Module)"
Expand All @@ -91,6 +94,10 @@ fields = [
{ name = "parameters", type = "Box<crate::Parameters>" },
{ name = "returns", type = "Expr?", is_annotation = true },
{ name = "body", type = "Stmt*" },
{ name = "runtime_decorator_list", type = "Vec<Option<crate::Expr>>?", skip_visit = true },
{ name = "runtime_type_comment", type = "Box<str>?", skip_visit = true },
{ name = "runtime_type_comment_bytes", type = "Vec<u8>?", skip_visit = true },
{ name = "runtime_body", type = "Vec<Option<crate::Stmt>>?", skip_visit = true },
]

[Stmt.nodes.StmtClassDef]
Expand All @@ -101,6 +108,8 @@ fields = [
{ name = "type_params", type = "Box<crate::TypeParams>?" },
{ name = "arguments", type = "Box<crate::Arguments>?" },
{ name = "body", type = "Stmt*" },
{ name = "runtime_decorator_list", type = "Vec<Option<crate::Expr>>?", skip_visit = true },
{ name = "runtime_body", type = "Vec<Option<crate::Stmt>>?", skip_visit = true },
]

[Stmt.nodes.StmtReturn]
Expand All @@ -109,7 +118,10 @@ fields = [{ name = "value", type = "Expr?" }]

[Stmt.nodes.StmtDelete]
doc = "See also [Delete](https://docs.python.org/3/library/ast.html#ast.Delete)"
fields = [{ name = "targets", type = "Expr*" }]
fields = [
{ name = "targets", type = "Expr*" },
{ name = "runtime_targets", type = "Vec<Option<crate::Expr>>?", skip_visit = true },
]

[Stmt.nodes.StmtTypeAlias]
doc = "See also [TypeAlias](https://docs.python.org/3/library/ast.html#ast.TypeAlias)"
Expand All @@ -124,6 +136,9 @@ doc = "See also [Assign](https://docs.python.org/3/library/ast.html#ast.Assign)"
fields = [
{ name = "targets", type = "Expr*" },
{ name = "value", type = "Expr" },
{ name = "runtime_targets", type = "Vec<Option<crate::Expr>>?", skip_visit = true },
{ name = "runtime_type_comment", type = "Box<str>?", skip_visit = true },
{ name = "runtime_type_comment_bytes", type = "Vec<u8>?", skip_visit = true },
]

[Stmt.nodes.StmtAugAssign]
Expand All @@ -141,6 +156,7 @@ fields = [
{ name = "annotation", type = "Expr", is_annotation = true },
{ name = "value", type = "Expr?" },
{ name = "simple", type = "bool" },
{ name = "runtime_simple", type = "i32?", skip_visit = true },
]

[Stmt.nodes.StmtFor]
Expand All @@ -154,6 +170,10 @@ fields = [
{ name = "iter", type = "Expr" },
{ name = "body", type = "Stmt*" },
{ name = "orelse", type = "Stmt*" },
{ name = "runtime_type_comment", type = "Box<str>?", skip_visit = true },
{ name = "runtime_type_comment_bytes", type = "Vec<u8>?", skip_visit = true },
{ name = "runtime_body", type = "Vec<Option<crate::Stmt>>?", skip_visit = true },
{ name = "runtime_orelse", type = "Vec<Option<crate::Stmt>>?", skip_visit = true },
]

[Stmt.nodes.StmtWhile]
Expand All @@ -163,6 +183,8 @@ fields = [
{ name = "test", type = "Expr" },
{ name = "body", type = "Stmt*" },
{ name = "orelse", type = "Stmt*" },
{ name = "runtime_body", type = "Vec<Option<crate::Stmt>>?", skip_visit = true },
{ name = "runtime_orelse", type = "Vec<Option<crate::Stmt>>?", skip_visit = true },
]

[Stmt.nodes.StmtIf]
Expand All @@ -172,6 +194,7 @@ fields = [
{ name = "test", type = "Expr" },
{ name = "body", type = "Stmt*" },
{ name = "elif_else_clauses", type = "ElifElseClause*" },
{ name = "runtime_body", type = "Vec<Option<crate::Stmt>>?", skip_visit = true },
]

[Stmt.nodes.StmtWith]
Expand All @@ -183,6 +206,9 @@ fields = [
{ name = "is_async", type = "bool" },
{ name = "items", type = "WithItem*" },
{ name = "body", type = "Stmt*" },
{ name = "runtime_type_comment", type = "Box<str>?", skip_visit = true },
{ name = "runtime_type_comment_bytes", type = "Vec<u8>?", skip_visit = true },
{ name = "runtime_body", type = "Vec<Option<crate::Stmt>>?", skip_visit = true },
]

[Stmt.nodes.StmtMatch]
Expand All @@ -205,6 +231,10 @@ fields = [
{ name = "orelse", type = "Stmt*" },
{ name = "finalbody", type = "Stmt*" },
{ name = "is_star", type = "bool" },
{ name = "runtime_body", type = "Vec<Option<crate::Stmt>>?", skip_visit = true },
{ name = "runtime_handlers", type = "Vec<Option<crate::ExceptHandler>>?", skip_visit = true },
{ name = "runtime_orelse", type = "Vec<Option<crate::Stmt>>?", skip_visit = true },
{ name = "runtime_finalbody", type = "Vec<Option<crate::Stmt>>?", skip_visit = true },
]

[Stmt.nodes.StmtAssert]
Expand All @@ -225,6 +255,7 @@ fields = [
{ name = "names", type = "Alias*" },
{ name = "level", type = "u32" },
{ name = "is_lazy", type = "bool" },
{ name = "runtime_level", type = "i32?", skip_visit = true },
]

[Stmt.nodes.StmtGlobal]
Expand Down Expand Up @@ -319,7 +350,11 @@ doc = "See also [expr](https://docs.python.org/3/library/ast.html#ast.expr)"

[Expr.nodes.ExprBoolOp]
doc = "See also [BoolOp](https://docs.python.org/3/library/ast.html#ast.BoolOp)"
fields = [{ name = "op", type = "BoolOp" }, { name = "values", type = "Expr*" }]
fields = [
{ name = "op", type = "BoolOp" },
{ name = "values", type = "Expr*" },
{ name = "runtime_values", type = "Vec<Option<crate::Expr>>?", skip_visit = true },
]
custom_source_order = true

[Expr.nodes.ExprNamed]
Expand Down Expand Up @@ -359,12 +394,18 @@ source_order = ["body", "test", "orelse"]

[Expr.nodes.ExprDict]
doc = "See also [Dict](https://docs.python.org/3/library/ast.html#ast.Dict)"
fields = [{ name = "items", type = "DictItem*" }]
fields = [
{ name = "items", type = "DictItem*" },
{ name = "runtime_values", type = "Vec<Option<crate::Expr>>?", skip_visit = true },
]
custom_source_order = true

[Expr.nodes.ExprSet]
doc = "See also [Set](https://docs.python.org/3/library/ast.html#ast.Set)"
fields = [{ name = "elts", type = "Expr*" }]
fields = [
{ name = "elts", type = "Expr*" },
{ name = "runtime_elts", type = "Vec<Option<crate::Expr>>?", skip_visit = true },
]

[Expr.nodes.ExprListComp]
doc = "See also [ListComp](https://docs.python.org/3/library/ast.html#ast.ListComp)"
Expand Down Expand Up @@ -414,6 +455,7 @@ fields = [
{ name = "left", type = "Expr" },
{ name = "ops", type = "&CmpOp*" },
{ name = "comparators", type = "&Expr*" },
{ name = "runtime_comparators", type = "Vec<Option<crate::Expr>>?", skip_visit = true },
]
# The fields must be visited simultaneously
custom_source_order = true
Expand All @@ -434,7 +476,11 @@ doesn't join the implicitly concatenated parts into a single string. Instead,
it keeps them separate and provide various methods to access the parts.

See also [JoinedStr](https://docs.python.org/3/library/ast.html#ast.JoinedStr)"""
fields = [{ name = "value", type = "FStringValue" }]
fields = [
{ name = "value", type = "FStringValue" },
{ name = "runtime_joined_str", type = "Vec<crate::Expr>?", skip_visit = true },
{ name = "runtime_values", type = "Vec<Option<crate::Expr>>?", skip_visit = true },
]
custom_source_order = true

[Expr.nodes.ExprTString]
Expand All @@ -446,7 +492,11 @@ doesn't join the implicitly concatenated parts into a single string. Instead,
it keeps them separate and provide various methods to access the parts.

See also [TemplateStr](https://docs.python.org/3/library/ast.html#ast.TemplateStr)"""
fields = [{ name = "value", type = "TStringValue" }]
fields = [
{ name = "value", type = "TStringValue" },
{ name = "runtime_template_str", type = "Vec<crate::Expr>?", skip_visit = true },
{ name = "runtime_values", type = "Vec<Option<crate::Expr>>?", skip_visit = true },
]
custom_source_order = true

[Expr.nodes.ExprStringLiteral]
Expand Down Expand Up @@ -475,9 +525,18 @@ fields = []
derives = ["Default"]

[Expr.nodes.ExprEllipsisLiteral]
fields = []
fields = [
]
derives = ["Default"]

[Expr.nodes.ExprConstant]
doc = "See also [Constant](https://docs.python.org/3/library/ast.html#ast.Constant)"
fields = [
{ name = "value", type = "ConstantValue", skip_visit = true },
{ name = "kind", type = "Box<str>?", skip_visit = true },
{ name = "invalid_type", type = "Box<str>?", skip_visit = true },
]

[Expr.nodes.ExprAttribute]
doc = "See also [Attribute](https://docs.python.org/3/library/ast.html#ast.Attribute)"
fields = [
Expand Down Expand Up @@ -513,6 +572,7 @@ doc = "See also [List](https://docs.python.org/3/library/ast.html#ast.List)"
fields = [
{ name = "elts", type = "Expr*" },
{ name = "ctx", type = "ExprContext" },
{ name = "runtime_elts", type = "Vec<Option<crate::Expr>>?", skip_visit = true },
]

[Expr.nodes.ExprTuple]
Expand All @@ -521,6 +581,7 @@ fields = [
{ name = "elts", type = "Expr*" },
{ name = "ctx", type = "ExprContext" },
{ name = "parenthesized", type = "bool" },
{ name = "runtime_elts", type = "Vec<Option<crate::Expr>>?", skip_visit = true },
]

[Expr.nodes.ExprSlice]
Expand Down Expand Up @@ -573,14 +634,19 @@ fields = [{ name = "value", type = "Singleton" }]

[Pattern.nodes.PatternMatchSequence]
doc = "See also [MatchSequence](https://docs.python.org/3/library/ast.html#ast.MatchSequence)"
fields = [{ name = "patterns", type = "Pattern*" }]
fields = [
{ name = "patterns", type = "Pattern*" },
{ name = "runtime_patterns", type = "Vec<Option<crate::Pattern>>?", skip_visit = true },
]

[Pattern.nodes.PatternMatchMapping]
doc = "See also [MatchMapping](https://docs.python.org/3/library/ast.html#ast.MatchMapping)"
fields = [
{ name = "keys", type = "Expr*" },
{ name = "patterns", type = "Pattern*" },
{ name = "rest", type = "Identifier?" },
{ name = "runtime_keys", type = "Vec<Option<crate::Expr>>?", skip_visit = true },
{ name = "runtime_patterns", type = "Vec<Option<crate::Pattern>>?", skip_visit = true },
]
custom_source_order = true

Expand All @@ -589,6 +655,9 @@ doc = "See also [MatchClass](https://docs.python.org/3/library/ast.html#ast.Matc
fields = [
{ name = "cls", type = "Box<Expr>" },
{ name = "arguments", type = "PatternArguments" },
{ name = "runtime_patterns", type = "Vec<Option<crate::Pattern>>?", skip_visit = true },
{ name = "runtime_kwd_attrs", type = "Vec<crate::Identifier>?", skip_visit = true },
{ name = "runtime_kwd_patterns", type = "Vec<Option<crate::Pattern>>?", skip_visit = true },
]

[Pattern.nodes.PatternMatchStar]
Expand All @@ -604,7 +673,10 @@ fields = [

[Pattern.nodes.PatternMatchOr]
doc = "See also [MatchOr](https://docs.python.org/3/library/ast.html#ast.MatchOr)"
fields = [{ name = "patterns", type = "Pattern*" }]
fields = [
{ name = "patterns", type = "Pattern*" },
{ name = "runtime_patterns", type = "Vec<Option<crate::Pattern>>?", skip_visit = true },
]

[TypeParam]
doc = "See also [type_param](https://docs.python.org/3/library/ast.html#ast.type_param)"
Expand Down
1 change: 1 addition & 0 deletions crates/ruff_python_ast/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"Alias",
"Singleton",
"PatternArguments",
"ConstantValue",
}


Expand Down
Loading