Replace LALRPOP parser with hand-written parser (#10036)

(Supersedes #9152, authored by @LaBatata101)

## Summary

This PR replaces the current parser generated from LALRPOP to a
hand-written recursive descent parser.

It also updates the grammar for [PEP
646](https://peps.python.org/pep-0646/) so that the parser outputs the
correct AST. For example, in `data[*x]`, the index expression is now a
tuple with a single starred expression instead of just a starred
expression.

Beyond the performance improvements, the parser is also error resilient
and can provide better error messages. The behavior as seen by any
downstream tools isn't changed. That is, the linter and formatter can
still assume that the parser will _stop_ at the first syntax error. This
will be updated in the following months.

For more details about the change here, refer to the PR corresponding to
the individual commits and the release blog post.

## Test Plan

Write _lots_ and _lots_ of tests for both valid and invalid syntax and
verify the output.

## Acknowledgements

- @MichaReiser for reviewing 100+ parser PRs and continuously providing
guidance throughout the project
- @LaBatata101 for initiating the transition to a hand-written parser in
#9152
- @addisoncrump for implementing the fuzzer which helped
[catch](https://github.com/astral-sh/ruff/pull/10903)
[a](https://github.com/astral-sh/ruff/pull/10910)
[lot](https://github.com/astral-sh/ruff/pull/10966)
[of](https://github.com/astral-sh/ruff/pull/10896)
[bugs](https://github.com/astral-sh/ruff/pull/10877)

---------

Co-authored-by: Victor Hugo Gomes <labatata101@linuxmail.org>
Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
Dhruv Manilawala 2024-04-18 17:57:39 +05:30 committed by GitHub
parent e09180b1df
commit 13ffb5bc19
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
852 changed files with 112948 additions and 103620 deletions

View file

@ -0,0 +1,293 @@
use std::cmp::Ordering;
use std::fmt::{Formatter, Write};
use std::fs;
use std::path::Path;
use annotate_snippets::display_list::{DisplayList, FormatOptions};
use annotate_snippets::snippet::{AnnotationType, Slice, Snippet, SourceAnnotation};
use ruff_python_ast::visitor::preorder::{walk_module, PreorderVisitor, TraversalSignal};
use ruff_python_ast::{AnyNodeRef, Mod};
use ruff_python_parser::{Mode, ParseErrorType, Program};
use ruff_source_file::{LineIndex, OneIndexed, SourceCode};
use ruff_text_size::{Ranged, TextLen, TextRange, TextSize};
#[test]
fn valid_syntax() {
insta::glob!("../resources", "valid/**/*.py", test_valid_syntax);
}
#[test]
fn invalid_syntax() {
insta::glob!("../resources", "invalid/**/*.py", test_invalid_syntax);
}
#[test]
fn inline_ok() {
insta::glob!("../resources/inline", "ok/**/*.py", test_valid_syntax);
}
#[test]
fn inline_err() {
insta::glob!("../resources/inline", "err/**/*.py", test_invalid_syntax);
}
/// Asserts that the parser generates no syntax errors for a valid program.
/// Snapshots the AST.
fn test_valid_syntax(input_path: &Path) {
let source = fs::read_to_string(input_path).expect("Expected test file to exist");
let program = Program::parse_str(&source, Mode::Module);
if !program.is_valid() {
let line_index = LineIndex::from_source_text(&source);
let source_code = SourceCode::new(&source, &line_index);
let mut message = "Expected no syntax errors for a valid program but the parser generated the following errors:\n".to_string();
for error in program.errors() {
writeln!(
&mut message,
"{}\n",
CodeFrame {
range: error.location,
error,
source_code: &source_code,
}
)
.unwrap();
}
panic!("{input_path:?}: {message}");
}
validate_ast(program.ast(), source.text_len(), input_path);
let mut output = String::new();
writeln!(&mut output, "## AST").unwrap();
writeln!(&mut output, "\n```\n{:#?}\n```", program.ast()).unwrap();
insta::with_settings!({
omit_expression => true,
input_file => input_path,
prepend_module_to_snapshot => false,
}, {
insta::assert_snapshot!(output);
});
}
/// Assert that the parser generates at least one syntax error for the given input file.
/// Snapshots the AST and the error messages.
fn test_invalid_syntax(input_path: &Path) {
let source = fs::read_to_string(input_path).expect("Expected test file to exist");
let program = Program::parse_str(&source, Mode::Module);
assert!(
!program.is_valid(),
"{input_path:?}: Expected parser to generate at least one syntax error for a program containing syntax errors."
);
validate_ast(program.ast(), source.text_len(), input_path);
let mut output = String::new();
writeln!(&mut output, "## AST").unwrap();
writeln!(&mut output, "\n```\n{:#?}\n```", program.ast()).unwrap();
writeln!(&mut output, "## Errors\n").unwrap();
let line_index = LineIndex::from_source_text(&source);
let source_code = SourceCode::new(&source, &line_index);
for error in program.errors() {
writeln!(
&mut output,
"{}\n",
CodeFrame {
range: error.location,
error,
source_code: &source_code,
}
)
.unwrap();
}
insta::with_settings!({
omit_expression => true,
input_file => input_path,
prepend_module_to_snapshot => false,
}, {
insta::assert_snapshot!(output);
});
}
// Test that is intentionally ignored by default.
// Use it for quickly debugging a parser issue.
#[test]
#[ignore]
#[allow(clippy::print_stdout)]
fn parser_quick_test() {
let source = "\
data[*x,]
";
let program = Program::parse_str(source, Mode::Module);
println!("AST:\n----\n{:#?}", program.ast());
if !program.is_valid() {
println!("Errors:\n-------");
let line_index = LineIndex::from_source_text(source);
let source_code = SourceCode::new(source, &line_index);
for error in program.errors() {
// Sometimes the code frame doesn't show the error message, so we print
// the message as well.
println!("Syntax Error: {error}");
println!(
"{}\n",
CodeFrame {
range: error.location,
error,
source_code: &source_code,
}
);
}
println!();
}
}
struct CodeFrame<'a> {
range: TextRange,
error: &'a ParseErrorType,
source_code: &'a SourceCode<'a, 'a>,
}
impl std::fmt::Display for CodeFrame<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
// Copied and modified from ruff_linter/src/message/text.rs
let content_start_index = self.source_code.line_index(self.range.start());
let mut start_index = content_start_index.saturating_sub(2);
// Trim leading empty lines.
while start_index < content_start_index {
if !self.source_code.line_text(start_index).trim().is_empty() {
break;
}
start_index = start_index.saturating_add(1);
}
let content_end_index = self.source_code.line_index(self.range.end());
let mut end_index = content_end_index
.saturating_add(2)
.min(OneIndexed::from_zero_indexed(self.source_code.line_count()));
// Trim trailing empty lines.
while end_index > content_end_index {
if !self.source_code.line_text(end_index).trim().is_empty() {
break;
}
end_index = end_index.saturating_sub(1);
}
let start_offset = self.source_code.line_start(start_index);
let end_offset = self.source_code.line_end(end_index);
let annotation_range = self.range - start_offset;
let source = self
.source_code
.slice(TextRange::new(start_offset, end_offset));
let start_char = source[TextRange::up_to(annotation_range.start())]
.chars()
.count();
let char_length = source[annotation_range].chars().count();
let label = format!("Syntax Error: {error}", error = self.error);
let snippet = Snippet {
title: None,
slices: vec![Slice {
source,
line_start: start_index.get(),
annotations: vec![SourceAnnotation {
label: &label,
annotation_type: AnnotationType::Error,
range: (start_char, start_char + char_length),
}],
// The origin (file name, line number, and column number) is already encoded
// in the `label`.
origin: None,
fold: false,
}],
footer: Vec::new(),
opt: FormatOptions::default(),
};
writeln!(f, "{message}", message = DisplayList::from(snippet))
}
}
/// Verifies that:
/// * the range of the parent node fully encloses all its child nodes
/// * the ranges are strictly increasing when traversing the nodes in pre-order.
/// * all ranges are within the length of the source code.
fn validate_ast(root: &Mod, source_len: TextSize, test_path: &Path) {
walk_module(&mut ValidateAstVisitor::new(source_len, test_path), root);
}
#[derive(Debug)]
struct ValidateAstVisitor<'a> {
parents: Vec<AnyNodeRef<'a>>,
previous: Option<AnyNodeRef<'a>>,
source_length: TextSize,
test_path: &'a Path,
}
impl<'a> ValidateAstVisitor<'a> {
fn new(source_length: TextSize, test_path: &'a Path) -> Self {
Self {
parents: Vec::new(),
previous: None,
source_length,
test_path,
}
}
}
impl<'ast> PreorderVisitor<'ast> for ValidateAstVisitor<'ast> {
fn enter_node(&mut self, node: AnyNodeRef<'ast>) -> TraversalSignal {
assert!(
node.end() <= self.source_length,
"{path}: The range of the node exceeds the length of the source code. Node: {node:#?}",
path = self.test_path.display()
);
if let Some(previous) = self.previous {
assert_ne!(previous.range().ordering(node.range()), Ordering::Greater,
"{path}: The ranges of the nodes are not strictly increasing when traversing the AST in pre-order.\nPrevious node: {previous:#?}\n\nCurrent node: {node:#?}\n\nRoot: {root:#?}",
path = self.test_path.display(),
root = self.parents.first()
);
}
if let Some(parent) = self.parents.last() {
assert!(parent.range().contains_range(node.range()),
"{path}: The range of the parent node does not fully enclose the range of the child node.\nParent node: {parent:#?}\n\nChild node: {node:#?}\n\nRoot: {root:#?}",
path = self.test_path.display(),
root = self.parents.first()
);
}
self.parents.push(node);
TraversalSignal::Traverse
}
fn leave_node(&mut self, node: AnyNodeRef<'ast>) {
self.parents.pop().expect("Expected tree to be balanced");
self.previous = Some(node);
}
}

View file

@ -0,0 +1,303 @@
//! This module takes specially formatted comments from `ruff_python_parser` code
//! and turns them into test fixtures. The code is derived from `rust-analyzer`
//! and `biome`.
//!
//! References:
//! - <https://github.com/rust-lang/rust-analyzer/blob/e4a405f877efd820bef9c0e77a02494e47c17512/crates/parser/src/tests/sourcegen_inline_tests.rs>
//! - <https://github.com/biomejs/biome/blob/b9f8ffea9967b098ec4c8bf74fa96826a879f043/xtask/codegen/src/parser_tests.rs>
use std::collections::HashMap;
use std::fmt;
use std::fs;
use std::ops::{AddAssign, Deref, DerefMut};
use std::path::{Path, PathBuf};
use anyhow::{Context, Result};
fn project_root() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("../../")
.canonicalize()
.unwrap()
}
#[test]
fn generate_inline_tests() -> Result<()> {
let parser_dir = project_root().join("crates/ruff_python_parser/src/parser");
let tests = TestCollection::try_from(parser_dir.as_path())?;
let mut test_files = TestFiles::default();
test_files += install_tests(&tests.ok, "crates/ruff_python_parser/resources/inline/ok")?;
test_files += install_tests(&tests.err, "crates/ruff_python_parser/resources/inline/err")?;
if !test_files.is_empty() {
anyhow::bail!("{}", test_files);
}
Ok(())
}
#[derive(Debug, Default)]
struct TestFiles {
unreferenced: Vec<PathBuf>,
updated: Vec<PathBuf>,
}
impl TestFiles {
fn is_empty(&self) -> bool {
self.unreferenced.is_empty() && self.updated.is_empty()
}
}
impl AddAssign<TestFiles> for TestFiles {
fn add_assign(&mut self, other: TestFiles) {
self.unreferenced.extend(other.unreferenced);
self.updated.extend(other.updated);
}
}
impl fmt::Display for TestFiles {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self.is_empty() {
writeln!(f, "No unreferenced or updated test files found")
} else {
let root_dir = project_root();
if !self.unreferenced.is_empty() {
writeln!(
f,
"Unreferenced test files found for which no comment exists:",
)?;
for path in &self.unreferenced {
writeln!(f, " {}", path.strip_prefix(&root_dir).unwrap().display())?;
}
writeln!(f, "Please delete these files manually")?;
}
if !self.updated.is_empty() {
if !self.unreferenced.is_empty() {
writeln!(f)?;
}
writeln!(
f,
"Following files were not up-to date and has been updated:",
)?;
for path in &self.updated {
writeln!(f, " {}", path.strip_prefix(&root_dir).unwrap().display())?;
}
writeln!(
f,
"Re-run the tests with `cargo test` to update the test snapshots"
)?;
if std::env::var("CI").is_ok() {
writeln!(
f,
"NOTE: Run the tests locally and commit the updated files"
)?;
}
}
Ok(())
}
}
}
fn install_tests(tests: &HashMap<String, Test>, target_dir: &str) -> Result<TestFiles> {
let root_dir = project_root();
let tests_dir = root_dir.join(target_dir);
if !tests_dir.is_dir() {
fs::create_dir_all(&tests_dir)?;
}
// Test kind is irrelevant for existing test cases.
let existing = existing_tests(&tests_dir)?;
let mut updated_files = vec![];
for (name, test) in tests {
let path = match existing.get(name) {
Some(path) => path.clone(),
None => tests_dir.join(name).with_extension("py"),
};
match fs::read_to_string(&path) {
Ok(old_contents) if old_contents == test.contents => continue,
_ => {}
}
fs::write(&path, &test.contents)
.with_context(|| format!("Failed to write to {:?}", path.display()))?;
updated_files.push(path);
}
Ok(TestFiles {
unreferenced: existing
.into_iter()
.filter(|(name, _)| !tests.contains_key(name))
.map(|(_, path)| path)
.collect::<Vec<_>>(),
updated: updated_files,
})
}
#[derive(Default, Debug)]
struct TestCollection {
ok: HashMap<String, Test>,
err: HashMap<String, Test>,
}
impl TryFrom<&Path> for TestCollection {
type Error = anyhow::Error;
fn try_from(path: &Path) -> Result<Self> {
let mut tests = TestCollection::default();
for entry in walkdir::WalkDir::new(path) {
let entry = entry?;
if !entry.file_type().is_file() {
continue;
}
if entry.path().extension().unwrap_or_default() != "rs" {
continue;
}
let text = fs::read_to_string(entry.path())?;
for test in collect_tests(&text) {
if test.is_ok() {
if let Some(old_test) = tests.ok.insert(test.name.clone(), test) {
anyhow::bail!(
"Duplicate test found: {name:?} (search '// test_ok {name}' for the location)\n",
name = old_test.name
);
}
} else if let Some(old_test) = tests.err.insert(test.name.clone(), test) {
anyhow::bail!(
"Duplicate test found: {name:?} (search '// test_err {name}' for the location)\n",
name = old_test.name
);
}
}
}
Ok(tests)
}
}
#[derive(Debug, Clone, Copy)]
enum TestKind {
Ok,
Err,
}
/// A test of the following form:
///
/// ```text
/// // (test_ok|test_err) name
/// // <code>
/// ```
#[derive(Debug)]
struct Test {
name: String,
contents: String,
kind: TestKind,
}
impl Test {
const fn is_ok(&self) -> bool {
matches!(self.kind, TestKind::Ok)
}
}
/// Collect the tests from the given source text.
fn collect_tests(text: &str) -> Vec<Test> {
let mut tests = Vec::new();
for comment_block in extract_comment_blocks(text) {
let first_line = &comment_block[0];
let (kind, name) = match first_line.split_once(' ') {
Some(("test_ok", suffix)) => (TestKind::Ok, suffix),
Some(("test_err", suffix)) => (TestKind::Err, suffix),
_ => continue,
};
let text: String = comment_block[1..]
.iter()
.cloned()
.chain([String::new()])
.collect::<Vec<_>>()
.join("\n");
assert!(!text.trim().is_empty() && text.ends_with('\n'));
tests.push(Test {
name: name.to_string(),
contents: text,
kind,
});
}
tests
}
#[derive(Debug, Default)]
struct CommentBlock(Vec<String>);
impl Deref for CommentBlock {
type Target = Vec<String>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl DerefMut for CommentBlock {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
/// Extract the comment blocks from the given source text.
///
/// A comment block is a sequence of lines that start with `// ` and are separated
/// by an empty line. An empty comment line (`//`) is also part of the block.
fn extract_comment_blocks(text: &str) -> Vec<CommentBlock> {
const COMMENT_PREFIX: &str = "// ";
const COMMENT_PREFIX_LEN: usize = COMMENT_PREFIX.len();
let mut comment_blocks = Vec::new();
let mut block = CommentBlock::default();
for line in text.lines().map(str::trim_start) {
if line == "//" {
block.push(String::new());
continue;
}
if line.starts_with(COMMENT_PREFIX) {
block.push(line[COMMENT_PREFIX_LEN..].to_string());
} else {
if !block.is_empty() {
comment_blocks.push(std::mem::take(&mut block));
}
}
}
if !block.is_empty() {
comment_blocks.push(block);
}
comment_blocks
}
/// Returns the existing tests in the given directory.
fn existing_tests(dir: &Path) -> Result<HashMap<String, PathBuf>> {
let mut tests = HashMap::new();
for file in fs::read_dir(dir)? {
let path = file?.path();
if path.extension().unwrap_or_default() != "py" {
continue;
}
let name = path
.file_stem()
.map(|x| x.to_string_lossy().to_string())
.unwrap();
if let Some(old) = tests.insert(name, path) {
anyhow::bail!("Multiple test file exists for {old:?}");
}
}
Ok(tests)
}

View file

@ -0,0 +1,200 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/ann_assign_stmt_invalid_annotation.py
---
## AST
```
Module(
ModModule {
range: 0..63,
body: [
AnnAssign(
StmtAnnAssign {
range: 0..11,
target: Name(
ExprName {
range: 0..1,
id: "x",
ctx: Store,
},
),
annotation: Starred(
ExprStarred {
range: 3..7,
value: Name(
ExprName {
range: 4..7,
id: "int",
ctx: Load,
},
),
ctx: Load,
},
),
value: Some(
NumberLiteral(
ExprNumberLiteral {
range: 10..11,
value: Int(
1,
),
},
),
),
simple: true,
},
),
AnnAssign(
StmtAnnAssign {
range: 12..26,
target: Name(
ExprName {
range: 12..13,
id: "x",
ctx: Store,
},
),
annotation: Yield(
ExprYield {
range: 15..22,
value: Some(
Name(
ExprName {
range: 21..22,
id: "a",
ctx: Load,
},
),
),
},
),
value: Some(
NumberLiteral(
ExprNumberLiteral {
range: 25..26,
value: Int(
1,
),
},
),
),
simple: true,
},
),
AnnAssign(
StmtAnnAssign {
range: 27..46,
target: Name(
ExprName {
range: 27..28,
id: "x",
ctx: Store,
},
),
annotation: YieldFrom(
ExprYieldFrom {
range: 30..42,
value: Name(
ExprName {
range: 41..42,
id: "b",
ctx: Load,
},
),
},
),
value: Some(
NumberLiteral(
ExprNumberLiteral {
range: 45..46,
value: Int(
1,
),
},
),
),
simple: true,
},
),
AnnAssign(
StmtAnnAssign {
range: 47..51,
target: Name(
ExprName {
range: 47..48,
id: "x",
ctx: Store,
},
),
annotation: Name(
ExprName {
range: 50..51,
id: "y",
ctx: Load,
},
),
value: None,
simple: true,
},
),
Assign(
StmtAssign {
range: 55..62,
targets: [
Name(
ExprName {
range: 55..58,
id: "int",
ctx: Store,
},
),
],
value: NumberLiteral(
ExprNumberLiteral {
range: 61..62,
value: Int(
1,
),
},
),
},
),
],
},
)
```
## Errors
|
1 | x: *int = 1
| ^^^^ Syntax Error: Starred expression cannot be used here
2 | x: yield a = 1
3 | x: yield from b = 1
|
|
1 | x: *int = 1
2 | x: yield a = 1
| ^^^^^^^ Syntax Error: Yield expression cannot be used here
3 | x: yield from b = 1
4 | x: y := int = 1
|
|
1 | x: *int = 1
2 | x: yield a = 1
3 | x: yield from b = 1
| ^^^^^^^^^^^^ Syntax Error: Yield expression cannot be used here
4 | x: y := int = 1
|
|
2 | x: yield a = 1
3 | x: yield from b = 1
4 | x: y := int = 1
| ^^ Syntax Error: Expected a statement
|

View file

@ -0,0 +1,508 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/ann_assign_stmt_invalid_target.py
---
## AST
```
Module(
ModModule {
range: 0..170,
body: [
AnnAssign(
StmtAnnAssign {
range: 0..18,
target: StringLiteral(
ExprStringLiteral {
range: 0..5,
value: StringLiteralValue {
inner: Single(
StringLiteral {
range: 0..5,
value: "abc",
flags: StringLiteralFlags {
quote_style: Double,
prefix: Empty,
triple_quoted: false,
},
},
),
},
},
),
annotation: Name(
ExprName {
range: 7..10,
id: "str",
ctx: Load,
},
),
value: Some(
StringLiteral(
ExprStringLiteral {
range: 13..18,
value: StringLiteralValue {
inner: Single(
StringLiteral {
range: 13..18,
value: "def",
flags: StringLiteralFlags {
quote_style: Double,
prefix: Empty,
triple_quoted: false,
},
},
),
},
},
),
),
simple: false,
},
),
AnnAssign(
StmtAnnAssign {
range: 19..37,
target: Call(
ExprCall {
range: 19..25,
func: Name(
ExprName {
range: 19..23,
id: "call",
ctx: Load,
},
),
arguments: Arguments {
range: 23..25,
args: [],
keywords: [],
},
},
),
annotation: Name(
ExprName {
range: 27..30,
id: "str",
ctx: Load,
},
),
value: Some(
StringLiteral(
ExprStringLiteral {
range: 33..37,
value: StringLiteralValue {
inner: Single(
StringLiteral {
range: 33..37,
value: "no",
flags: StringLiteralFlags {
quote_style: Double,
prefix: Empty,
triple_quoted: false,
},
},
),
},
},
),
),
simple: false,
},
),
AnnAssign(
StmtAnnAssign {
range: 38..52,
target: Starred(
ExprStarred {
range: 38..40,
value: Name(
ExprName {
range: 39..40,
id: "x",
ctx: Store,
},
),
ctx: Store,
},
),
annotation: Name(
ExprName {
range: 42..45,
id: "int",
ctx: Load,
},
),
value: Some(
Tuple(
ExprTuple {
range: 48..52,
elts: [
NumberLiteral(
ExprNumberLiteral {
range: 48..49,
value: Int(
1,
),
},
),
NumberLiteral(
ExprNumberLiteral {
range: 51..52,
value: Int(
2,
),
},
),
],
ctx: Load,
parenthesized: false,
},
),
),
simple: false,
},
),
AnnAssign(
StmtAnnAssign {
range: 72..83,
target: Tuple(
ExprTuple {
range: 72..74,
elts: [
Name(
ExprName {
range: 72..73,
id: "x",
ctx: Store,
},
),
],
ctx: Store,
parenthesized: false,
},
),
annotation: Name(
ExprName {
range: 76..79,
id: "int",
ctx: Load,
},
),
value: Some(
NumberLiteral(
ExprNumberLiteral {
range: 82..83,
value: Int(
1,
),
},
),
),
simple: false,
},
),
AnnAssign(
StmtAnnAssign {
range: 84..100,
target: Tuple(
ExprTuple {
range: 84..88,
elts: [
Name(
ExprName {
range: 84..85,
id: "x",
ctx: Store,
},
),
Name(
ExprName {
range: 87..88,
id: "y",
ctx: Store,
},
),
],
ctx: Store,
parenthesized: false,
},
),
annotation: Name(
ExprName {
range: 90..93,
id: "int",
ctx: Load,
},
),
value: Some(
Tuple(
ExprTuple {
range: 96..100,
elts: [
NumberLiteral(
ExprNumberLiteral {
range: 96..97,
value: Int(
1,
),
},
),
NumberLiteral(
ExprNumberLiteral {
range: 99..100,
value: Int(
2,
),
},
),
],
ctx: Load,
parenthesized: false,
},
),
),
simple: false,
},
),
AnnAssign(
StmtAnnAssign {
range: 101..119,
target: Tuple(
ExprTuple {
range: 101..107,
elts: [
Name(
ExprName {
range: 102..103,
id: "x",
ctx: Store,
},
),
Name(
ExprName {
range: 105..106,
id: "y",
ctx: Store,
},
),
],
ctx: Store,
parenthesized: true,
},
),
annotation: Name(
ExprName {
range: 109..112,
id: "int",
ctx: Load,
},
),
value: Some(
Tuple(
ExprTuple {
range: 115..119,
elts: [
NumberLiteral(
ExprNumberLiteral {
range: 115..116,
value: Int(
1,
),
},
),
NumberLiteral(
ExprNumberLiteral {
range: 118..119,
value: Int(
2,
),
},
),
],
ctx: Load,
parenthesized: false,
},
),
),
simple: false,
},
),
AnnAssign(
StmtAnnAssign {
range: 138..150,
target: List(
ExprList {
range: 138..141,
elts: [
Name(
ExprName {
range: 139..140,
id: "x",
ctx: Store,
},
),
],
ctx: Store,
},
),
annotation: Name(
ExprName {
range: 143..146,
id: "int",
ctx: Load,
},
),
value: Some(
NumberLiteral(
ExprNumberLiteral {
range: 149..150,
value: Int(
1,
),
},
),
),
simple: false,
},
),
AnnAssign(
StmtAnnAssign {
range: 151..169,
target: List(
ExprList {
range: 151..157,
elts: [
Name(
ExprName {
range: 152..153,
id: "x",
ctx: Store,
},
),
Name(
ExprName {
range: 155..156,
id: "y",
ctx: Store,
},
),
],
ctx: Store,
},
),
annotation: Name(
ExprName {
range: 159..162,
id: "int",
ctx: Load,
},
),
value: Some(
Tuple(
ExprTuple {
range: 165..169,
elts: [
NumberLiteral(
ExprNumberLiteral {
range: 165..166,
value: Int(
1,
),
},
),
NumberLiteral(
ExprNumberLiteral {
range: 168..169,
value: Int(
2,
),
},
),
],
ctx: Load,
parenthesized: false,
},
),
),
simple: false,
},
),
],
},
)
```
## Errors
|
1 | "abc": str = "def"
| ^^^^^ Syntax Error: Invalid annotated assignment target
2 | call(): str = "no"
3 | *x: int = 1, 2
|
|
1 | "abc": str = "def"
2 | call(): str = "no"
| ^^^^^^ Syntax Error: Invalid annotated assignment target
3 | *x: int = 1, 2
4 | # Tuple assignment
|
|
1 | "abc": str = "def"
2 | call(): str = "no"
3 | *x: int = 1, 2
| ^^ Syntax Error: Invalid annotated assignment target
4 | # Tuple assignment
5 | x,: int = 1
|
|
3 | *x: int = 1, 2
4 | # Tuple assignment
5 | x,: int = 1
| ^^ Syntax Error: Only single target (not tuple) can be annotated
6 | x, y: int = 1, 2
7 | (x, y): int = 1, 2
|
|
4 | # Tuple assignment
5 | x,: int = 1
6 | x, y: int = 1, 2
| ^^^^ Syntax Error: Only single target (not tuple) can be annotated
7 | (x, y): int = 1, 2
8 | # List assignment
|
|
5 | x,: int = 1
6 | x, y: int = 1, 2
7 | (x, y): int = 1, 2
| ^^^^^^ Syntax Error: Only single target (not tuple) can be annotated
8 | # List assignment
9 | [x]: int = 1
|
|
7 | (x, y): int = 1, 2
8 | # List assignment
9 | [x]: int = 1
| ^^^ Syntax Error: Only single target (not list) can be annotated
10 | [x, y]: int = 1, 2
|
|
8 | # List assignment
9 | [x]: int = 1
10 | [x, y]: int = 1, 2
| ^^^^^^ Syntax Error: Only single target (not list) can be annotated
|

View file

@ -0,0 +1,222 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/ann_assign_stmt_invalid_value.py
---
## AST
```
Module(
ModModule {
range: 0..65,
body: [
AnnAssign(
StmtAnnAssign {
range: 0..17,
target: Name(
ExprName {
range: 0..1,
id: "x",
ctx: Store,
},
),
annotation: Name(
ExprName {
range: 3..6,
id: "Any",
ctx: Load,
},
),
value: Some(
Starred(
ExprStarred {
range: 9..17,
value: BoolOp(
ExprBoolOp {
range: 10..17,
op: And,
values: [
Name(
ExprName {
range: 10..11,
id: "a",
ctx: Load,
},
),
Name(
ExprName {
range: 16..17,
id: "b",
ctx: Load,
},
),
],
},
),
ctx: Load,
},
),
),
simple: true,
},
),
AnnAssign(
StmtAnnAssign {
range: 18..28,
target: Name(
ExprName {
range: 18..19,
id: "x",
ctx: Store,
},
),
annotation: Name(
ExprName {
range: 21..24,
id: "Any",
ctx: Load,
},
),
value: Some(
Name(
ExprName {
range: 27..28,
id: "x",
ctx: Load,
},
),
),
simple: true,
},
),
Expr(
StmtExpr {
range: 32..33,
value: NumberLiteral(
ExprNumberLiteral {
range: 32..33,
value: Int(
1,
),
},
),
},
),
AnnAssign(
StmtAnnAssign {
range: 34..64,
target: Name(
ExprName {
range: 34..35,
id: "x",
ctx: Store,
},
),
annotation: Name(
ExprName {
range: 37..41,
id: "list",
ctx: Load,
},
),
value: Some(
List(
ExprList {
range: 44..64,
elts: [
Name(
ExprName {
range: 45..46,
id: "x",
ctx: Load,
},
),
Starred(
ExprStarred {
range: 48..54,
value: BinOp(
ExprBinOp {
range: 49..54,
left: Name(
ExprName {
range: 49..50,
id: "a",
ctx: Load,
},
),
op: BitOr,
right: Name(
ExprName {
range: 53..54,
id: "b",
ctx: Load,
},
),
},
),
ctx: Load,
},
),
Starred(
ExprStarred {
range: 56..63,
value: BoolOp(
ExprBoolOp {
range: 57..63,
op: Or,
values: [
Name(
ExprName {
range: 57..58,
id: "a",
ctx: Load,
},
),
Name(
ExprName {
range: 62..63,
id: "b",
ctx: Load,
},
),
],
},
),
ctx: Load,
},
),
],
ctx: Load,
},
),
),
simple: true,
},
),
],
},
)
```
## Errors
|
1 | x: Any = *a and b
| ^^^^^^^ Syntax Error: Boolean expression cannot be used here
2 | x: Any = x := 1
3 | x: list = [x, *a | b, *a or b]
|
|
1 | x: Any = *a and b
2 | x: Any = x := 1
| ^^ Syntax Error: Expected a statement
3 | x: list = [x, *a | b, *a or b]
|
|
1 | x: Any = *a and b
2 | x: Any = x := 1
3 | x: list = [x, *a | b, *a or b]
| ^^^^^^ Syntax Error: Boolean expression cannot be used here
|

View file

@ -0,0 +1,42 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/ann_assign_stmt_missing_rhs.py
---
## AST
```
Module(
ModModule {
range: 0..9,
body: [
AnnAssign(
StmtAnnAssign {
range: 0..8,
target: Name(
ExprName {
range: 0..1,
id: "x",
ctx: Store,
},
),
annotation: Name(
ExprName {
range: 3..6,
id: "int",
ctx: Load,
},
),
value: None,
simple: true,
},
),
],
},
)
```
## Errors
|
1 | x: int =
| ^ Syntax Error: Expected an expression
|

View file

@ -0,0 +1,108 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/ann_assign_stmt_type_alias_annotation.py
---
## AST
```
Module(
ModModule {
range: 0..37,
body: [
AnnAssign(
StmtAnnAssign {
range: 0..2,
target: Name(
ExprName {
range: 0..1,
id: "a",
ctx: Store,
},
),
annotation: Name(
ExprName {
range: 2..2,
id: "",
ctx: Invalid,
},
),
value: None,
simple: true,
},
),
TypeAlias(
StmtTypeAlias {
range: 3..15,
name: Name(
ExprName {
range: 8..9,
id: "X",
ctx: Store,
},
),
type_params: None,
value: Name(
ExprName {
range: 12..15,
id: "int",
ctx: Load,
},
),
},
),
Expr(
StmtExpr {
range: 16..23,
value: Lambda(
ExprLambda {
range: 16..23,
parameters: None,
body: Name(
ExprName {
range: 23..23,
id: "",
ctx: Invalid,
},
),
},
),
},
),
TypeAlias(
StmtTypeAlias {
range: 24..36,
name: Name(
ExprName {
range: 29..30,
id: "X",
ctx: Store,
},
),
type_params: None,
value: Name(
ExprName {
range: 33..36,
id: "int",
ctx: Load,
},
),
},
),
],
},
)
```
## Errors
|
1 | a: type X = int
| ^^^^ Syntax Error: Expected an expression
2 | lambda: type X = int
|
|
1 | a: type X = int
2 | lambda: type X = int
| ^^^^ Syntax Error: Expected an expression
|

View file

@ -0,0 +1,34 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/assert_empty_msg.py
---
## AST
```
Module(
ModModule {
range: 0..10,
body: [
Assert(
StmtAssert {
range: 0..9,
test: Name(
ExprName {
range: 7..8,
id: "x",
ctx: Load,
},
),
msg: None,
},
),
],
},
)
```
## Errors
|
1 | assert x,
| ^ Syntax Error: Expected an expression
|

View file

@ -0,0 +1,34 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/assert_empty_test.py
---
## AST
```
Module(
ModModule {
range: 0..7,
body: [
Assert(
StmtAssert {
range: 0..6,
test: Name(
ExprName {
range: 6..6,
id: "",
ctx: Invalid,
},
),
msg: None,
},
),
],
},
)
```
## Errors
|
1 | assert
| ^ Syntax Error: Expected an expression
|

View file

@ -0,0 +1,160 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/assert_invalid_msg_expr.py
---
## AST
```
Module(
ModModule {
range: 0..83,
body: [
Assert(
StmtAssert {
range: 0..16,
test: BooleanLiteral(
ExprBooleanLiteral {
range: 7..12,
value: false,
},
),
msg: Some(
Starred(
ExprStarred {
range: 14..16,
value: Name(
ExprName {
range: 15..16,
id: "x",
ctx: Load,
},
),
ctx: Load,
},
),
),
},
),
Assert(
StmtAssert {
range: 17..30,
test: BooleanLiteral(
ExprBooleanLiteral {
range: 24..29,
value: false,
},
),
msg: None,
},
),
Assert(
StmtAssert {
range: 31..39,
test: Name(
ExprName {
range: 38..39,
id: "x",
ctx: Load,
},
),
msg: None,
},
),
Assert(
StmtAssert {
range: 40..61,
test: BooleanLiteral(
ExprBooleanLiteral {
range: 47..52,
value: false,
},
),
msg: Some(
Yield(
ExprYield {
range: 54..61,
value: Some(
Name(
ExprName {
range: 60..61,
id: "x",
ctx: Load,
},
),
),
},
),
),
},
),
Assert(
StmtAssert {
range: 62..77,
test: BooleanLiteral(
ExprBooleanLiteral {
range: 69..74,
value: false,
},
),
msg: Some(
Name(
ExprName {
range: 76..77,
id: "x",
ctx: Load,
},
),
),
},
),
Expr(
StmtExpr {
range: 81..82,
value: NumberLiteral(
ExprNumberLiteral {
range: 81..82,
value: Int(
1,
),
},
),
},
),
],
},
)
```
## Errors
|
1 | assert False, *x
| ^^ Syntax Error: Starred expression cannot be used here
2 | assert False, assert x
3 | assert False, yield x
|
|
1 | assert False, *x
2 | assert False, assert x
| ^^^^^^ Syntax Error: Expected an expression
3 | assert False, yield x
4 | assert False, x := 1
|
|
1 | assert False, *x
2 | assert False, assert x
3 | assert False, yield x
| ^^^^^^^ Syntax Error: Yield expression cannot be used here
4 | assert False, x := 1
|
|
2 | assert False, assert x
3 | assert False, yield x
4 | assert False, x := 1
| ^^ Syntax Error: Expected a statement
|

View file

@ -0,0 +1,148 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/assert_invalid_test_expr.py
---
## AST
```
Module(
ModModule {
range: 0..55,
body: [
Assert(
StmtAssert {
range: 0..9,
test: Starred(
ExprStarred {
range: 7..9,
value: Name(
ExprName {
range: 8..9,
id: "x",
ctx: Load,
},
),
ctx: Load,
},
),
msg: None,
},
),
Assert(
StmtAssert {
range: 10..23,
test: Name(
ExprName {
range: 17..23,
id: "assert",
ctx: Load,
},
),
msg: None,
},
),
Expr(
StmtExpr {
range: 24..25,
value: Name(
ExprName {
range: 24..25,
id: "x",
ctx: Load,
},
),
},
),
Assert(
StmtAssert {
range: 26..40,
test: Yield(
ExprYield {
range: 33..40,
value: Some(
Name(
ExprName {
range: 39..40,
id: "x",
ctx: Load,
},
),
),
},
),
msg: None,
},
),
Assert(
StmtAssert {
range: 41..49,
test: Name(
ExprName {
range: 48..49,
id: "x",
ctx: Load,
},
),
msg: None,
},
),
Expr(
StmtExpr {
range: 53..54,
value: NumberLiteral(
ExprNumberLiteral {
range: 53..54,
value: Int(
1,
),
},
),
},
),
],
},
)
```
## Errors
|
1 | assert *x
| ^^ Syntax Error: Starred expression cannot be used here
2 | assert assert x
3 | assert yield x
|
|
1 | assert *x
2 | assert assert x
| ^^^^^^ Syntax Error: Expected an identifier, but found a keyword 'assert' that cannot be used here
3 | assert yield x
4 | assert x := 1
|
|
1 | assert *x
2 | assert assert x
| ^ Syntax Error: Simple statements must be separated by newlines or semicolons
3 | assert yield x
4 | assert x := 1
|
|
1 | assert *x
2 | assert assert x
3 | assert yield x
| ^^^^^^^ Syntax Error: Yield expression cannot be used here
4 | assert x := 1
|
|
2 | assert assert x
3 | assert yield x
4 | assert x := 1
| ^^ Syntax Error: Expected a statement
|

View file

@ -0,0 +1,258 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/assign_stmt_invalid_target.py
---
## AST
```
Module(
ModModule {
range: 0..58,
body: [
Assign(
StmtAssign {
range: 0..5,
targets: [
NumberLiteral(
ExprNumberLiteral {
range: 0..1,
value: Int(
1,
),
},
),
],
value: NumberLiteral(
ExprNumberLiteral {
range: 4..5,
value: Int(
1,
),
},
),
},
),
Assign(
StmtAssign {
range: 6..15,
targets: [
Name(
ExprName {
range: 6..7,
id: "x",
ctx: Store,
},
),
NumberLiteral(
ExprNumberLiteral {
range: 10..11,
value: Int(
1,
),
},
),
],
value: NumberLiteral(
ExprNumberLiteral {
range: 14..15,
value: Int(
2,
),
},
),
},
),
Assign(
StmtAssign {
range: 16..33,
targets: [
Name(
ExprName {
range: 16..17,
id: "x",
ctx: Store,
},
),
NumberLiteral(
ExprNumberLiteral {
range: 20..21,
value: Int(
1,
),
},
),
Name(
ExprName {
range: 24..25,
id: "y",
ctx: Store,
},
),
NumberLiteral(
ExprNumberLiteral {
range: 28..29,
value: Int(
2,
),
},
),
],
value: Name(
ExprName {
range: 32..33,
id: "z",
ctx: Load,
},
),
},
),
Assign(
StmtAssign {
range: 34..57,
targets: [
List(
ExprList {
range: 34..44,
elts: [
StringLiteral(
ExprStringLiteral {
range: 35..38,
value: StringLiteralValue {
inner: Single(
StringLiteral {
range: 35..38,
value: "a",
flags: StringLiteralFlags {
quote_style: Double,
prefix: Empty,
triple_quoted: false,
},
},
),
},
},
),
StringLiteral(
ExprStringLiteral {
range: 40..43,
value: StringLiteralValue {
inner: Single(
StringLiteral {
range: 40..43,
value: "b",
flags: StringLiteralFlags {
quote_style: Double,
prefix: Empty,
triple_quoted: false,
},
},
),
},
},
),
],
ctx: Store,
},
),
],
value: List(
ExprList {
range: 47..57,
elts: [
StringLiteral(
ExprStringLiteral {
range: 48..51,
value: StringLiteralValue {
inner: Single(
StringLiteral {
range: 48..51,
value: "a",
flags: StringLiteralFlags {
quote_style: Double,
prefix: Empty,
triple_quoted: false,
},
},
),
},
},
),
StringLiteral(
ExprStringLiteral {
range: 53..56,
value: StringLiteralValue {
inner: Single(
StringLiteral {
range: 53..56,
value: "b",
flags: StringLiteralFlags {
quote_style: Double,
prefix: Empty,
triple_quoted: false,
},
},
),
},
},
),
],
ctx: Load,
},
),
},
),
],
},
)
```
## Errors
|
1 | 1 = 1
| ^ Syntax Error: Invalid assignment target
2 | x = 1 = 2
3 | x = 1 = y = 2 = z
|
|
1 | 1 = 1
2 | x = 1 = 2
| ^ Syntax Error: Invalid assignment target
3 | x = 1 = y = 2 = z
4 | ["a", "b"] = ["a", "b"]
|
|
1 | 1 = 1
2 | x = 1 = 2
3 | x = 1 = y = 2 = z
| ^ Syntax Error: Invalid assignment target
4 | ["a", "b"] = ["a", "b"]
|
|
1 | 1 = 1
2 | x = 1 = 2
3 | x = 1 = y = 2 = z
| ^ Syntax Error: Invalid assignment target
4 | ["a", "b"] = ["a", "b"]
|
|
2 | x = 1 = 2
3 | x = 1 = y = 2 = z
4 | ["a", "b"] = ["a", "b"]
| ^^^ Syntax Error: Invalid assignment target
|
|
2 | x = 1 = 2
3 | x = 1 = y = 2 = z
4 | ["a", "b"] = ["a", "b"]
| ^^^ Syntax Error: Invalid assignment target
|

View file

@ -0,0 +1,256 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/assign_stmt_invalid_value_expr.py
---
## AST
```
Module(
ModModule {
range: 0..72,
body: [
Assign(
StmtAssign {
range: 0..12,
targets: [
Name(
ExprName {
range: 0..1,
id: "x",
ctx: Store,
},
),
],
value: Starred(
ExprStarred {
range: 4..12,
value: BoolOp(
ExprBoolOp {
range: 5..12,
op: And,
values: [
Name(
ExprName {
range: 5..6,
id: "a",
ctx: Load,
},
),
Name(
ExprName {
range: 11..12,
id: "b",
ctx: Load,
},
),
],
},
),
ctx: Load,
},
),
},
),
Assign(
StmtAssign {
range: 13..25,
targets: [
Name(
ExprName {
range: 13..14,
id: "x",
ctx: Store,
},
),
],
value: Starred(
ExprStarred {
range: 17..25,
value: Yield(
ExprYield {
range: 18..25,
value: Some(
Name(
ExprName {
range: 24..25,
id: "x",
ctx: Load,
},
),
),
},
),
ctx: Load,
},
),
},
),
Assign(
StmtAssign {
range: 26..43,
targets: [
Name(
ExprName {
range: 26..27,
id: "x",
ctx: Store,
},
),
],
value: Starred(
ExprStarred {
range: 30..43,
value: YieldFrom(
ExprYieldFrom {
range: 31..43,
value: Name(
ExprName {
range: 42..43,
id: "x",
ctx: Load,
},
),
},
),
ctx: Load,
},
),
},
),
Assign(
StmtAssign {
range: 44..60,
targets: [
Name(
ExprName {
range: 44..45,
id: "x",
ctx: Store,
},
),
],
value: Starred(
ExprStarred {
range: 48..60,
value: Lambda(
ExprLambda {
range: 49..60,
parameters: Some(
Parameters {
range: 56..57,
posonlyargs: [],
args: [
ParameterWithDefault {
range: 56..57,
parameter: Parameter {
range: 56..57,
name: Identifier {
id: "x",
range: 56..57,
},
annotation: None,
},
default: None,
},
],
vararg: None,
kwonlyargs: [],
kwarg: None,
},
),
body: Name(
ExprName {
range: 59..60,
id: "x",
ctx: Load,
},
),
},
),
ctx: Load,
},
),
},
),
Assign(
StmtAssign {
range: 61..66,
targets: [
Name(
ExprName {
range: 61..62,
id: "x",
ctx: Store,
},
),
],
value: Name(
ExprName {
range: 65..66,
id: "x",
ctx: Load,
},
),
},
),
Expr(
StmtExpr {
range: 70..71,
value: NumberLiteral(
ExprNumberLiteral {
range: 70..71,
value: Int(
1,
),
},
),
},
),
],
},
)
```
## Errors
|
1 | x = *a and b
| ^^^^^^^ Syntax Error: Boolean expression cannot be used here
2 | x = *yield x
3 | x = *yield from x
|
|
1 | x = *a and b
2 | x = *yield x
| ^^^^^^^ Syntax Error: Yield expression cannot be used here
3 | x = *yield from x
4 | x = *lambda x: x
|
|
1 | x = *a and b
2 | x = *yield x
3 | x = *yield from x
| ^^^^^^^^^^^^ Syntax Error: Yield expression cannot be used here
4 | x = *lambda x: x
5 | x = x := 1
|
|
2 | x = *yield x
3 | x = *yield from x
4 | x = *lambda x: x
| ^^^^^^^^^^^ Syntax Error: Lambda expression cannot be used here
5 | x = x := 1
|
|
3 | x = *yield from x
4 | x = *lambda x: x
5 | x = x := 1
| ^^ Syntax Error: Expected a statement
|

View file

@ -0,0 +1,145 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/assign_stmt_keyword_target.py
---
## AST
```
Module(
ModModule {
range: 0..42,
body: [
Assign(
StmtAssign {
range: 0..12,
targets: [
Name(
ExprName {
range: 0..1,
id: "a",
ctx: Store,
},
),
Name(
ExprName {
range: 4..8,
id: "pass",
ctx: Store,
},
),
],
value: Name(
ExprName {
range: 11..12,
id: "c",
ctx: Load,
},
),
},
),
Expr(
StmtExpr {
range: 13..18,
value: BinOp(
ExprBinOp {
range: 13..18,
left: Name(
ExprName {
range: 13..14,
id: "a",
ctx: Load,
},
),
op: Add,
right: Name(
ExprName {
range: 17..18,
id: "b",
ctx: Load,
},
),
},
),
},
),
Assign(
StmtAssign {
range: 19..35,
targets: [
Name(
ExprName {
range: 19..20,
id: "a",
ctx: Store,
},
),
Name(
ExprName {
range: 23..24,
id: "b",
ctx: Store,
},
),
Name(
ExprName {
range: 27..31,
id: "pass",
ctx: Store,
},
),
],
value: Name(
ExprName {
range: 34..35,
id: "c",
ctx: Load,
},
),
},
),
Expr(
StmtExpr {
range: 36..41,
value: BinOp(
ExprBinOp {
range: 36..41,
left: Name(
ExprName {
range: 36..37,
id: "a",
ctx: Load,
},
),
op: Add,
right: Name(
ExprName {
range: 40..41,
id: "b",
ctx: Load,
},
),
},
),
},
),
],
},
)
```
## Errors
|
1 | a = pass = c
| ^^^^ Syntax Error: Expected an identifier, but found a keyword 'pass' that cannot be used here
2 | a + b
3 | a = b = pass = c
|
|
1 | a = pass = c
2 | a + b
3 | a = b = pass = c
| ^^^^ Syntax Error: Expected an identifier, but found a keyword 'pass' that cannot be used here
4 | a + b
|

View file

@ -0,0 +1,202 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/assign_stmt_missing_rhs.py
---
## AST
```
Module(
ModModule {
range: 0..38,
body: [
Assign(
StmtAssign {
range: 0..3,
targets: [
Name(
ExprName {
range: 0..1,
id: "x",
ctx: Store,
},
),
],
value: Name(
ExprName {
range: 3..3,
id: "",
ctx: Invalid,
},
),
},
),
Expr(
StmtExpr {
range: 4..9,
value: BinOp(
ExprBinOp {
range: 4..9,
left: NumberLiteral(
ExprNumberLiteral {
range: 4..5,
value: Int(
1,
),
},
),
op: Add,
right: NumberLiteral(
ExprNumberLiteral {
range: 8..9,
value: Int(
1,
),
},
),
},
),
},
),
Assign(
StmtAssign {
range: 10..17,
targets: [
Name(
ExprName {
range: 10..11,
id: "x",
ctx: Store,
},
),
Name(
ExprName {
range: 14..15,
id: "y",
ctx: Store,
},
),
],
value: Name(
ExprName {
range: 17..17,
id: "",
ctx: Invalid,
},
),
},
),
Expr(
StmtExpr {
range: 18..23,
value: BinOp(
ExprBinOp {
range: 18..23,
left: NumberLiteral(
ExprNumberLiteral {
range: 18..19,
value: Int(
2,
),
},
),
op: Add,
right: NumberLiteral(
ExprNumberLiteral {
range: 22..23,
value: Int(
2,
),
},
),
},
),
},
),
Assign(
StmtAssign {
range: 24..31,
targets: [
Name(
ExprName {
range: 24..25,
id: "x",
ctx: Store,
},
),
Name(
ExprName {
range: 27..27,
id: "",
ctx: Store,
},
),
],
value: Name(
ExprName {
range: 30..31,
id: "y",
ctx: Load,
},
),
},
),
Expr(
StmtExpr {
range: 32..37,
value: BinOp(
ExprBinOp {
range: 32..37,
left: NumberLiteral(
ExprNumberLiteral {
range: 32..33,
value: Int(
3,
),
},
),
op: Add,
right: NumberLiteral(
ExprNumberLiteral {
range: 36..37,
value: Int(
3,
),
},
),
},
),
},
),
],
},
)
```
## Errors
|
1 | x =
| ^ Syntax Error: Expected an expression
2 | 1 + 1
3 | x = y =
4 | 2 + 2
|
|
1 | x =
2 | 1 + 1
3 | x = y =
| ^ Syntax Error: Expected an expression
4 | 2 + 2
5 | x = = y
6 | 3 + 3
|
|
3 | x = y =
4 | 2 + 2
5 | x = = y
| ^ Syntax Error: Expected an expression
6 | 3 + 3
|

View file

@ -0,0 +1,257 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/async_unexpected_token.py
---
## AST
```
Module(
ModModule {
range: 0..220,
body: [
ClassDef(
StmtClassDef {
range: 6..20,
decorator_list: [],
name: Identifier {
id: "Foo",
range: 12..15,
},
type_params: None,
arguments: None,
body: [
Expr(
StmtExpr {
range: 17..20,
value: EllipsisLiteral(
ExprEllipsisLiteral {
range: 17..20,
},
),
},
),
],
},
),
While(
StmtWhile {
range: 27..42,
test: Name(
ExprName {
range: 33..37,
id: "test",
ctx: Load,
},
),
body: [
Expr(
StmtExpr {
range: 39..42,
value: EllipsisLiteral(
ExprEllipsisLiteral {
range: 39..42,
},
),
},
),
],
orelse: [],
},
),
Assign(
StmtAssign {
range: 49..54,
targets: [
Name(
ExprName {
range: 49..50,
id: "x",
ctx: Store,
},
),
],
value: NumberLiteral(
ExprNumberLiteral {
range: 53..54,
value: Int(
1,
),
},
),
},
),
FunctionDef(
StmtFunctionDef {
range: 61..81,
is_async: true,
decorator_list: [],
name: Identifier {
id: "foo",
range: 71..74,
},
type_params: None,
parameters: Parameters {
range: 74..76,
posonlyargs: [],
args: [],
vararg: None,
kwonlyargs: [],
kwarg: None,
},
returns: None,
body: [
Expr(
StmtExpr {
range: 78..81,
value: EllipsisLiteral(
ExprEllipsisLiteral {
range: 78..81,
},
),
},
),
],
},
),
Expr(
StmtExpr {
range: 192..197,
value: Name(
ExprName {
range: 192..197,
id: "match",
ctx: Load,
},
),
},
),
AnnAssign(
StmtAnnAssign {
range: 198..203,
target: Name(
ExprName {
range: 198..202,
id: "test",
ctx: Store,
},
),
annotation: Name(
ExprName {
range: 203..203,
id: "",
ctx: Invalid,
},
),
value: None,
simple: true,
},
),
AnnAssign(
StmtAnnAssign {
range: 213..219,
target: Name(
ExprName {
range: 213..214,
id: "_",
ctx: Store,
},
),
annotation: EllipsisLiteral(
ExprEllipsisLiteral {
range: 216..219,
},
),
value: None,
simple: true,
},
),
],
},
)
```
## Errors
|
1 | async class Foo: ...
| ^^^^^ Syntax Error: Expected 'def', 'with' or 'for' to follow 'async', found 'class'
2 | async while test: ...
3 | async x = 1
|
|
1 | async class Foo: ...
2 | async while test: ...
| ^^^^^ Syntax Error: Expected 'def', 'with' or 'for' to follow 'async', found 'while'
3 | async x = 1
4 | async async def foo(): ...
|
|
1 | async class Foo: ...
2 | async while test: ...
3 | async x = 1
| ^ Syntax Error: Expected 'def', 'with' or 'for' to follow 'async', found name
4 | async async def foo(): ...
5 | # TODO(dhruvmanila): Here, `match` is actually a Name token because
|
|
2 | async while test: ...
3 | async x = 1
4 | async async def foo(): ...
| ^^^^^ Syntax Error: Expected 'def', 'with' or 'for' to follow 'async', found 'async'
5 | # TODO(dhruvmanila): Here, `match` is actually a Name token because
6 | # of the soft keyword # transformer
|
|
5 | # TODO(dhruvmanila): Here, `match` is actually a Name token because
6 | # of the soft keyword # transformer
7 | async match test:
| ^^^^^ Syntax Error: Expected 'def', 'with' or 'for' to follow 'async', found name
8 | case _: ...
|
|
5 | # TODO(dhruvmanila): Here, `match` is actually a Name token because
6 | # of the soft keyword # transformer
7 | async match test:
| ^^^^ Syntax Error: Simple statements must be separated by newlines or semicolons
8 | case _: ...
|
|
5 | # TODO(dhruvmanila): Here, `match` is actually a Name token because
6 | # of the soft keyword # transformer
7 | async match test:
| ^ Syntax Error: Expected an expression
8 | case _: ...
|
|
6 | # of the soft keyword # transformer
7 | async match test:
8 | case _: ...
| ^^^^ Syntax Error: Unexpected indentation
|
|
6 | # of the soft keyword # transformer
7 | async match test:
8 | case _: ...
| ^^^^ Syntax Error: Expected a statement
|
|
7 | async match test:
8 | case _: ...
|

View file

@ -0,0 +1,232 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/aug_assign_stmt_invalid_target.py
---
## AST
```
Module(
ModModule {
range: 0..59,
body: [
AugAssign(
StmtAugAssign {
range: 0..6,
target: NumberLiteral(
ExprNumberLiteral {
range: 0..1,
value: Int(
1,
),
},
),
op: Add,
value: NumberLiteral(
ExprNumberLiteral {
range: 5..6,
value: Int(
1,
),
},
),
},
),
AugAssign(
StmtAugAssign {
range: 7..17,
target: StringLiteral(
ExprStringLiteral {
range: 7..10,
value: StringLiteralValue {
inner: Single(
StringLiteral {
range: 7..10,
value: "a",
flags: StringLiteralFlags {
quote_style: Double,
prefix: Empty,
triple_quoted: false,
},
},
),
},
},
),
op: Add,
value: StringLiteral(
ExprStringLiteral {
range: 14..17,
value: StringLiteralValue {
inner: Single(
StringLiteral {
range: 14..17,
value: "b",
flags: StringLiteralFlags {
quote_style: Double,
prefix: Empty,
triple_quoted: false,
},
},
),
},
},
),
},
),
AugAssign(
StmtAugAssign {
range: 18..25,
target: Starred(
ExprStarred {
range: 18..20,
value: Name(
ExprName {
range: 19..20,
id: "x",
ctx: Store,
},
),
ctx: Store,
},
),
op: Add,
value: NumberLiteral(
ExprNumberLiteral {
range: 24..25,
value: Int(
1,
),
},
),
},
),
Pass(
StmtPass {
range: 26..30,
},
),
Expr(
StmtExpr {
range: 34..35,
value: NumberLiteral(
ExprNumberLiteral {
range: 34..35,
value: Int(
1,
),
},
),
},
),
AugAssign(
StmtAugAssign {
range: 36..45,
target: Name(
ExprName {
range: 36..37,
id: "x",
ctx: Store,
},
),
op: Add,
value: Name(
ExprName {
range: 41..45,
id: "pass",
ctx: Load,
},
),
},
),
AugAssign(
StmtAugAssign {
range: 46..58,
target: BinOp(
ExprBinOp {
range: 47..52,
left: Name(
ExprName {
range: 47..48,
id: "x",
ctx: Load,
},
),
op: Add,
right: Name(
ExprName {
range: 51..52,
id: "y",
ctx: Load,
},
),
},
),
op: Add,
value: NumberLiteral(
ExprNumberLiteral {
range: 57..58,
value: Int(
1,
),
},
),
},
),
],
},
)
```
## Errors
|
1 | 1 += 1
| ^ Syntax Error: Invalid augmented assignment target
2 | "a" += "b"
3 | *x += 1
|
|
1 | 1 += 1
2 | "a" += "b"
| ^^^ Syntax Error: Invalid augmented assignment target
3 | *x += 1
4 | pass += 1
|
|
1 | 1 += 1
2 | "a" += "b"
3 | *x += 1
| ^^ Syntax Error: Invalid augmented assignment target
4 | pass += 1
5 | x += pass
|
|
2 | "a" += "b"
3 | *x += 1
4 | pass += 1
| ^^ Syntax Error: Expected a statement
5 | x += pass
6 | (x + y) += 1
|
|
3 | *x += 1
4 | pass += 1
5 | x += pass
| ^^^^ Syntax Error: Expected an identifier, but found a keyword 'pass' that cannot be used here
6 | (x + y) += 1
|
|
4 | pass += 1
5 | x += pass
6 | (x + y) += 1
| ^^^^^ Syntax Error: Invalid augmented assignment target
|

View file

@ -0,0 +1,251 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/aug_assign_stmt_invalid_value.py
---
## AST
```
Module(
ModModule {
range: 0..77,
body: [
AugAssign(
StmtAugAssign {
range: 0..13,
target: Name(
ExprName {
range: 0..1,
id: "x",
ctx: Store,
},
),
op: Add,
value: Starred(
ExprStarred {
range: 5..13,
value: BoolOp(
ExprBoolOp {
range: 6..13,
op: And,
values: [
Name(
ExprName {
range: 6..7,
id: "a",
ctx: Load,
},
),
Name(
ExprName {
range: 12..13,
id: "b",
ctx: Load,
},
),
],
},
),
ctx: Load,
},
),
},
),
AugAssign(
StmtAugAssign {
range: 14..27,
target: Name(
ExprName {
range: 14..15,
id: "x",
ctx: Store,
},
),
op: Add,
value: Starred(
ExprStarred {
range: 19..27,
value: Yield(
ExprYield {
range: 20..27,
value: Some(
Name(
ExprName {
range: 26..27,
id: "x",
ctx: Load,
},
),
),
},
),
ctx: Load,
},
),
},
),
AugAssign(
StmtAugAssign {
range: 28..46,
target: Name(
ExprName {
range: 28..29,
id: "x",
ctx: Store,
},
),
op: Add,
value: Starred(
ExprStarred {
range: 33..46,
value: YieldFrom(
ExprYieldFrom {
range: 34..46,
value: Name(
ExprName {
range: 45..46,
id: "x",
ctx: Load,
},
),
},
),
ctx: Load,
},
),
},
),
AugAssign(
StmtAugAssign {
range: 47..64,
target: Name(
ExprName {
range: 47..48,
id: "x",
ctx: Store,
},
),
op: Add,
value: Starred(
ExprStarred {
range: 52..64,
value: Lambda(
ExprLambda {
range: 53..64,
parameters: Some(
Parameters {
range: 60..61,
posonlyargs: [],
args: [
ParameterWithDefault {
range: 60..61,
parameter: Parameter {
range: 60..61,
name: Identifier {
id: "x",
range: 60..61,
},
annotation: None,
},
default: None,
},
],
vararg: None,
kwonlyargs: [],
kwarg: None,
},
),
body: Name(
ExprName {
range: 63..64,
id: "x",
ctx: Load,
},
),
},
),
ctx: Load,
},
),
},
),
AugAssign(
StmtAugAssign {
range: 65..71,
target: Name(
ExprName {
range: 65..66,
id: "x",
ctx: Store,
},
),
op: Add,
value: Name(
ExprName {
range: 70..71,
id: "y",
ctx: Load,
},
),
},
),
Expr(
StmtExpr {
range: 75..76,
value: NumberLiteral(
ExprNumberLiteral {
range: 75..76,
value: Int(
1,
),
},
),
},
),
],
},
)
```
## Errors
|
1 | x += *a and b
| ^^^^^^^ Syntax Error: Boolean expression cannot be used here
2 | x += *yield x
3 | x += *yield from x
|
|
1 | x += *a and b
2 | x += *yield x
| ^^^^^^^ Syntax Error: Yield expression cannot be used here
3 | x += *yield from x
4 | x += *lambda x: x
|
|
1 | x += *a and b
2 | x += *yield x
3 | x += *yield from x
| ^^^^^^^^^^^^ Syntax Error: Yield expression cannot be used here
4 | x += *lambda x: x
5 | x += y := 1
|
|
2 | x += *yield x
3 | x += *yield from x
4 | x += *lambda x: x
| ^^^^^^^^^^^ Syntax Error: Lambda expression cannot be used here
5 | x += y := 1
|
|
3 | x += *yield from x
4 | x += *lambda x: x
5 | x += y := 1
| ^^ Syntax Error: Expected a statement
|

View file

@ -0,0 +1,136 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/aug_assign_stmt_missing_rhs.py
---
## AST
```
Module(
ModModule {
range: 0..27,
body: [
AugAssign(
StmtAugAssign {
range: 0..4,
target: Name(
ExprName {
range: 0..1,
id: "x",
ctx: Store,
},
),
op: Add,
value: Name(
ExprName {
range: 4..4,
id: "",
ctx: Invalid,
},
),
},
),
Expr(
StmtExpr {
range: 5..10,
value: BinOp(
ExprBinOp {
range: 5..10,
left: NumberLiteral(
ExprNumberLiteral {
range: 5..6,
value: Int(
1,
),
},
),
op: Add,
right: NumberLiteral(
ExprNumberLiteral {
range: 9..10,
value: Int(
1,
),
},
),
},
),
},
),
AugAssign(
StmtAugAssign {
range: 11..17,
target: Name(
ExprName {
range: 11..12,
id: "x",
ctx: Store,
},
),
op: Add,
value: Name(
ExprName {
range: 16..17,
id: "y",
ctx: Load,
},
),
},
),
Expr(
StmtExpr {
range: 21..26,
value: BinOp(
ExprBinOp {
range: 21..26,
left: NumberLiteral(
ExprNumberLiteral {
range: 21..22,
value: Int(
2,
),
},
),
op: Add,
right: NumberLiteral(
ExprNumberLiteral {
range: 25..26,
value: Int(
2,
),
},
),
},
),
},
),
],
},
)
```
## Errors
|
1 | x +=
| ^ Syntax Error: Expected an expression
2 | 1 + 1
3 | x += y +=
4 | 2 + 2
|
|
1 | x +=
2 | 1 + 1
3 | x += y +=
| ^^ Syntax Error: Expected a statement
4 | 2 + 2
|
|
1 | x +=
2 | 1 + 1
3 | x += y +=
| ^ Syntax Error: Expected a statement
4 | 2 + 2
|

View file

@ -0,0 +1,85 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/class_def_empty_body.py
---
## AST
```
Module(
ModModule {
range: 0..31,
body: [
ClassDef(
StmtClassDef {
range: 0..10,
decorator_list: [],
name: Identifier {
id: "Foo",
range: 6..9,
},
type_params: None,
arguments: None,
body: [],
},
),
ClassDef(
StmtClassDef {
range: 11..23,
decorator_list: [],
name: Identifier {
id: "Foo",
range: 17..20,
},
type_params: None,
arguments: Some(
Arguments {
range: 20..22,
args: [],
keywords: [],
},
),
body: [],
},
),
Assign(
StmtAssign {
range: 24..30,
targets: [
Name(
ExprName {
range: 24..25,
id: "x",
ctx: Store,
},
),
],
value: NumberLiteral(
ExprNumberLiteral {
range: 28..30,
value: Int(
42,
),
},
),
},
),
],
},
)
```
## Errors
|
1 | class Foo:
2 | class Foo():
| ^^^^^ Syntax Error: Expected an indented block after `class` definition
3 | x = 42
|
|
1 | class Foo:
2 | class Foo():
3 | x = 42
| ^ Syntax Error: Expected an indented block after `class` definition
|

View file

@ -0,0 +1,140 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/class_def_missing_name.py
---
## AST
```
Module(
ModModule {
range: 0..53,
body: [
ClassDef(
StmtClassDef {
range: 0..11,
decorator_list: [],
name: Identifier {
id: "",
range: 5..5,
},
type_params: None,
arguments: None,
body: [
Expr(
StmtExpr {
range: 8..11,
value: EllipsisLiteral(
ExprEllipsisLiteral {
range: 8..11,
},
),
},
),
],
},
),
ClassDef(
StmtClassDef {
range: 12..25,
decorator_list: [],
name: Identifier {
id: "",
range: 17..17,
},
type_params: None,
arguments: Some(
Arguments {
range: 18..20,
args: [],
keywords: [],
},
),
body: [
Expr(
StmtExpr {
range: 22..25,
value: EllipsisLiteral(
ExprEllipsisLiteral {
range: 22..25,
},
),
},
),
],
},
),
ClassDef(
StmtClassDef {
range: 26..52,
decorator_list: [],
name: Identifier {
id: "",
range: 31..31,
},
type_params: None,
arguments: Some(
Arguments {
range: 32..47,
args: [],
keywords: [
Keyword {
range: 33..46,
arg: Some(
Identifier {
id: "metaclass",
range: 33..42,
},
),
value: Name(
ExprName {
range: 43..46,
id: "ABC",
ctx: Load,
},
),
},
],
},
),
body: [
Expr(
StmtExpr {
range: 49..52,
value: EllipsisLiteral(
ExprEllipsisLiteral {
range: 49..52,
},
),
},
),
],
},
),
],
},
)
```
## Errors
|
1 | class : ...
| ^ Syntax Error: Expected an identifier
2 | class (): ...
3 | class (metaclass=ABC): ...
|
|
1 | class : ...
2 | class (): ...
| ^ Syntax Error: Expected an identifier
3 | class (metaclass=ABC): ...
|
|
1 | class : ...
2 | class (): ...
3 | class (metaclass=ABC): ...
| ^ Syntax Error: Expected an identifier
|

View file

@ -0,0 +1,124 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/class_def_unclosed_type_param_list.py
---
## AST
```
Module(
ModModule {
range: 0..41,
body: [
ClassDef(
StmtClassDef {
range: 0..40,
decorator_list: [],
name: Identifier {
id: "Foo",
range: 6..9,
},
type_params: Some(
TypeParams {
range: 9..17,
type_params: [
TypeVar(
TypeParamTypeVar {
range: 10..12,
name: Identifier {
id: "T1",
range: 10..12,
},
bound: None,
},
),
TypeVarTuple(
TypeParamTypeVarTuple {
range: 14..17,
name: Identifier {
id: "T2",
range: 15..17,
},
},
),
],
},
),
arguments: Some(
Arguments {
range: 17..23,
args: [
Name(
ExprName {
range: 18..19,
id: "a",
ctx: Load,
},
),
Name(
ExprName {
range: 21..22,
id: "b",
ctx: Load,
},
),
],
keywords: [],
},
),
body: [
Pass(
StmtPass {
range: 29..33,
},
),
Assign(
StmtAssign {
range: 34..40,
targets: [
Name(
ExprName {
range: 34..35,
id: "x",
ctx: Store,
},
),
],
value: NumberLiteral(
ExprNumberLiteral {
range: 38..40,
value: Int(
10,
),
},
),
},
),
],
},
),
],
},
)
```
## Errors
|
1 | class Foo[T1, *T2(a, b):
| ^ Syntax Error: Expected ']', found '('
2 | pass
3 | x = 10
|
|
1 | class Foo[T1, *T2(a, b):
2 | pass
3 | x = 10
| ^ Syntax Error: Simple statements must be separated by newlines or semicolons
|
|
2 | pass
3 | x = 10
|

View file

@ -0,0 +1,64 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/clause_expect_indented_block.py
---
## AST
```
Module(
ModModule {
range: 0..171,
body: [
If(
StmtIf {
range: 53..61,
test: BooleanLiteral(
ExprBooleanLiteral {
range: 56..60,
value: true,
},
),
body: [],
elif_else_clauses: [],
},
),
Pass(
StmtPass {
range: 62..66,
},
),
If(
StmtIf {
range: 162..170,
test: BooleanLiteral(
ExprBooleanLiteral {
range: 165..169,
value: true,
},
),
body: [],
elif_else_clauses: [],
},
),
],
},
)
```
## Errors
|
1 | # Here, the error is highlighted at the `pass` token
2 | if True:
3 | pass
| ^^^^ Syntax Error: Expected an indented block after `if` statement
4 | # The parser is at the end of the program, so let's highlight
5 | # at the newline token after `:`
|
|
4 | # The parser is at the end of the program, so let's highlight
5 | # at the newline token after `:`
6 | if True:
| ^ Syntax Error: Expected an indented block after `if` statement
|

View file

@ -0,0 +1,53 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/clause_expect_single_statement.py
---
## AST
```
Module(
ModModule {
range: 0..23,
body: [
If(
StmtIf {
range: 0..8,
test: BooleanLiteral(
ExprBooleanLiteral {
range: 3..7,
value: true,
},
),
body: [],
elif_else_clauses: [],
},
),
If(
StmtIf {
range: 9..22,
test: BooleanLiteral(
ExprBooleanLiteral {
range: 12..16,
value: true,
},
),
body: [
Pass(
StmtPass {
range: 18..22,
},
),
],
elif_else_clauses: [],
},
),
],
},
)
```
## Errors
|
1 | if True: if True: pass
| ^^ Syntax Error: Expected a simple statement
|

View file

@ -0,0 +1,114 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/comprehension_missing_for_after_async.py
---
## AST
```
Module(
ModModule {
range: 0..28,
body: [
Expr(
StmtExpr {
range: 0..7,
value: Generator(
ExprGenerator {
range: 0..7,
elt: Name(
ExprName {
range: 1..1,
id: "",
ctx: Invalid,
},
),
generators: [
Comprehension {
range: 1..6,
target: Name(
ExprName {
range: 6..6,
id: "",
ctx: Store,
},
),
iter: Name(
ExprName {
range: 6..6,
id: "",
ctx: Invalid,
},
),
ifs: [],
is_async: true,
},
],
parenthesized: true,
},
),
},
),
Expr(
StmtExpr {
range: 8..27,
value: Generator(
ExprGenerator {
range: 8..27,
elt: Name(
ExprName {
range: 9..10,
id: "x",
ctx: Load,
},
),
generators: [
Comprehension {
range: 11..26,
target: Name(
ExprName {
range: 17..18,
id: "x",
ctx: Store,
},
),
iter: Name(
ExprName {
range: 22..26,
id: "iter",
ctx: Load,
},
),
ifs: [],
is_async: true,
},
],
parenthesized: true,
},
),
},
),
],
},
)
```
## Errors
|
1 | (async)
| ^^^^^ Syntax Error: Expected an expression
2 | (x async x in iter)
|
|
1 | (async)
| ^ Syntax Error: Expected 'for', found ')'
2 | (x async x in iter)
|
|
1 | (async)
2 | (x async x in iter)
| ^ Syntax Error: Expected 'for', found name
|

View file

@ -0,0 +1,175 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/decorator_invalid_expression.py
---
## AST
```
Module(
ModModule {
range: 0..56,
body: [
FunctionDef(
StmtFunctionDef {
range: 0..55,
is_async: false,
decorator_list: [
Decorator {
range: 0..3,
expression: Starred(
ExprStarred {
range: 1..3,
value: Name(
ExprName {
range: 2..3,
id: "x",
ctx: Load,
},
),
ctx: Load,
},
),
},
Decorator {
range: 4..9,
expression: Starred(
ExprStarred {
range: 6..8,
value: Name(
ExprName {
range: 7..8,
id: "x",
ctx: Load,
},
),
ctx: Load,
},
),
},
Decorator {
range: 10..17,
expression: Starred(
ExprStarred {
range: 13..15,
value: Name(
ExprName {
range: 14..15,
id: "x",
ctx: Load,
},
),
ctx: Load,
},
),
},
Decorator {
range: 18..26,
expression: Yield(
ExprYield {
range: 19..26,
value: Some(
Name(
ExprName {
range: 25..26,
id: "x",
ctx: Load,
},
),
),
},
),
},
Decorator {
range: 27..40,
expression: YieldFrom(
ExprYieldFrom {
range: 28..40,
value: Name(
ExprName {
range: 39..40,
id: "x",
ctx: Load,
},
),
},
),
},
],
name: Identifier {
id: "foo",
range: 45..48,
},
type_params: None,
parameters: Parameters {
range: 48..50,
posonlyargs: [],
args: [],
vararg: None,
kwonlyargs: [],
kwarg: None,
},
returns: None,
body: [
Expr(
StmtExpr {
range: 52..55,
value: EllipsisLiteral(
ExprEllipsisLiteral {
range: 52..55,
},
),
},
),
],
},
),
],
},
)
```
## Errors
|
1 | @*x
| ^^ Syntax Error: Starred expression cannot be used here
2 | @(*x)
3 | @((*x))
|
|
1 | @*x
2 | @(*x)
| ^^ Syntax Error: Starred expression cannot be used here
3 | @((*x))
4 | @yield x
|
|
1 | @*x
2 | @(*x)
3 | @((*x))
| ^^ Syntax Error: Starred expression cannot be used here
4 | @yield x
5 | @yield from x
|
|
2 | @(*x)
3 | @((*x))
4 | @yield x
| ^^^^^^^ Syntax Error: Yield expression cannot be used here
5 | @yield from x
6 | def foo(): ...
|
|
3 | @((*x))
4 | @yield x
5 | @yield from x
| ^^^^^^^^^^^^ Syntax Error: Yield expression cannot be used here
6 | def foo(): ...
|

View file

@ -0,0 +1,189 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/decorator_missing_expression.py
---
## AST
```
Module(
ModModule {
range: 0..51,
body: [
AnnAssign(
StmtAnnAssign {
range: 5..15,
target: Call(
ExprCall {
range: 5..10,
func: Name(
ExprName {
range: 5..8,
id: "foo",
ctx: Load,
},
),
arguments: Arguments {
range: 8..10,
args: [],
keywords: [],
},
},
),
annotation: EllipsisLiteral(
ExprEllipsisLiteral {
range: 12..15,
},
),
value: None,
simple: false,
},
),
FunctionDef(
StmtFunctionDef {
range: 16..32,
is_async: false,
decorator_list: [
Decorator {
range: 16..17,
expression: Name(
ExprName {
range: 17..17,
id: "",
ctx: Invalid,
},
),
},
],
name: Identifier {
id: "foo",
range: 22..25,
},
type_params: None,
parameters: Parameters {
range: 25..27,
posonlyargs: [],
args: [],
vararg: None,
kwonlyargs: [],
kwarg: None,
},
returns: None,
body: [
Expr(
StmtExpr {
range: 29..32,
value: EllipsisLiteral(
ExprEllipsisLiteral {
range: 29..32,
},
),
},
),
],
},
),
FunctionDef(
StmtFunctionDef {
range: 33..50,
is_async: false,
decorator_list: [
Decorator {
range: 33..35,
expression: BinOp(
ExprBinOp {
range: 34..35,
left: Name(
ExprName {
range: 34..34,
id: "",
ctx: Invalid,
},
),
op: MatMult,
right: Name(
ExprName {
range: 35..35,
id: "",
ctx: Invalid,
},
),
},
),
},
],
name: Identifier {
id: "foo",
range: 40..43,
},
type_params: None,
parameters: Parameters {
range: 43..45,
posonlyargs: [],
args: [],
vararg: None,
kwonlyargs: [],
kwarg: None,
},
returns: None,
body: [
Expr(
StmtExpr {
range: 47..50,
value: EllipsisLiteral(
ExprEllipsisLiteral {
range: 47..50,
},
),
},
),
],
},
),
],
},
)
```
## Errors
|
1 | @def foo(): ...
| ^^^ Syntax Error: Expected an identifier, but found a keyword 'def' that cannot be used here
2 | @
3 | def foo(): ...
|
|
1 | @def foo(): ...
| ^^^ Syntax Error: Expected newline, found name
2 | @
3 | def foo(): ...
|
|
1 | @def foo(): ...
2 | @
| ^ Syntax Error: Expected an expression
3 | def foo(): ...
4 | @@
5 | def foo(): ...
|
|
2 | @
3 | def foo(): ...
4 | @@
| ^ Syntax Error: Expected an expression
5 | def foo(): ...
|
|
2 | @
3 | def foo(): ...
4 | @@
| ^ Syntax Error: Expected an expression
5 | def foo(): ...
|

View file

@ -0,0 +1,162 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/decorator_missing_newline.py
---
## AST
```
Module(
ModModule {
range: 0..60,
body: [
FunctionDef(
StmtFunctionDef {
range: 0..17,
is_async: false,
decorator_list: [
Decorator {
range: 0..2,
expression: Name(
ExprName {
range: 1..2,
id: "x",
ctx: Load,
},
),
},
],
name: Identifier {
id: "foo",
range: 7..10,
},
type_params: None,
parameters: Parameters {
range: 10..12,
posonlyargs: [],
args: [],
vararg: None,
kwonlyargs: [],
kwarg: None,
},
returns: None,
body: [
Expr(
StmtExpr {
range: 14..17,
value: EllipsisLiteral(
ExprEllipsisLiteral {
range: 14..17,
},
),
},
),
],
},
),
FunctionDef(
StmtFunctionDef {
range: 18..41,
is_async: true,
decorator_list: [
Decorator {
range: 18..20,
expression: Name(
ExprName {
range: 19..20,
id: "x",
ctx: Load,
},
),
},
],
name: Identifier {
id: "foo",
range: 31..34,
},
type_params: None,
parameters: Parameters {
range: 34..36,
posonlyargs: [],
args: [],
vararg: None,
kwonlyargs: [],
kwarg: None,
},
returns: None,
body: [
Expr(
StmtExpr {
range: 38..41,
value: EllipsisLiteral(
ExprEllipsisLiteral {
range: 38..41,
},
),
},
),
],
},
),
ClassDef(
StmtClassDef {
range: 42..59,
decorator_list: [
Decorator {
range: 42..44,
expression: Name(
ExprName {
range: 43..44,
id: "x",
ctx: Load,
},
),
},
],
name: Identifier {
id: "Foo",
range: 51..54,
},
type_params: None,
arguments: None,
body: [
Expr(
StmtExpr {
range: 56..59,
value: EllipsisLiteral(
ExprEllipsisLiteral {
range: 56..59,
},
),
},
),
],
},
),
],
},
)
```
## Errors
|
1 | @x def foo(): ...
| ^^^ Syntax Error: Expected newline, found 'def'
2 | @x async def foo(): ...
3 | @x class Foo: ...
|
|
1 | @x def foo(): ...
2 | @x async def foo(): ...
| ^^^^^ Syntax Error: Expected newline, found 'async'
3 | @x class Foo: ...
|
|
1 | @x def foo(): ...
2 | @x async def foo(): ...
3 | @x class Foo: ...
| ^^^^^ Syntax Error: Expected newline, found 'class'
|

View file

@ -0,0 +1,85 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/decorator_unexpected_token.py
---
## AST
```
Module(
ModModule {
range: 0..34,
body: [
With(
StmtWith {
range: 5..22,
is_async: true,
items: [
WithItem {
range: 16..17,
context_expr: Name(
ExprName {
range: 16..17,
id: "x",
ctx: Load,
},
),
optional_vars: None,
},
],
body: [
Expr(
StmtExpr {
range: 19..22,
value: EllipsisLiteral(
ExprEllipsisLiteral {
range: 19..22,
},
),
},
),
],
},
),
Assign(
StmtAssign {
range: 28..33,
targets: [
Name(
ExprName {
range: 28..29,
id: "x",
ctx: Store,
},
),
],
value: NumberLiteral(
ExprNumberLiteral {
range: 32..33,
value: Int(
1,
),
},
),
},
),
],
},
)
```
## Errors
|
1 | @foo
2 | async with x: ...
| ^^^^^ Syntax Error: Expected class, function definition or async function definition after decorator
3 | @foo
4 | x = 1
|
|
2 | async with x: ...
3 | @foo
4 | x = 1
| ^ Syntax Error: Expected class, function definition or async function definition after decorator
|

View file

@ -0,0 +1,124 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/del_incomplete_target.py
---
## AST
```
Module(
ModModule {
range: 0..24,
body: [
Delete(
StmtDelete {
range: 0..9,
targets: [
Name(
ExprName {
range: 4..5,
id: "x",
ctx: Del,
},
),
Attribute(
ExprAttribute {
range: 7..9,
value: Name(
ExprName {
range: 7..8,
id: "y",
ctx: Load,
},
),
attr: Identifier {
id: "",
range: 9..9,
},
ctx: Del,
},
),
],
},
),
Expr(
StmtExpr {
range: 10..11,
value: Name(
ExprName {
range: 10..11,
id: "z",
ctx: Load,
},
),
},
),
Delete(
StmtDelete {
range: 12..24,
targets: [
Name(
ExprName {
range: 16..17,
id: "x",
ctx: Del,
},
),
Subscript(
ExprSubscript {
range: 19..23,
value: Name(
ExprName {
range: 19..20,
id: "y",
ctx: Load,
},
),
slice: Slice(
ExprSlice {
range: 22..23,
lower: Some(
Name(
ExprName {
range: 22..23,
id: "z",
ctx: Load,
},
),
),
upper: Some(
Name(
ExprName {
range: 23..23,
id: "",
ctx: Invalid,
},
),
),
step: None,
},
),
ctx: Del,
},
),
],
},
),
],
},
)
```
## Errors
|
1 | del x, y.
| ^ Syntax Error: Expected an identifier
2 | z
3 | del x, y[
4 | z
|
|
3 | del x, y[
4 | z
|

View file

@ -0,0 +1,27 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/del_stmt_empty.py
---
## AST
```
Module(
ModModule {
range: 0..4,
body: [
Delete(
StmtDelete {
range: 0..3,
targets: [],
},
),
],
},
)
```
## Errors
|
1 | del
| ^ Syntax Error: Delete statement must have at least one target
|

View file

@ -0,0 +1,88 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/dotted_name_multiple_dots.py
---
## AST
```
Module(
ModModule {
range: 0..25,
body: [
Import(
StmtImport {
range: 0..11,
names: [
Alias {
range: 7..11,
name: Identifier {
id: "a..b",
range: 7..11,
},
asname: None,
},
],
},
),
Import(
StmtImport {
range: 12..20,
names: [
Alias {
range: 19..20,
name: Identifier {
id: "a",
range: 19..20,
},
asname: None,
},
],
},
),
Expr(
StmtExpr {
range: 20..23,
value: EllipsisLiteral(
ExprEllipsisLiteral {
range: 20..23,
},
),
},
),
Expr(
StmtExpr {
range: 23..24,
value: Name(
ExprName {
range: 23..24,
id: "b",
ctx: Load,
},
),
},
),
],
},
)
```
## Errors
|
1 | import a..b
| ^ Syntax Error: Expected an identifier
2 | import a...b
|
|
1 | import a..b
2 | import a...b
| ^^^ Syntax Error: Expected ',', found '...'
|
|
1 | import a..b
2 | import a...b
| ^ Syntax Error: Simple statements must be separated by newlines or semicolons
|

View file

@ -0,0 +1,125 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/except_stmt_invalid_expression.py
---
## AST
```
Module(
ModModule {
range: 0..74,
body: [
Try(
StmtTry {
range: 0..38,
body: [
Pass(
StmtPass {
range: 9..13,
},
),
],
handlers: [
ExceptHandler(
ExceptHandlerExceptHandler {
range: 14..38,
type_: Some(
Yield(
ExprYield {
range: 21..28,
value: Some(
Name(
ExprName {
range: 27..28,
id: "x",
ctx: Load,
},
),
),
},
),
),
name: None,
body: [
Pass(
StmtPass {
range: 34..38,
},
),
],
},
),
],
orelse: [],
finalbody: [],
is_star: false,
},
),
Try(
StmtTry {
range: 39..73,
body: [
Pass(
StmtPass {
range: 48..52,
},
),
],
handlers: [
ExceptHandler(
ExceptHandlerExceptHandler {
range: 53..73,
type_: Some(
Starred(
ExprStarred {
range: 61..63,
value: Name(
ExprName {
range: 62..63,
id: "x",
ctx: Load,
},
),
ctx: Load,
},
),
),
name: None,
body: [
Pass(
StmtPass {
range: 69..73,
},
),
],
},
),
],
orelse: [],
finalbody: [],
is_star: true,
},
),
],
},
)
```
## Errors
|
1 | try:
2 | pass
3 | except yield x:
| ^^^^^^^ Syntax Error: Yield expression cannot be used here
4 | pass
5 | try:
|
|
5 | try:
6 | pass
7 | except* *x:
| ^^ Syntax Error: Starred expression cannot be used here
8 | pass
|

View file

@ -0,0 +1,95 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/except_stmt_missing_as_name.py
---
## AST
```
Module(
ModModule {
range: 0..73,
body: [
Try(
StmtTry {
range: 0..72,
body: [
Pass(
StmtPass {
range: 9..13,
},
),
],
handlers: [
ExceptHandler(
ExceptHandlerExceptHandler {
range: 14..43,
type_: Some(
Name(
ExprName {
range: 21..30,
id: "Exception",
ctx: Load,
},
),
),
name: None,
body: [
Pass(
StmtPass {
range: 39..43,
},
),
],
},
),
ExceptHandler(
ExceptHandlerExceptHandler {
range: 44..72,
type_: Some(
Name(
ExprName {
range: 51..60,
id: "Exception",
ctx: Load,
},
),
),
name: None,
body: [
Pass(
StmtPass {
range: 68..72,
},
),
],
},
),
],
orelse: [],
finalbody: [],
is_star: false,
},
),
],
},
)
```
## Errors
|
1 | try:
2 | pass
3 | except Exception as:
| ^ Syntax Error: Expected name after `as`
4 | pass
5 | except Exception as
|
|
3 | except Exception as:
4 | pass
5 | except Exception as
| ^ Syntax Error: Expected name after `as`
6 | pass
|

View file

@ -0,0 +1,155 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/except_stmt_missing_exception.py
---
## AST
```
Module(
ModModule {
range: 0..166,
body: [
Try(
StmtTry {
range: 0..37,
body: [
Pass(
StmtPass {
range: 9..13,
},
),
],
handlers: [
ExceptHandler(
ExceptHandlerExceptHandler {
range: 14..37,
type_: None,
name: Some(
Identifier {
id: "exc",
range: 24..27,
},
),
body: [
Pass(
StmtPass {
range: 33..37,
},
),
],
},
),
],
orelse: [],
finalbody: [],
is_star: false,
},
),
Try(
StmtTry {
range: 92..165,
body: [
Pass(
StmtPass {
range: 101..105,
},
),
],
handlers: [
ExceptHandler(
ExceptHandlerExceptHandler {
range: 106..123,
type_: None,
name: None,
body: [
Pass(
StmtPass {
range: 119..123,
},
),
],
},
),
ExceptHandler(
ExceptHandlerExceptHandler {
range: 124..140,
type_: None,
name: None,
body: [
Pass(
StmtPass {
range: 136..140,
},
),
],
},
),
ExceptHandler(
ExceptHandlerExceptHandler {
range: 141..165,
type_: None,
name: Some(
Identifier {
id: "exc",
range: 152..155,
},
),
body: [
Pass(
StmtPass {
range: 161..165,
},
),
],
},
),
],
orelse: [],
finalbody: [],
is_star: true,
},
),
],
},
)
```
## Errors
|
1 | try:
2 | pass
3 | except as exc:
| ^^ Syntax Error: Expected one or more exception types
4 | pass
5 | # If a '*' is present then exception type is required
|
|
6 | try:
7 | pass
8 | except*:
| ^ Syntax Error: Expected one or more exception types
9 | pass
10 | except*
|
|
8 | except*:
9 | pass
10 | except*
| ^ Syntax Error: Expected one or more exception types
11 | pass
12 | except* as exc:
13 | pass
|
|
10 | except*
11 | pass
12 | except* as exc:
| ^^ Syntax Error: Expected one or more exception types
13 | pass
|

View file

@ -0,0 +1,64 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/except_stmt_missing_exception_and_as_name.py
---
## AST
```
Module(
ModModule {
range: 0..34,
body: [
Try(
StmtTry {
range: 0..33,
body: [
Pass(
StmtPass {
range: 9..13,
},
),
],
handlers: [
ExceptHandler(
ExceptHandlerExceptHandler {
range: 14..33,
type_: None,
name: None,
body: [
Pass(
StmtPass {
range: 29..33,
},
),
],
},
),
],
orelse: [],
finalbody: [],
is_star: false,
},
),
],
},
)
```
## Errors
|
1 | try:
2 | pass
3 | except as:
| ^^ Syntax Error: Expected one or more exception types
4 | pass
|
|
1 | try:
2 | pass
3 | except as:
| ^ Syntax Error: Expected name after `as`
4 | pass
|

View file

@ -0,0 +1,250 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/except_stmt_unparenthesized_tuple.py
---
## AST
```
Module(
ModModule {
range: 0..131,
body: [
Try(
StmtTry {
range: 0..64,
body: [
Pass(
StmtPass {
range: 9..13,
},
),
],
handlers: [
ExceptHandler(
ExceptHandlerExceptHandler {
range: 14..35,
type_: Some(
Tuple(
ExprTuple {
range: 21..25,
elts: [
Name(
ExprName {
range: 21..22,
id: "x",
ctx: Load,
},
),
Name(
ExprName {
range: 24..25,
id: "y",
ctx: Load,
},
),
],
ctx: Load,
parenthesized: false,
},
),
),
name: None,
body: [
Pass(
StmtPass {
range: 31..35,
},
),
],
},
),
ExceptHandler(
ExceptHandlerExceptHandler {
range: 36..64,
type_: Some(
Tuple(
ExprTuple {
range: 43..47,
elts: [
Name(
ExprName {
range: 43..44,
id: "x",
ctx: Load,
},
),
Name(
ExprName {
range: 46..47,
id: "y",
ctx: Load,
},
),
],
ctx: Load,
parenthesized: false,
},
),
),
name: Some(
Identifier {
id: "exc",
range: 51..54,
},
),
body: [
Pass(
StmtPass {
range: 60..64,
},
),
],
},
),
],
orelse: [],
finalbody: [],
is_star: false,
},
),
Try(
StmtTry {
range: 65..130,
body: [
Pass(
StmtPass {
range: 74..78,
},
),
],
handlers: [
ExceptHandler(
ExceptHandlerExceptHandler {
range: 79..101,
type_: Some(
Tuple(
ExprTuple {
range: 87..91,
elts: [
Name(
ExprName {
range: 87..88,
id: "x",
ctx: Load,
},
),
Name(
ExprName {
range: 90..91,
id: "y",
ctx: Load,
},
),
],
ctx: Load,
parenthesized: false,
},
),
),
name: None,
body: [
Pass(
StmtPass {
range: 97..101,
},
),
],
},
),
ExceptHandler(
ExceptHandlerExceptHandler {
range: 102..130,
type_: Some(
Tuple(
ExprTuple {
range: 110..114,
elts: [
Name(
ExprName {
range: 110..111,
id: "x",
ctx: Load,
},
),
Name(
ExprName {
range: 113..114,
id: "y",
ctx: Load,
},
),
],
ctx: Load,
parenthesized: false,
},
),
),
name: Some(
Identifier {
id: "eg",
range: 118..120,
},
),
body: [
Pass(
StmtPass {
range: 126..130,
},
),
],
},
),
],
orelse: [],
finalbody: [],
is_star: true,
},
),
],
},
)
```
## Errors
|
1 | try:
2 | pass
3 | except x, y:
| ^^^^ Syntax Error: Multiple exception types must be parenthesized
4 | pass
5 | except x, y as exc:
|
|
3 | except x, y:
4 | pass
5 | except x, y as exc:
| ^^^^ Syntax Error: Multiple exception types must be parenthesized
6 | pass
7 | try:
|
|
7 | try:
8 | pass
9 | except* x, y:
| ^^^^ Syntax Error: Multiple exception types must be parenthesized
10 | pass
11 | except* x, y as eg:
|
|
9 | except* x, y:
10 | pass
11 | except* x, y as eg:
| ^^^^ Syntax Error: Multiple exception types must be parenthesized
12 | pass
|

View file

@ -0,0 +1,221 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/arguments/double_starred.py
---
## AST
```
Module(
ModModule {
range: 0..55,
body: [
Expr(
StmtExpr {
range: 0..15,
value: Call(
ExprCall {
range: 0..15,
func: Name(
ExprName {
range: 0..4,
id: "call",
ctx: Load,
},
),
arguments: Arguments {
range: 4..15,
args: [],
keywords: [
Keyword {
range: 5..14,
arg: None,
value: Yield(
ExprYield {
range: 7..14,
value: Some(
Name(
ExprName {
range: 13..14,
id: "x",
ctx: Load,
},
),
),
},
),
},
],
},
},
),
},
),
Expr(
StmtExpr {
range: 16..27,
value: Call(
ExprCall {
range: 16..27,
func: Name(
ExprName {
range: 16..20,
id: "call",
ctx: Load,
},
),
arguments: Arguments {
range: 20..27,
args: [],
keywords: [
Keyword {
range: 21..26,
arg: None,
value: Starred(
ExprStarred {
range: 24..26,
value: Name(
ExprName {
range: 25..26,
id: "x",
ctx: Load,
},
),
ctx: Load,
},
),
},
],
},
},
),
},
),
Expr(
StmtExpr {
range: 28..38,
value: Call(
ExprCall {
range: 28..38,
func: Name(
ExprName {
range: 28..32,
id: "call",
ctx: Load,
},
),
arguments: Arguments {
range: 32..38,
args: [],
keywords: [
Keyword {
range: 33..37,
arg: None,
value: Starred(
ExprStarred {
range: 35..37,
value: Name(
ExprName {
range: 36..37,
id: "x",
ctx: Load,
},
),
ctx: Load,
},
),
},
],
},
},
),
},
),
Expr(
StmtExpr {
range: 40..54,
value: Call(
ExprCall {
range: 40..54,
func: Name(
ExprName {
range: 40..44,
id: "call",
ctx: Load,
},
),
arguments: Arguments {
range: 44..54,
args: [
NumberLiteral(
ExprNumberLiteral {
range: 52..53,
value: Int(
1,
),
},
),
],
keywords: [
Keyword {
range: 45..48,
arg: None,
value: Name(
ExprName {
range: 47..48,
id: "x",
ctx: Load,
},
),
},
],
},
},
),
},
),
],
},
)
```
## Errors
|
1 | call(**yield x)
| ^^^^^^^ Syntax Error: Yield expression cannot be used here
2 | call(** *x)
3 | call(***x)
|
|
1 | call(**yield x)
2 | call(** *x)
| ^^ Syntax Error: Starred expression cannot be used here
3 | call(***x)
|
|
1 | call(**yield x)
2 | call(** *x)
3 | call(***x)
| ^^ Syntax Error: Starred expression cannot be used here
4 |
5 | call(**x := 1)
|
|
3 | call(***x)
4 |
5 | call(**x := 1)
| ^^ Syntax Error: Expected ',', found ':='
|
|
3 | call(***x)
4 |
5 | call(**x := 1)
| ^ Syntax Error: Positional argument cannot follow keyword argument unpacking
|

View file

@ -0,0 +1,135 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/arguments/duplicate_keyword_arguments.py
---
## AST
```
Module(
ModModule {
range: 0..28,
body: [
Expr(
StmtExpr {
range: 0..28,
value: Call(
ExprCall {
range: 0..28,
func: Name(
ExprName {
range: 0..3,
id: "foo",
ctx: Load,
},
),
arguments: Arguments {
range: 3..28,
args: [],
keywords: [
Keyword {
range: 4..7,
arg: Some(
Identifier {
id: "a",
range: 4..5,
},
),
value: NumberLiteral(
ExprNumberLiteral {
range: 6..7,
value: Int(
1,
),
},
),
},
Keyword {
range: 9..12,
arg: Some(
Identifier {
id: "b",
range: 9..10,
},
),
value: NumberLiteral(
ExprNumberLiteral {
range: 11..12,
value: Int(
2,
),
},
),
},
Keyword {
range: 14..17,
arg: Some(
Identifier {
id: "c",
range: 14..15,
},
),
value: NumberLiteral(
ExprNumberLiteral {
range: 16..17,
value: Int(
3,
),
},
),
},
Keyword {
range: 19..22,
arg: Some(
Identifier {
id: "b",
range: 19..20,
},
),
value: NumberLiteral(
ExprNumberLiteral {
range: 21..22,
value: Int(
4,
),
},
),
},
Keyword {
range: 24..27,
arg: Some(
Identifier {
id: "a",
range: 24..25,
},
),
value: NumberLiteral(
ExprNumberLiteral {
range: 26..27,
value: Int(
5,
),
},
),
},
],
},
},
),
},
),
],
},
)
```
## Errors
|
1 | foo(a=1, b=2, c=3, b=4, a=5)
| ^^^ Syntax Error: Duplicate keyword argument "b"
|
|
1 | foo(a=1, b=2, c=3, b=4, a=5)
| ^^^ Syntax Error: Duplicate keyword argument "a"
|

View file

@ -0,0 +1,199 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/arguments/invalid_expression.py
---
## AST
```
Module(
ModModule {
range: 0..67,
body: [
Expr(
StmtExpr {
range: 0..15,
value: Call(
ExprCall {
range: 0..15,
func: Name(
ExprName {
range: 0..4,
id: "call",
ctx: Load,
},
),
arguments: Arguments {
range: 4..15,
args: [],
keywords: [
Keyword {
range: 5..14,
arg: Some(
Identifier {
id: "",
range: 5..10,
},
),
value: NumberLiteral(
ExprNumberLiteral {
range: 13..14,
value: Int(
1,
),
},
),
},
],
},
},
),
},
),
Expr(
StmtExpr {
range: 16..32,
value: Call(
ExprCall {
range: 16..32,
func: Name(
ExprName {
range: 16..20,
id: "call",
ctx: Load,
},
),
arguments: Arguments {
range: 20..32,
args: [],
keywords: [
Keyword {
range: 21..31,
arg: Some(
Identifier {
id: "",
range: 21..27,
},
),
value: NumberLiteral(
ExprNumberLiteral {
range: 30..31,
value: Int(
1,
),
},
),
},
],
},
},
),
},
),
Expr(
StmtExpr {
range: 34..47,
value: Call(
ExprCall {
range: 34..47,
func: Name(
ExprName {
range: 34..38,
id: "call",
ctx: Load,
},
),
arguments: Arguments {
range: 38..47,
args: [
Yield(
ExprYield {
range: 39..46,
value: Some(
Name(
ExprName {
range: 45..46,
id: "x",
ctx: Load,
},
),
),
},
),
],
keywords: [],
},
},
),
},
),
Expr(
StmtExpr {
range: 48..66,
value: Call(
ExprCall {
range: 48..66,
func: Name(
ExprName {
range: 48..52,
id: "call",
ctx: Load,
},
),
arguments: Arguments {
range: 52..66,
args: [
YieldFrom(
ExprYieldFrom {
range: 53..65,
value: Name(
ExprName {
range: 64..65,
id: "x",
ctx: Load,
},
),
},
),
],
keywords: [],
},
},
),
},
),
],
},
)
```
## Errors
|
1 | call(x + y = 1)
| ^^^^^ Syntax Error: Expected a parameter name
2 | call(x := 1 = 1)
|
|
1 | call(x + y = 1)
2 | call(x := 1 = 1)
| ^^^^^^ Syntax Error: Expected a parameter name
3 |
4 | call(yield x)
|
|
2 | call(x := 1 = 1)
3 |
4 | call(yield x)
| ^^^^^^^ Syntax Error: Yield expression cannot be used here
5 | call(yield from x)
|
|
4 | call(yield x)
5 | call(yield from x)
| ^^^^^^^^^^^^ Syntax Error: Yield expression cannot be used here
|

View file

@ -0,0 +1,229 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/arguments/invalid_keyword_expression.py
---
## AST
```
Module(
ModModule {
range: 0..69,
body: [
Expr(
StmtExpr {
range: 0..17,
value: Call(
ExprCall {
range: 0..17,
func: Name(
ExprName {
range: 0..4,
id: "call",
ctx: Load,
},
),
arguments: Arguments {
range: 4..17,
args: [],
keywords: [
Keyword {
range: 5..16,
arg: Some(
Identifier {
id: "x",
range: 5..6,
},
),
value: Yield(
ExprYield {
range: 9..16,
value: Some(
Name(
ExprName {
range: 15..16,
id: "y",
ctx: Load,
},
),
),
},
),
},
],
},
},
),
},
),
Expr(
StmtExpr {
range: 18..40,
value: Call(
ExprCall {
range: 18..40,
func: Name(
ExprName {
range: 18..22,
id: "call",
ctx: Load,
},
),
arguments: Arguments {
range: 22..40,
args: [],
keywords: [
Keyword {
range: 23..39,
arg: Some(
Identifier {
id: "x",
range: 23..24,
},
),
value: YieldFrom(
ExprYieldFrom {
range: 27..39,
value: Name(
ExprName {
range: 38..39,
id: "y",
ctx: Load,
},
),
},
),
},
],
},
},
),
},
),
Expr(
StmtExpr {
range: 41..53,
value: Call(
ExprCall {
range: 41..53,
func: Name(
ExprName {
range: 41..45,
id: "call",
ctx: Load,
},
),
arguments: Arguments {
range: 45..53,
args: [],
keywords: [
Keyword {
range: 46..52,
arg: Some(
Identifier {
id: "x",
range: 46..47,
},
),
value: Starred(
ExprStarred {
range: 50..52,
value: Name(
ExprName {
range: 51..52,
id: "y",
ctx: Load,
},
),
ctx: Load,
},
),
},
],
},
},
),
},
),
Expr(
StmtExpr {
range: 54..68,
value: Call(
ExprCall {
range: 54..68,
func: Name(
ExprName {
range: 54..58,
id: "call",
ctx: Load,
},
),
arguments: Arguments {
range: 58..68,
args: [],
keywords: [
Keyword {
range: 59..67,
arg: Some(
Identifier {
id: "x",
range: 59..60,
},
),
value: Starred(
ExprStarred {
range: 64..66,
value: Name(
ExprName {
range: 65..66,
id: "y",
ctx: Load,
},
),
ctx: Load,
},
),
},
],
},
},
),
},
),
],
},
)
```
## Errors
|
1 | call(x = yield y)
| ^^^^^^^ Syntax Error: Yield expression cannot be used here
2 | call(x = yield from y)
3 | call(x = *y)
|
|
1 | call(x = yield y)
2 | call(x = yield from y)
| ^^^^^^^^^^^^ Syntax Error: Yield expression cannot be used here
3 | call(x = *y)
4 | call(x = (*y))
|
|
1 | call(x = yield y)
2 | call(x = yield from y)
3 | call(x = *y)
| ^^ Syntax Error: Starred expression cannot be used here
4 | call(x = (*y))
|
|
2 | call(x = yield from y)
3 | call(x = *y)
4 | call(x = (*y))
| ^^ Syntax Error: Starred expression cannot be used here
|

View file

@ -0,0 +1,304 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/arguments/invalid_order.py
---
## AST
```
Module(
ModModule {
range: 0..100,
body: [
Expr(
StmtExpr {
range: 0..17,
value: Call(
ExprCall {
range: 0..17,
func: Name(
ExprName {
range: 0..4,
id: "call",
ctx: Load,
},
),
arguments: Arguments {
range: 4..17,
args: [
Name(
ExprName {
range: 15..16,
id: "x",
ctx: Load,
},
),
],
keywords: [
Keyword {
range: 5..13,
arg: None,
value: Name(
ExprName {
range: 7..13,
id: "kwargs",
ctx: Load,
},
),
},
],
},
},
),
},
),
Expr(
StmtExpr {
range: 18..30,
value: Call(
ExprCall {
range: 18..30,
func: Name(
ExprName {
range: 18..22,
id: "call",
ctx: Load,
},
),
arguments: Arguments {
range: 22..30,
args: [
Name(
ExprName {
range: 28..29,
id: "y",
ctx: Load,
},
),
],
keywords: [
Keyword {
range: 23..26,
arg: Some(
Identifier {
id: "x",
range: 23..24,
},
),
value: NumberLiteral(
ExprNumberLiteral {
range: 25..26,
value: Int(
1,
),
},
),
},
],
},
},
),
},
),
Expr(
StmtExpr {
range: 31..53,
value: Call(
ExprCall {
range: 31..53,
func: Name(
ExprName {
range: 31..35,
id: "call",
ctx: Load,
},
),
arguments: Arguments {
range: 35..53,
args: [
Name(
ExprName {
range: 51..52,
id: "y",
ctx: Load,
},
),
],
keywords: [
Keyword {
range: 36..39,
arg: Some(
Identifier {
id: "x",
range: 36..37,
},
),
value: NumberLiteral(
ExprNumberLiteral {
range: 38..39,
value: Int(
1,
),
},
),
},
Keyword {
range: 41..49,
arg: None,
value: Name(
ExprName {
range: 43..49,
id: "kwargs",
ctx: Load,
},
),
},
],
},
},
),
},
),
Expr(
StmtExpr {
range: 54..75,
value: Call(
ExprCall {
range: 54..75,
func: Name(
ExprName {
range: 54..58,
id: "call",
ctx: Load,
},
),
arguments: Arguments {
range: 58..75,
args: [
Starred(
ExprStarred {
range: 69..74,
value: Name(
ExprName {
range: 70..74,
id: "args",
ctx: Load,
},
),
ctx: Load,
},
),
],
keywords: [
Keyword {
range: 59..67,
arg: None,
value: Name(
ExprName {
range: 61..67,
id: "kwargs",
ctx: Load,
},
),
},
],
},
},
),
},
),
Expr(
StmtExpr {
range: 76..99,
value: Call(
ExprCall {
range: 76..99,
func: Name(
ExprName {
range: 76..80,
id: "call",
ctx: Load,
},
),
arguments: Arguments {
range: 80..99,
args: [
Starred(
ExprStarred {
range: 92..97,
value: Name(
ExprName {
range: 93..97,
id: "args",
ctx: Load,
},
),
ctx: Load,
},
),
],
keywords: [
Keyword {
range: 81..89,
arg: None,
value: Name(
ExprName {
range: 83..89,
id: "kwargs",
ctx: Load,
},
),
},
],
},
},
),
},
),
],
},
)
```
## Errors
|
1 | call(**kwargs, x)
| ^ Syntax Error: Positional argument cannot follow keyword argument unpacking
2 | call(x=1, y)
3 | call(x=1, **kwargs, y)
|
|
1 | call(**kwargs, x)
2 | call(x=1, y)
| ^ Syntax Error: Positional argument cannot follow keyword argument
3 | call(x=1, **kwargs, y)
4 | call(**kwargs, *args)
|
|
1 | call(**kwargs, x)
2 | call(x=1, y)
3 | call(x=1, **kwargs, y)
| ^ Syntax Error: Positional argument cannot follow keyword argument unpacking
4 | call(**kwargs, *args)
5 | call(**kwargs, (*args))
|
|
2 | call(x=1, y)
3 | call(x=1, **kwargs, y)
4 | call(**kwargs, *args)
| ^^^^^ Syntax Error: Iterable argument unpacking cannot follow keyword argument unpacking
5 | call(**kwargs, (*args))
|
|
3 | call(x=1, **kwargs, y)
4 | call(**kwargs, *args)
5 | call(**kwargs, (*args))
| ^^^^^ Syntax Error: Starred expression cannot be used here
|

View file

@ -0,0 +1,58 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/arguments/missing_argument.py
---
## AST
```
Module(
ModModule {
range: 0..10,
body: [
Expr(
StmtExpr {
range: 0..10,
value: Call(
ExprCall {
range: 0..10,
func: Name(
ExprName {
range: 0..4,
id: "call",
ctx: Load,
},
),
arguments: Arguments {
range: 4..10,
args: [
Name(
ExprName {
range: 5..6,
id: "x",
ctx: Load,
},
),
Name(
ExprName {
range: 8..9,
id: "y",
ctx: Load,
},
),
],
keywords: [],
},
},
),
},
),
],
},
)
```
## Errors
|
1 | call(x,,y)
| ^ Syntax Error: Expected an expression or a ')'
|

View file

@ -0,0 +1,58 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/arguments/missing_comma.py
---
## AST
```
Module(
ModModule {
range: 0..9,
body: [
Expr(
StmtExpr {
range: 0..9,
value: Call(
ExprCall {
range: 0..9,
func: Name(
ExprName {
range: 0..4,
id: "call",
ctx: Load,
},
),
arguments: Arguments {
range: 4..9,
args: [
Name(
ExprName {
range: 5..6,
id: "x",
ctx: Load,
},
),
Name(
ExprName {
range: 7..8,
id: "y",
ctx: Load,
},
),
],
keywords: [],
},
},
),
},
),
],
},
)
```
## Errors
|
1 | call(x y)
| ^ Syntax Error: Expected ',', found name
|

View file

@ -0,0 +1,166 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/arguments/missing_expression.py
---
## AST
```
Module(
ModModule {
range: 0..38,
body: [
Expr(
StmtExpr {
range: 0..10,
value: Call(
ExprCall {
range: 0..10,
func: Name(
ExprName {
range: 0..4,
id: "call",
ctx: Load,
},
),
arguments: Arguments {
range: 4..10,
args: [
NumberLiteral(
ExprNumberLiteral {
range: 8..9,
value: Int(
1,
),
},
),
],
keywords: [],
},
},
),
},
),
Expr(
StmtExpr {
range: 11..21,
value: Call(
ExprCall {
range: 11..21,
func: Name(
ExprName {
range: 11..15,
id: "call",
ctx: Load,
},
),
arguments: Arguments {
range: 15..21,
args: [],
keywords: [
Keyword {
range: 16..19,
arg: Some(
Identifier {
id: "x",
range: 16..17,
},
),
value: Name(
ExprName {
range: 19..19,
id: "",
ctx: Invalid,
},
),
},
],
},
},
),
},
),
Expr(
StmtExpr {
range: 22..32,
value: Call(
ExprCall {
range: 22..32,
func: Name(
ExprName {
range: 22..26,
id: "call",
ctx: Load,
},
),
arguments: Arguments {
range: 26..32,
args: [
Starred(
ExprStarred {
range: 27..28,
value: Name(
ExprName {
range: 28..28,
id: "",
ctx: Invalid,
},
),
ctx: Load,
},
),
Name(
ExprName {
range: 30..31,
id: "y",
ctx: Load,
},
),
],
keywords: [],
},
},
),
},
),
Expr(
StmtExpr {
range: 34..37,
value: Name(
ExprName {
range: 34..37,
id: "foo",
ctx: Load,
},
),
},
),
],
},
)
```
## Errors
|
1 | call( = 1)
| ^ Syntax Error: Expected an expression or a ')'
2 | call(x = )
3 | call(*, y)
|
|
1 | call( = 1)
2 | call(x = )
| ^ Syntax Error: Expected an expression
3 | call(*, y)
|
|
1 | call( = 1)
2 | call(x = )
3 | call(*, y)
| ^ Syntax Error: Expected an expression
4 |
5 | foo
|

View file

@ -0,0 +1,186 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/arguments/starred.py
---
## AST
```
Module(
ModModule {
range: 0..64,
body: [
Expr(
StmtExpr {
range: 0..28,
value: Call(
ExprCall {
range: 0..28,
func: Name(
ExprName {
range: 0..4,
id: "call",
ctx: Load,
},
),
arguments: Arguments {
range: 4..28,
args: [
Generator(
ExprGenerator {
range: 5..27,
elt: Starred(
ExprStarred {
range: 5..10,
value: Name(
ExprName {
range: 6..10,
id: "data",
ctx: Load,
},
),
ctx: Load,
},
),
generators: [
Comprehension {
range: 11..27,
target: Name(
ExprName {
range: 15..19,
id: "data",
ctx: Store,
},
),
iter: Name(
ExprName {
range: 23..27,
id: "iter",
ctx: Load,
},
),
ifs: [],
is_async: false,
},
],
parenthesized: false,
},
),
],
keywords: [],
},
},
),
},
),
Expr(
StmtExpr {
range: 29..43,
value: Call(
ExprCall {
range: 29..43,
func: Name(
ExprName {
range: 29..33,
id: "call",
ctx: Load,
},
),
arguments: Arguments {
range: 33..43,
args: [
Starred(
ExprStarred {
range: 34..42,
value: Yield(
ExprYield {
range: 35..42,
value: Some(
Name(
ExprName {
range: 41..42,
id: "x",
ctx: Load,
},
),
),
},
),
ctx: Load,
},
),
],
keywords: [],
},
},
),
},
),
Expr(
StmtExpr {
range: 44..63,
value: Call(
ExprCall {
range: 44..63,
func: Name(
ExprName {
range: 44..48,
id: "call",
ctx: Load,
},
),
arguments: Arguments {
range: 48..63,
args: [
Starred(
ExprStarred {
range: 49..62,
value: YieldFrom(
ExprYieldFrom {
range: 50..62,
value: Name(
ExprName {
range: 61..62,
id: "x",
ctx: Load,
},
),
},
),
ctx: Load,
},
),
],
keywords: [],
},
},
),
},
),
],
},
)
```
## Errors
|
1 | call(*data for data in iter)
| ^^^^^ Syntax Error: Iterable unpacking cannot be used in a comprehension
2 | call(*yield x)
3 | call(*yield from x)
|
|
1 | call(*data for data in iter)
2 | call(*yield x)
| ^^^^^^^ Syntax Error: Yield expression cannot be used here
3 | call(*yield from x)
|
|
1 | call(*data for data in iter)
2 | call(*yield x)
3 | call(*yield from x)
| ^^^^^^^^^^^^ Syntax Error: Yield expression cannot be used here
|

View file

@ -0,0 +1,81 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/arguments/unclosed_0.py
---
## AST
```
Module(
ModModule {
range: 0..26,
body: [
Expr(
StmtExpr {
range: 0..5,
value: Call(
ExprCall {
range: 0..5,
func: Name(
ExprName {
range: 0..4,
id: "call",
ctx: Load,
},
),
arguments: Arguments {
range: 4..5,
args: [],
keywords: [],
},
},
),
},
),
FunctionDef(
StmtFunctionDef {
range: 7..26,
is_async: false,
decorator_list: [],
name: Identifier {
id: "foo",
range: 11..14,
},
type_params: None,
parameters: Parameters {
range: 14..16,
posonlyargs: [],
args: [],
vararg: None,
kwonlyargs: [],
kwarg: None,
},
returns: None,
body: [
Pass(
StmtPass {
range: 22..26,
},
),
],
},
),
],
},
)
```
## Errors
|
1 | call(
2 |
3 | def foo():
| ^^^ Syntax Error: Expected an expression or a ')'
4 | pass
|
|
3 | def foo():
4 | pass
| Syntax Error: unexpected EOF while parsing
|

View file

@ -0,0 +1,89 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/arguments/unclosed_1.py
---
## AST
```
Module(
ModModule {
range: 0..27,
body: [
Expr(
StmtExpr {
range: 0..6,
value: Call(
ExprCall {
range: 0..6,
func: Name(
ExprName {
range: 0..4,
id: "call",
ctx: Load,
},
),
arguments: Arguments {
range: 4..6,
args: [
Name(
ExprName {
range: 5..6,
id: "x",
ctx: Load,
},
),
],
keywords: [],
},
},
),
},
),
FunctionDef(
StmtFunctionDef {
range: 8..27,
is_async: false,
decorator_list: [],
name: Identifier {
id: "foo",
range: 12..15,
},
type_params: None,
parameters: Parameters {
range: 15..17,
posonlyargs: [],
args: [],
vararg: None,
kwonlyargs: [],
kwarg: None,
},
returns: None,
body: [
Pass(
StmtPass {
range: 23..27,
},
),
],
},
),
],
},
)
```
## Errors
|
1 | call(x
2 |
3 | def foo():
| ^^^ Syntax Error: Expected ',', found 'def'
4 | pass
|
|
3 | def foo():
4 | pass
| Syntax Error: unexpected EOF while parsing
|

View file

@ -0,0 +1,89 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/arguments/unclosed_2.py
---
## AST
```
Module(
ModModule {
range: 0..28,
body: [
Expr(
StmtExpr {
range: 0..7,
value: Call(
ExprCall {
range: 0..7,
func: Name(
ExprName {
range: 0..4,
id: "call",
ctx: Load,
},
),
arguments: Arguments {
range: 4..7,
args: [
Name(
ExprName {
range: 5..6,
id: "x",
ctx: Load,
},
),
],
keywords: [],
},
},
),
},
),
FunctionDef(
StmtFunctionDef {
range: 9..28,
is_async: false,
decorator_list: [],
name: Identifier {
id: "foo",
range: 13..16,
},
type_params: None,
parameters: Parameters {
range: 16..18,
posonlyargs: [],
args: [],
vararg: None,
kwonlyargs: [],
kwarg: None,
},
returns: None,
body: [
Pass(
StmtPass {
range: 24..28,
},
),
],
},
),
],
},
)
```
## Errors
|
1 | call(x,
2 |
3 | def foo():
| ^^^ Syntax Error: Expected an expression or a ')'
4 | pass
|
|
3 | def foo():
4 | pass
| Syntax Error: unexpected EOF while parsing
|

View file

@ -0,0 +1,146 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/attribute/invalid_member.py
---
## AST
```
Module(
ModModule {
range: 0..16,
body: [
Expr(
StmtExpr {
range: 0..1,
value: Name(
ExprName {
range: 0..1,
id: "x",
ctx: Load,
},
),
},
),
Expr(
StmtExpr {
range: 1..3,
value: NumberLiteral(
ExprNumberLiteral {
range: 1..3,
value: Float(
0.1,
),
},
),
},
),
Expr(
StmtExpr {
range: 4..5,
value: Name(
ExprName {
range: 4..5,
id: "x",
ctx: Load,
},
),
},
),
Expr(
StmtExpr {
range: 5..7,
value: NumberLiteral(
ExprNumberLiteral {
range: 5..7,
value: Float(
0.1,
),
},
),
},
),
Expr(
StmtExpr {
range: 7..9,
value: NumberLiteral(
ExprNumberLiteral {
range: 7..9,
value: Float(
0.0,
),
},
),
},
),
Expr(
StmtExpr {
range: 10..15,
value: Subscript(
ExprSubscript {
range: 10..15,
value: Attribute(
ExprAttribute {
range: 10..12,
value: Name(
ExprName {
range: 10..11,
id: "x",
ctx: Load,
},
),
attr: Identifier {
id: "",
range: 12..12,
},
ctx: Load,
},
),
slice: NumberLiteral(
ExprNumberLiteral {
range: 13..14,
value: Int(
0,
),
},
),
ctx: Load,
},
),
},
),
],
},
)
```
## Errors
|
1 | x.1
| ^^ Syntax Error: Simple statements must be separated by newlines or semicolons
2 | x.1.0
3 | x.[0]
|
|
1 | x.1
2 | x.1.0
| ^^ Syntax Error: Simple statements must be separated by newlines or semicolons
3 | x.[0]
|
|
1 | x.1
2 | x.1.0
| ^^ Syntax Error: Simple statements must be separated by newlines or semicolons
3 | x.[0]
|
|
1 | x.1
2 | x.1.0
3 | x.[0]
| ^ Syntax Error: Expected an identifier
|

View file

@ -0,0 +1,153 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/attribute/multiple_dots.py
---
## AST
```
Module(
ModModule {
range: 0..46,
body: [
Expr(
StmtExpr {
range: 0..10,
value: Attribute(
ExprAttribute {
range: 0..10,
value: Attribute(
ExprAttribute {
range: 0..6,
value: Name(
ExprName {
range: 0..5,
id: "extra",
ctx: Load,
},
),
attr: Identifier {
id: "",
range: 6..6,
},
ctx: Load,
},
),
attr: Identifier {
id: "dot",
range: 7..10,
},
ctx: Load,
},
),
},
),
Expr(
StmtExpr {
range: 11..19,
value: Name(
ExprName {
range: 11..19,
id: "multiple",
ctx: Load,
},
),
},
),
Expr(
StmtExpr {
range: 19..27,
value: Attribute(
ExprAttribute {
range: 19..27,
value: EllipsisLiteral(
ExprEllipsisLiteral {
range: 19..22,
},
),
attr: Identifier {
id: "dots",
range: 23..27,
},
ctx: Load,
},
),
},
),
Expr(
StmtExpr {
range: 28..36,
value: Name(
ExprName {
range: 28..36,
id: "multiple",
ctx: Load,
},
),
},
),
Expr(
StmtExpr {
range: 36..45,
value: Attribute(
ExprAttribute {
range: 36..45,
value: Attribute(
ExprAttribute {
range: 36..40,
value: EllipsisLiteral(
ExprEllipsisLiteral {
range: 36..39,
},
),
attr: Identifier {
id: "",
range: 40..40,
},
ctx: Load,
},
),
attr: Identifier {
id: "dots",
range: 41..45,
},
ctx: Load,
},
),
},
),
],
},
)
```
## Errors
|
1 | extra..dot
| ^ Syntax Error: Expected an identifier
2 | multiple....dots
3 | multiple.....dots
|
|
1 | extra..dot
2 | multiple....dots
| ^^^ Syntax Error: Simple statements must be separated by newlines or semicolons
3 | multiple.....dots
|
|
1 | extra..dot
2 | multiple....dots
3 | multiple.....dots
| ^^^ Syntax Error: Simple statements must be separated by newlines or semicolons
|
|
1 | extra..dot
2 | multiple....dots
3 | multiple.....dots
| ^ Syntax Error: Expected an identifier
|

View file

@ -0,0 +1,88 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/attribute/no_member.py
---
## AST
```
Module(
ModModule {
range: 0..141,
body: [
Expr(
StmtExpr {
range: 87..93,
value: Attribute(
ExprAttribute {
range: 87..93,
value: Name(
ExprName {
range: 87..92,
id: "first",
ctx: Load,
},
),
attr: Identifier {
id: "",
range: 93..93,
},
ctx: Load,
},
),
},
),
Expr(
StmtExpr {
range: 94..100,
value: Name(
ExprName {
range: 94..100,
id: "second",
ctx: Load,
},
),
},
),
Expr(
StmtExpr {
range: 136..141,
value: Attribute(
ExprAttribute {
range: 136..141,
value: Name(
ExprName {
range: 136..140,
id: "last",
ctx: Load,
},
),
attr: Identifier {
id: "",
range: 141..141,
},
ctx: Load,
},
),
},
),
],
},
)
```
## Errors
|
1 | # The `second` is a variable on another line and not part of the attribute expression.
2 | first.
| ^ Syntax Error: Expected an identifier
3 | second
4 |
5 | # No member access after the dot.
|
|
5 | # No member access after the dot.
6 | last.
| Syntax Error: Expected an identifier
|

View file

@ -0,0 +1,66 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/await/no_expression_0.py
---
## AST
```
Module(
ModModule {
range: 0..73,
body: [
Expr(
StmtExpr {
range: 61..66,
value: Await(
ExprAwait {
range: 61..66,
value: Name(
ExprName {
range: 66..66,
id: "",
ctx: Invalid,
},
),
},
),
},
),
Expr(
StmtExpr {
range: 68..73,
value: BinOp(
ExprBinOp {
range: 68..73,
left: Name(
ExprName {
range: 68..69,
id: "x",
ctx: Load,
},
),
op: Add,
right: Name(
ExprName {
range: 72..73,
id: "y",
ctx: Load,
},
),
},
),
},
),
],
},
)
```
## Errors
|
1 | # No expression after `await`, an expression on another line
2 | await
| ^ Syntax Error: Expected an expression
3 |
4 | x + y
|

View file

@ -0,0 +1,70 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/await/no_expression_1.py
---
## AST
```
Module(
ModModule {
range: 0..85,
body: [
Expr(
StmtExpr {
range: 59..64,
value: Await(
ExprAwait {
range: 59..64,
value: Name(
ExprName {
range: 64..64,
id: "",
ctx: Invalid,
},
),
},
),
},
),
FunctionDef(
StmtFunctionDef {
range: 66..85,
is_async: false,
decorator_list: [],
name: Identifier {
id: "foo",
range: 70..73,
},
type_params: None,
parameters: Parameters {
range: 73..75,
posonlyargs: [],
args: [],
vararg: None,
kwonlyargs: [],
kwarg: None,
},
returns: None,
body: [
Pass(
StmtPass {
range: 81..85,
},
),
],
},
),
],
},
)
```
## Errors
|
1 | # No expression after `await`, a statement on another line
2 | await
| ^ Syntax Error: Expected an expression
3 |
4 | def foo():
5 | pass
|

View file

@ -0,0 +1,327 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/await/recover.py
---
## AST
```
Module(
ModModule {
range: 0..284,
body: [
Expr(
StmtExpr {
range: 117..130,
value: Await(
ExprAwait {
range: 117..130,
value: Await(
ExprAwait {
range: 123..130,
value: Name(
ExprName {
range: 129..130,
id: "x",
ctx: Load,
},
),
},
),
},
),
},
),
Expr(
StmtExpr {
range: 154..162,
value: Await(
ExprAwait {
range: 154..162,
value: Starred(
ExprStarred {
range: 160..162,
value: Name(
ExprName {
range: 161..162,
id: "x",
ctx: Load,
},
),
ctx: Load,
},
),
},
),
},
),
Expr(
StmtExpr {
range: 163..173,
value: Await(
ExprAwait {
range: 163..173,
value: Starred(
ExprStarred {
range: 170..172,
value: Name(
ExprName {
range: 171..172,
id: "x",
ctx: Load,
},
),
ctx: Load,
},
),
},
),
},
),
Expr(
StmtExpr {
range: 214..227,
value: Await(
ExprAwait {
range: 214..227,
value: Yield(
ExprYield {
range: 220..227,
value: Some(
Name(
ExprName {
range: 226..227,
id: "x",
ctx: Load,
},
),
),
},
),
},
),
},
),
Expr(
StmtExpr {
range: 228..245,
value: Await(
ExprAwait {
range: 228..245,
value: Lambda(
ExprLambda {
range: 234..245,
parameters: Some(
Parameters {
range: 241..242,
posonlyargs: [],
args: [
ParameterWithDefault {
range: 241..242,
parameter: Parameter {
range: 241..242,
name: Identifier {
id: "x",
range: 241..242,
},
annotation: None,
},
default: None,
},
],
vararg: None,
kwonlyargs: [],
kwarg: None,
},
),
body: Name(
ExprName {
range: 244..245,
id: "x",
ctx: Load,
},
),
},
),
},
),
},
),
Expr(
StmtExpr {
range: 246..254,
value: Await(
ExprAwait {
range: 246..254,
value: UnaryOp(
ExprUnaryOp {
range: 252..254,
op: UAdd,
operand: Name(
ExprName {
range: 253..254,
id: "x",
ctx: Load,
},
),
},
),
},
),
},
),
Expr(
StmtExpr {
range: 255..263,
value: Await(
ExprAwait {
range: 255..263,
value: UnaryOp(
ExprUnaryOp {
range: 261..263,
op: USub,
operand: Name(
ExprName {
range: 262..263,
id: "x",
ctx: Load,
},
),
},
),
},
),
},
),
Expr(
StmtExpr {
range: 264..272,
value: Await(
ExprAwait {
range: 264..272,
value: UnaryOp(
ExprUnaryOp {
range: 270..272,
op: Invert,
operand: Name(
ExprName {
range: 271..272,
id: "x",
ctx: Load,
},
),
},
),
},
),
},
),
Expr(
StmtExpr {
range: 273..284,
value: Await(
ExprAwait {
range: 273..284,
value: UnaryOp(
ExprUnaryOp {
range: 279..284,
op: Not,
operand: Name(
ExprName {
range: 283..284,
id: "x",
ctx: Load,
},
),
},
),
},
),
},
),
],
},
)
```
## Errors
|
4 | # Nested await
5 | await await x
| ^^^^^^^ Syntax Error: Await expression cannot be used here
6 |
7 | # Starred expressions
|
|
7 | # Starred expressions
8 | await *x
| ^^ Syntax Error: Starred expression cannot be used here
9 | await (*x)
|
|
7 | # Starred expressions
8 | await *x
9 | await (*x)
| ^^ Syntax Error: Starred expression cannot be used here
10 |
11 | # Invalid expression as per precedence
|
|
11 | # Invalid expression as per precedence
12 | await yield x
| ^^^^^^^ Syntax Error: Yield expression cannot be used here
13 | await lambda x: x
14 | await +x
|
|
11 | # Invalid expression as per precedence
12 | await yield x
13 | await lambda x: x
| ^^^^^^^^^^^ Syntax Error: Lambda expression cannot be used here
14 | await +x
15 | await -x
|
|
12 | await yield x
13 | await lambda x: x
14 | await +x
| ^^ Syntax Error: Unary '+' expression cannot be used here
15 | await -x
16 | await ~x
|
|
13 | await lambda x: x
14 | await +x
15 | await -x
| ^^ Syntax Error: Unary '-' expression cannot be used here
16 | await ~x
17 | await not x
|
|
14 | await +x
15 | await -x
16 | await ~x
| ^^ Syntax Error: Unary '~' expression cannot be used here
17 | await not x
|
|
15 | await -x
16 | await ~x
17 | await not x
| ^^^^^ Syntax Error: Boolean 'not' expression cannot be used here
|

View file

@ -0,0 +1,116 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/bin_op/invalid_rhs_expression.py
---
## AST
```
Module(
ModModule {
range: 0..28,
body: [
Expr(
StmtExpr {
range: 0..15,
value: BinOp(
ExprBinOp {
range: 0..15,
left: Name(
ExprName {
range: 0..1,
id: "x",
ctx: Load,
},
),
op: Add,
right: Lambda(
ExprLambda {
range: 4..15,
parameters: Some(
Parameters {
range: 11..12,
posonlyargs: [],
args: [
ParameterWithDefault {
range: 11..12,
parameter: Parameter {
range: 11..12,
name: Identifier {
id: "y",
range: 11..12,
},
annotation: None,
},
default: None,
},
],
vararg: None,
kwonlyargs: [],
kwarg: None,
},
),
body: Name(
ExprName {
range: 14..15,
id: "y",
ctx: Load,
},
),
},
),
},
),
},
),
Expr(
StmtExpr {
range: 17..28,
value: BinOp(
ExprBinOp {
range: 17..28,
left: Name(
ExprName {
range: 17..18,
id: "x",
ctx: Load,
},
),
op: Sub,
right: Yield(
ExprYield {
range: 21..28,
value: Some(
Name(
ExprName {
range: 27..28,
id: "y",
ctx: Load,
},
),
),
},
),
},
),
},
),
],
},
)
```
## Errors
|
1 | x + lambda y: y
| ^^^^^^^^^^^ Syntax Error: Lambda expression cannot be used here
2 |
3 | x - yield y
|
|
1 | x + lambda y: y
2 |
3 | x - yield y
| ^^^^^^^ Syntax Error: Yield expression cannot be used here
|

View file

@ -0,0 +1,62 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/bin_op/missing_lhs.py
---
## AST
```
Module(
ModModule {
range: 0..10,
body: [
Expr(
StmtExpr {
range: 2..3,
value: Name(
ExprName {
range: 2..3,
id: "y",
ctx: Load,
},
),
},
),
Expr(
StmtExpr {
range: 5..10,
value: BinOp(
ExprBinOp {
range: 5..10,
left: NumberLiteral(
ExprNumberLiteral {
range: 5..6,
value: Int(
1,
),
},
),
op: Add,
right: NumberLiteral(
ExprNumberLiteral {
range: 9..10,
value: Int(
2,
),
},
),
},
),
},
),
],
},
)
```
## Errors
|
1 | / y
| ^ Syntax Error: Expected a statement
2 |
3 | 1 + 2
|

View file

@ -0,0 +1,76 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/bin_op/missing_rhs_0.py
---
## AST
```
Module(
ModModule {
range: 0..10,
body: [
Expr(
StmtExpr {
range: 0..3,
value: BinOp(
ExprBinOp {
range: 0..3,
left: NumberLiteral(
ExprNumberLiteral {
range: 0..1,
value: Int(
0,
),
},
),
op: Add,
right: Name(
ExprName {
range: 3..3,
id: "",
ctx: Invalid,
},
),
},
),
},
),
Expr(
StmtExpr {
range: 5..10,
value: BinOp(
ExprBinOp {
range: 5..10,
left: NumberLiteral(
ExprNumberLiteral {
range: 5..6,
value: Int(
1,
),
},
),
op: Add,
right: NumberLiteral(
ExprNumberLiteral {
range: 9..10,
value: Int(
2,
),
},
),
},
),
},
),
],
},
)
```
## Errors
|
1 | 0 +
| ^ Syntax Error: Expected an expression
2 |
3 | 1 + 2
|

View file

@ -0,0 +1,104 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/bin_op/missing_rhs_1.py
---
## AST
```
Module(
ModModule {
range: 0..18,
body: [
Expr(
StmtExpr {
range: 0..11,
value: BinOp(
ExprBinOp {
range: 0..11,
left: BinOp(
ExprBinOp {
range: 0..5,
left: NumberLiteral(
ExprNumberLiteral {
range: 0..1,
value: Int(
1,
),
},
),
op: Add,
right: NumberLiteral(
ExprNumberLiteral {
range: 4..5,
value: Int(
2,
),
},
),
},
),
op: Sub,
right: BinOp(
ExprBinOp {
range: 8..11,
left: NumberLiteral(
ExprNumberLiteral {
range: 8..9,
value: Int(
3,
),
},
),
op: Mult,
right: Name(
ExprName {
range: 11..11,
id: "",
ctx: Invalid,
},
),
},
),
},
),
},
),
Expr(
StmtExpr {
range: 13..18,
value: BinOp(
ExprBinOp {
range: 13..18,
left: NumberLiteral(
ExprNumberLiteral {
range: 13..14,
value: Int(
4,
),
},
),
op: Add,
right: NumberLiteral(
ExprNumberLiteral {
range: 17..18,
value: Int(
5,
),
},
),
},
),
},
),
],
},
)
```
## Errors
|
1 | 1 + 2 - 3 *
| ^ Syntax Error: Expected an expression
2 |
3 | 4 + 5
|

View file

@ -0,0 +1,149 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/bin_op/multiple_ops.py
---
## AST
```
Module(
ModModule {
range: 0..19,
body: [
Expr(
StmtExpr {
range: 0..3,
value: BinOp(
ExprBinOp {
range: 0..3,
left: Name(
ExprName {
range: 0..1,
id: "x",
ctx: Load,
},
),
op: Add,
right: UnaryOp(
ExprUnaryOp {
range: 2..3,
op: UAdd,
operand: Name(
ExprName {
range: 3..3,
id: "",
ctx: Invalid,
},
),
},
),
},
),
},
),
Expr(
StmtExpr {
range: 4..9,
value: BinOp(
ExprBinOp {
range: 4..9,
left: NumberLiteral(
ExprNumberLiteral {
range: 4..5,
value: Int(
1,
),
},
),
op: Add,
right: NumberLiteral(
ExprNumberLiteral {
range: 8..9,
value: Int(
2,
),
},
),
},
),
},
),
Expr(
StmtExpr {
range: 10..13,
value: BinOp(
ExprBinOp {
range: 10..13,
left: Name(
ExprName {
range: 10..11,
id: "x",
ctx: Load,
},
),
op: Sub,
right: UnaryOp(
ExprUnaryOp {
range: 12..13,
op: USub,
operand: Name(
ExprName {
range: 13..13,
id: "",
ctx: Invalid,
},
),
},
),
},
),
},
),
Expr(
StmtExpr {
range: 14..19,
value: BinOp(
ExprBinOp {
range: 14..19,
left: NumberLiteral(
ExprNumberLiteral {
range: 14..15,
value: Int(
1,
),
},
),
op: Sub,
right: NumberLiteral(
ExprNumberLiteral {
range: 18..19,
value: Int(
2,
),
},
),
},
),
},
),
],
},
)
```
## Errors
|
1 | x++
| ^ Syntax Error: Expected an expression
2 | 1 + 2
3 | x--
4 | 1 - 2
|
|
1 | x++
2 | 1 + 2
3 | x--
| ^ Syntax Error: Expected an expression
4 | 1 - 2
|

View file

@ -0,0 +1,122 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/bin_op/named_expression.py
---
## AST
```
Module(
ModModule {
range: 0..26,
body: [
Expr(
StmtExpr {
range: 0..5,
value: BinOp(
ExprBinOp {
range: 0..5,
left: Name(
ExprName {
range: 0..1,
id: "x",
ctx: Load,
},
),
op: Sub,
right: Name(
ExprName {
range: 4..5,
id: "y",
ctx: Load,
},
),
},
),
},
),
Expr(
StmtExpr {
range: 9..15,
value: Tuple(
ExprTuple {
range: 9..15,
elts: [
NumberLiteral(
ExprNumberLiteral {
range: 10..11,
value: Int(
1,
),
},
),
NumberLiteral(
ExprNumberLiteral {
range: 13..14,
value: Int(
2,
),
},
),
],
ctx: Load,
parenthesized: true,
},
),
},
),
Expr(
StmtExpr {
range: 16..21,
value: BinOp(
ExprBinOp {
range: 16..21,
left: Name(
ExprName {
range: 16..17,
id: "x",
ctx: Load,
},
),
op: Div,
right: Name(
ExprName {
range: 20..21,
id: "y",
ctx: Load,
},
),
},
),
},
),
Expr(
StmtExpr {
range: 25..26,
value: NumberLiteral(
ExprNumberLiteral {
range: 25..26,
value: Int(
2,
),
},
),
},
),
],
},
)
```
## Errors
|
1 | x - y := (1, 2)
| ^^ Syntax Error: Expected a statement
2 | x / y := 2
|
|
1 | x - y := (1, 2)
2 | x / y := 2
| ^^ Syntax Error: Expected a statement
|

View file

@ -0,0 +1,91 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/bin_op/starred_expression.py
---
## AST
```
Module(
ModModule {
range: 0..14,
body: [
Expr(
StmtExpr {
range: 0..6,
value: BinOp(
ExprBinOp {
range: 0..6,
left: Name(
ExprName {
range: 0..1,
id: "x",
ctx: Load,
},
),
op: Add,
right: Starred(
ExprStarred {
range: 4..6,
value: Name(
ExprName {
range: 5..6,
id: "y",
ctx: Load,
},
),
ctx: Load,
},
),
},
),
},
),
Expr(
StmtExpr {
range: 7..14,
value: BinOp(
ExprBinOp {
range: 7..14,
left: Name(
ExprName {
range: 7..8,
id: "x",
ctx: Load,
},
),
op: Pow,
right: Starred(
ExprStarred {
range: 12..14,
value: Name(
ExprName {
range: 13..14,
id: "y",
ctx: Load,
},
),
ctx: Load,
},
),
},
),
},
),
],
},
)
```
## Errors
|
1 | x + *y
| ^^ Syntax Error: Starred expression cannot be used here
2 | x ** *y
|
|
1 | x + *y
2 | x ** *y
| ^^ Syntax Error: Starred expression cannot be used here
|

View file

@ -0,0 +1,120 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/bool_op/invalid_rhs_expression.py
---
## AST
```
Module(
ModModule {
range: 0..31,
body: [
Expr(
StmtExpr {
range: 0..17,
value: BoolOp(
ExprBoolOp {
range: 0..17,
op: And,
values: [
Name(
ExprName {
range: 0..1,
id: "x",
ctx: Load,
},
),
Lambda(
ExprLambda {
range: 6..17,
parameters: Some(
Parameters {
range: 13..14,
posonlyargs: [],
args: [
ParameterWithDefault {
range: 13..14,
parameter: Parameter {
range: 13..14,
name: Identifier {
id: "y",
range: 13..14,
},
annotation: None,
},
default: None,
},
],
vararg: None,
kwonlyargs: [],
kwarg: None,
},
),
body: Name(
ExprName {
range: 16..17,
id: "y",
ctx: Load,
},
),
},
),
],
},
),
},
),
Expr(
StmtExpr {
range: 19..31,
value: BoolOp(
ExprBoolOp {
range: 19..31,
op: Or,
values: [
Name(
ExprName {
range: 19..20,
id: "x",
ctx: Load,
},
),
Yield(
ExprYield {
range: 24..31,
value: Some(
Name(
ExprName {
range: 30..31,
id: "y",
ctx: Load,
},
),
),
},
),
],
},
),
},
),
],
},
)
```
## Errors
|
1 | x and lambda y: y
| ^^^^^^^^^^^ Syntax Error: Lambda expression cannot be used here
2 |
3 | x or yield y
|
|
1 | x and lambda y: y
2 |
3 | x or yield y
| ^^^^^^^ Syntax Error: Yield expression cannot be used here
|

View file

@ -0,0 +1,33 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/bool_op/missing_lhs.py
---
## AST
```
Module(
ModModule {
range: 0..5,
body: [
Expr(
StmtExpr {
range: 4..5,
value: Name(
ExprName {
range: 4..5,
id: "y",
ctx: Load,
},
),
},
),
],
},
)
```
## Errors
|
1 | and y
| ^^^ Syntax Error: Expected a statement
|

View file

@ -0,0 +1,77 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/bool_op/missing_rhs.py
---
## AST
```
Module(
ModModule {
range: 0..12,
body: [
Expr(
StmtExpr {
range: 0..5,
value: BoolOp(
ExprBoolOp {
range: 0..5,
op: And,
values: [
Name(
ExprName {
range: 0..1,
id: "x",
ctx: Load,
},
),
Name(
ExprName {
range: 5..5,
id: "",
ctx: Invalid,
},
),
],
},
),
},
),
Expr(
StmtExpr {
range: 7..12,
value: BinOp(
ExprBinOp {
range: 7..12,
left: NumberLiteral(
ExprNumberLiteral {
range: 7..8,
value: Int(
1,
),
},
),
op: Add,
right: NumberLiteral(
ExprNumberLiteral {
range: 11..12,
value: Int(
2,
),
},
),
},
),
},
),
],
},
)
```
## Errors
|
1 | x and
| ^ Syntax Error: Expected an expression
2 |
3 | 1 + 2
|

View file

@ -0,0 +1,107 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/bool_op/named_expression.py
---
## AST
```
Module(
ModModule {
range: 0..24,
body: [
Expr(
StmtExpr {
range: 0..7,
value: BoolOp(
ExprBoolOp {
range: 0..7,
op: And,
values: [
Name(
ExprName {
range: 0..1,
id: "x",
ctx: Load,
},
),
Name(
ExprName {
range: 6..7,
id: "a",
ctx: Load,
},
),
],
},
),
},
),
Expr(
StmtExpr {
range: 11..12,
value: Name(
ExprName {
range: 11..12,
id: "b",
ctx: Load,
},
),
},
),
Expr(
StmtExpr {
range: 13..19,
value: BoolOp(
ExprBoolOp {
range: 13..19,
op: Or,
values: [
Name(
ExprName {
range: 13..14,
id: "x",
ctx: Load,
},
),
Name(
ExprName {
range: 18..19,
id: "a",
ctx: Load,
},
),
],
},
),
},
),
Expr(
StmtExpr {
range: 23..24,
value: Name(
ExprName {
range: 23..24,
id: "b",
ctx: Load,
},
),
},
),
],
},
)
```
## Errors
|
1 | x and a := b
| ^^ Syntax Error: Expected a statement
2 | x or a := b
|
|
1 | x and a := b
2 | x or a := b
| ^^ Syntax Error: Expected a statement
|

View file

@ -0,0 +1,95 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/bool_op/starred_expression.py
---
## AST
```
Module(
ModModule {
range: 0..16,
body: [
Expr(
StmtExpr {
range: 0..8,
value: BoolOp(
ExprBoolOp {
range: 0..8,
op: And,
values: [
Name(
ExprName {
range: 0..1,
id: "x",
ctx: Load,
},
),
Starred(
ExprStarred {
range: 6..8,
value: Name(
ExprName {
range: 7..8,
id: "y",
ctx: Load,
},
),
ctx: Load,
},
),
],
},
),
},
),
Expr(
StmtExpr {
range: 9..16,
value: BoolOp(
ExprBoolOp {
range: 9..16,
op: Or,
values: [
Name(
ExprName {
range: 9..10,
id: "x",
ctx: Load,
},
),
Starred(
ExprStarred {
range: 14..16,
value: Name(
ExprName {
range: 15..16,
id: "y",
ctx: Load,
},
),
ctx: Load,
},
),
],
},
),
},
),
],
},
)
```
## Errors
|
1 | x and *y
| ^^ Syntax Error: Starred expression cannot be used here
2 | x or *y
|
|
1 | x and *y
2 | x or *y
| ^^ Syntax Error: Starred expression cannot be used here
|

View file

@ -0,0 +1,168 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/compare/invalid_order.py
---
## AST
```
Module(
ModModule {
range: 0..131,
body: [
Expr(
StmtExpr {
range: 0..10,
value: Compare(
ExprCompare {
range: 0..10,
left: Name(
ExprName {
range: 0..1,
id: "x",
ctx: Load,
},
),
ops: [
In,
],
comparators: [
UnaryOp(
ExprUnaryOp {
range: 5..10,
op: Not,
operand: Name(
ExprName {
range: 9..10,
id: "y",
ctx: Load,
},
),
},
),
],
},
),
},
),
Assign(
StmtAssign {
range: 35..41,
targets: [
Name(
ExprName {
range: 35..36,
id: "x",
ctx: Store,
},
),
],
value: Compare(
ExprCompare {
range: 38..41,
left: Name(
ExprName {
range: 38..38,
id: "",
ctx: Invalid,
},
),
ops: [
Gt,
],
comparators: [
Name(
ExprName {
range: 40..41,
id: "y",
ctx: Load,
},
),
],
},
),
},
),
Expr(
StmtExpr {
range: 120..121,
value: Name(
ExprName {
range: 120..121,
id: "x",
ctx: Load,
},
),
},
),
Expr(
StmtExpr {
range: 122..128,
value: UnaryOp(
ExprUnaryOp {
range: 122..128,
op: Not,
operand: Name(
ExprName {
range: 126..128,
id: "is",
ctx: Load,
},
),
},
),
},
),
Expr(
StmtExpr {
range: 129..130,
value: Name(
ExprName {
range: 129..130,
id: "y",
ctx: Load,
},
),
},
),
],
},
)
```
## Errors
|
1 | x in not y
| ^^^^^ Syntax Error: Boolean 'not' expression cannot be used here
2 |
3 | # `=>` instead of `>=`
|
|
3 | # `=>` instead of `>=`
4 | x => y
| ^ Syntax Error: Expected an expression
5 |
6 | # Same here as well, `not` without `in` is considered to be a unary operator
|
|
6 | # Same here as well, `not` without `in` is considered to be a unary operator
7 | x not is y
| ^^^ Syntax Error: Simple statements must be separated by newlines or semicolons
|
|
6 | # Same here as well, `not` without `in` is considered to be a unary operator
7 | x not is y
| ^^ Syntax Error: Expected an identifier, but found a keyword 'is' that cannot be used here
|
|
6 | # Same here as well, `not` without `in` is considered to be a unary operator
7 | x not is y
| ^ Syntax Error: Simple statements must be separated by newlines or semicolons
|

View file

@ -0,0 +1,124 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/compare/invalid_rhs_expression.py
---
## AST
```
Module(
ModModule {
range: 0..34,
body: [
Expr(
StmtExpr {
range: 0..20,
value: Compare(
ExprCompare {
range: 0..20,
left: Name(
ExprName {
range: 0..1,
id: "x",
ctx: Load,
},
),
ops: [
NotIn,
],
comparators: [
Lambda(
ExprLambda {
range: 9..20,
parameters: Some(
Parameters {
range: 16..17,
posonlyargs: [],
args: [
ParameterWithDefault {
range: 16..17,
parameter: Parameter {
range: 16..17,
name: Identifier {
id: "y",
range: 16..17,
},
annotation: None,
},
default: None,
},
],
vararg: None,
kwonlyargs: [],
kwarg: None,
},
),
body: Name(
ExprName {
range: 19..20,
id: "y",
ctx: Load,
},
),
},
),
],
},
),
},
),
Expr(
StmtExpr {
range: 22..34,
value: Compare(
ExprCompare {
range: 22..34,
left: Name(
ExprName {
range: 22..23,
id: "x",
ctx: Load,
},
),
ops: [
Eq,
],
comparators: [
Yield(
ExprYield {
range: 27..34,
value: Some(
Name(
ExprName {
range: 33..34,
id: "y",
ctx: Load,
},
),
),
},
),
],
},
),
},
),
],
},
)
```
## Errors
|
1 | x not in lambda y: y
| ^^^^^^^^^^^ Syntax Error: Lambda expression cannot be used here
2 |
3 | x == yield y
|
|
1 | x not in lambda y: y
2 |
3 | x == yield y
| ^^^^^^^ Syntax Error: Yield expression cannot be used here
|

View file

@ -0,0 +1,62 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/compare/missing_lhs.py
---
## AST
```
Module(
ModModule {
range: 0..10,
body: [
Expr(
StmtExpr {
range: 2..3,
value: Name(
ExprName {
range: 2..3,
id: "y",
ctx: Load,
},
),
},
),
Expr(
StmtExpr {
range: 5..10,
value: BinOp(
ExprBinOp {
range: 5..10,
left: NumberLiteral(
ExprNumberLiteral {
range: 5..6,
value: Int(
1,
),
},
),
op: Add,
right: NumberLiteral(
ExprNumberLiteral {
range: 9..10,
value: Int(
2,
),
},
),
},
),
},
),
],
},
)
```
## Errors
|
1 | > y
| ^ Syntax Error: Expected a statement
2 |
3 | 1 + 2
|

View file

@ -0,0 +1,79 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/compare/missing_rhs_0.py
---
## AST
```
Module(
ModModule {
range: 0..10,
body: [
Expr(
StmtExpr {
range: 0..3,
value: Compare(
ExprCompare {
range: 0..3,
left: Name(
ExprName {
range: 0..1,
id: "x",
ctx: Load,
},
),
ops: [
Gt,
],
comparators: [
Name(
ExprName {
range: 3..3,
id: "",
ctx: Invalid,
},
),
],
},
),
},
),
Expr(
StmtExpr {
range: 5..10,
value: BinOp(
ExprBinOp {
range: 5..10,
left: NumberLiteral(
ExprNumberLiteral {
range: 5..6,
value: Int(
1,
),
},
),
op: Add,
right: NumberLiteral(
ExprNumberLiteral {
range: 9..10,
value: Int(
2,
),
},
),
},
),
},
),
],
},
)
```
## Errors
|
1 | x >
| ^ Syntax Error: Expected an expression
2 |
3 | 1 + 2
|

View file

@ -0,0 +1,90 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/compare/missing_rhs_1.py
---
## AST
```
Module(
ModModule {
range: 0..71,
body: [
Expr(
StmtExpr {
range: 59..60,
value: Name(
ExprName {
range: 59..60,
id: "x",
ctx: Load,
},
),
},
),
Expr(
StmtExpr {
range: 61..64,
value: UnaryOp(
ExprUnaryOp {
range: 61..64,
op: Not,
operand: Name(
ExprName {
range: 64..64,
id: "",
ctx: Invalid,
},
),
},
),
},
),
Expr(
StmtExpr {
range: 66..71,
value: BinOp(
ExprBinOp {
range: 66..71,
left: NumberLiteral(
ExprNumberLiteral {
range: 66..67,
value: Int(
1,
),
},
),
op: Add,
right: NumberLiteral(
ExprNumberLiteral {
range: 70..71,
value: Int(
2,
),
},
),
},
),
},
),
],
},
)
```
## Errors
|
1 | # Without the `in`, this is considered to be a unary `not`
2 | x not
| ^^^ Syntax Error: Simple statements must be separated by newlines or semicolons
3 |
4 | 1 + 2
|
|
1 | # Without the `in`, this is considered to be a unary `not`
2 | x not
| ^ Syntax Error: Expected an expression
3 |
4 | 1 + 2
|

View file

@ -0,0 +1,79 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/compare/missing_rhs_2.py
---
## AST
```
Module(
ModModule {
range: 0..15,
body: [
Expr(
StmtExpr {
range: 0..8,
value: Compare(
ExprCompare {
range: 0..8,
left: Name(
ExprName {
range: 0..1,
id: "x",
ctx: Load,
},
),
ops: [
IsNot,
],
comparators: [
Name(
ExprName {
range: 8..8,
id: "",
ctx: Invalid,
},
),
],
},
),
},
),
Expr(
StmtExpr {
range: 10..15,
value: BinOp(
ExprBinOp {
range: 10..15,
left: NumberLiteral(
ExprNumberLiteral {
range: 10..11,
value: Int(
1,
),
},
),
op: Add,
right: NumberLiteral(
ExprNumberLiteral {
range: 14..15,
value: Int(
2,
),
},
),
},
),
},
),
],
},
)
```
## Errors
|
1 | x is not
| ^ Syntax Error: Expected an expression
2 |
3 | 1 + 2
|

View file

@ -0,0 +1,123 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/compare/multiple_equals.py
---
## AST
```
Module(
ModModule {
range: 0..41,
body: [
Assign(
StmtAssign {
range: 25..32,
targets: [
Compare(
ExprCompare {
range: 25..29,
left: Name(
ExprName {
range: 25..26,
id: "x",
ctx: Load,
},
),
ops: [
Eq,
],
comparators: [
Name(
ExprName {
range: 29..29,
id: "",
ctx: Invalid,
},
),
],
},
),
],
value: Name(
ExprName {
range: 31..32,
id: "y",
ctx: Load,
},
),
},
),
Assign(
StmtAssign {
range: 33..40,
targets: [
Compare(
ExprCompare {
range: 33..37,
left: Name(
ExprName {
range: 33..34,
id: "x",
ctx: Load,
},
),
ops: [
NotEq,
],
comparators: [
Name(
ExprName {
range: 37..37,
id: "",
ctx: Invalid,
},
),
],
},
),
],
value: Name(
ExprName {
range: 39..40,
id: "y",
ctx: Load,
},
),
},
),
],
},
)
```
## Errors
|
1 | # This is not JavaScript
2 | x === y
| ^ Syntax Error: Expected an expression
3 | x !== y
|
|
1 | # This is not JavaScript
2 | x === y
| ^^^^ Syntax Error: Invalid assignment target
3 | x !== y
|
|
1 | # This is not JavaScript
2 | x === y
3 | x !== y
| ^ Syntax Error: Expected an expression
|
|
1 | # This is not JavaScript
2 | x === y
3 | x !== y
| ^^^^ Syntax Error: Invalid assignment target
|

View file

@ -0,0 +1,130 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/compare/named_expression.py
---
## AST
```
Module(
ModModule {
range: 0..31,
body: [
Expr(
StmtExpr {
range: 0..10,
value: Compare(
ExprCompare {
range: 0..10,
left: Name(
ExprName {
range: 0..1,
id: "x",
ctx: Load,
},
),
ops: [
NotIn,
],
comparators: [
Name(
ExprName {
range: 9..10,
id: "y",
ctx: Load,
},
),
],
},
),
},
),
Expr(
StmtExpr {
range: 14..20,
value: Tuple(
ExprTuple {
range: 14..20,
elts: [
NumberLiteral(
ExprNumberLiteral {
range: 15..16,
value: Int(
1,
),
},
),
NumberLiteral(
ExprNumberLiteral {
range: 18..19,
value: Int(
2,
),
},
),
],
ctx: Load,
parenthesized: true,
},
),
},
),
Expr(
StmtExpr {
range: 21..26,
value: Compare(
ExprCompare {
range: 21..26,
left: Name(
ExprName {
range: 21..22,
id: "x",
ctx: Load,
},
),
ops: [
Gt,
],
comparators: [
Name(
ExprName {
range: 25..26,
id: "y",
ctx: Load,
},
),
],
},
),
},
),
Expr(
StmtExpr {
range: 30..31,
value: NumberLiteral(
ExprNumberLiteral {
range: 30..31,
value: Int(
2,
),
},
),
},
),
],
},
)
```
## Errors
|
1 | x not in y := (1, 2)
| ^^ Syntax Error: Expected a statement
2 | x > y := 2
|
|
1 | x not in y := (1, 2)
2 | x > y := 2
| ^^ Syntax Error: Expected a statement
|

View file

@ -0,0 +1,187 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/compare/starred_expression.py
---
## AST
```
Module(
ModModule {
range: 0..39,
body: [
Expr(
StmtExpr {
range: 0..7,
value: Compare(
ExprCompare {
range: 0..7,
left: Name(
ExprName {
range: 0..1,
id: "x",
ctx: Load,
},
),
ops: [
GtE,
],
comparators: [
Starred(
ExprStarred {
range: 5..7,
value: Name(
ExprName {
range: 6..7,
id: "y",
ctx: Load,
},
),
ctx: Load,
},
),
],
},
),
},
),
Expr(
StmtExpr {
range: 8..19,
value: Compare(
ExprCompare {
range: 8..19,
left: Name(
ExprName {
range: 8..9,
id: "x",
ctx: Load,
},
),
ops: [
NotIn,
],
comparators: [
Starred(
ExprStarred {
range: 17..19,
value: Name(
ExprName {
range: 18..19,
id: "y",
ctx: Load,
},
),
ctx: Load,
},
),
],
},
),
},
),
Expr(
StmtExpr {
range: 21..27,
value: Starred(
ExprStarred {
range: 21..27,
value: Compare(
ExprCompare {
range: 22..27,
left: Name(
ExprName {
range: 22..23,
id: "x",
ctx: Load,
},
),
ops: [
Lt,
],
comparators: [
Name(
ExprName {
range: 26..27,
id: "y",
ctx: Load,
},
),
],
},
),
ctx: Load,
},
),
},
),
Expr(
StmtExpr {
range: 28..39,
value: Starred(
ExprStarred {
range: 28..39,
value: Compare(
ExprCompare {
range: 29..39,
left: Name(
ExprName {
range: 29..30,
id: "x",
ctx: Load,
},
),
ops: [
IsNot,
],
comparators: [
Name(
ExprName {
range: 38..39,
id: "y",
ctx: Load,
},
),
],
},
),
ctx: Load,
},
),
},
),
],
},
)
```
## Errors
|
1 | x >= *y
| ^^ Syntax Error: Starred expression cannot be used here
2 | x not in *y
|
|
1 | x >= *y
2 | x not in *y
| ^^ Syntax Error: Starred expression cannot be used here
3 |
4 | *x < y
|
|
2 | x not in *y
3 |
4 | *x < y
| ^^^^^ Syntax Error: Comparison expression cannot be used here
5 | *x is not y
|
|
4 | *x < y
5 | *x is not y
| ^^^^^^^^^^ Syntax Error: Comparison expression cannot be used here
|

View file

@ -0,0 +1,827 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/dict/comprehension.py
---
## AST
```
Module(
ModModule {
range: 0..362,
body: [
Expr(
StmtExpr {
range: 17..34,
value: DictComp(
ExprDictComp {
range: 17..34,
key: Name(
ExprName {
range: 18..19,
id: "x",
ctx: Load,
},
),
value: Name(
ExprName {
range: 21..22,
id: "y",
ctx: Load,
},
),
generators: [
Comprehension {
range: 23..33,
target: NumberLiteral(
ExprNumberLiteral {
range: 27..28,
value: Int(
1,
),
},
),
iter: Name(
ExprName {
range: 32..33,
id: "y",
ctx: Load,
},
),
ifs: [],
is_async: false,
},
],
},
),
},
),
Expr(
StmtExpr {
range: 35..54,
value: DictComp(
ExprDictComp {
range: 35..54,
key: Name(
ExprName {
range: 36..37,
id: "x",
ctx: Load,
},
),
value: Name(
ExprName {
range: 39..40,
id: "y",
ctx: Load,
},
),
generators: [
Comprehension {
range: 41..53,
target: StringLiteral(
ExprStringLiteral {
range: 45..48,
value: StringLiteralValue {
inner: Single(
StringLiteral {
range: 45..48,
value: "a",
flags: StringLiteralFlags {
quote_style: Single,
prefix: Empty,
triple_quoted: false,
},
},
),
},
},
),
iter: Name(
ExprName {
range: 52..53,
id: "y",
ctx: Load,
},
),
ifs: [],
is_async: false,
},
],
},
),
},
),
Expr(
StmtExpr {
range: 55..77,
value: DictComp(
ExprDictComp {
range: 55..77,
key: Name(
ExprName {
range: 56..57,
id: "x",
ctx: Load,
},
),
value: Name(
ExprName {
range: 59..60,
id: "y",
ctx: Load,
},
),
generators: [
Comprehension {
range: 61..76,
target: Call(
ExprCall {
range: 65..71,
func: Name(
ExprName {
range: 65..69,
id: "call",
ctx: Load,
},
),
arguments: Arguments {
range: 69..71,
args: [],
keywords: [],
},
},
),
iter: Name(
ExprName {
range: 75..76,
id: "y",
ctx: Load,
},
),
ifs: [],
is_async: false,
},
],
},
),
},
),
Expr(
StmtExpr {
range: 78..100,
value: DictComp(
ExprDictComp {
range: 78..100,
key: Name(
ExprName {
range: 79..80,
id: "x",
ctx: Load,
},
),
value: Name(
ExprName {
range: 82..83,
id: "y",
ctx: Load,
},
),
generators: [
Comprehension {
range: 84..99,
target: Set(
ExprSet {
range: 88..94,
elts: [
Name(
ExprName {
range: 89..90,
id: "a",
ctx: Load,
},
),
Name(
ExprName {
range: 92..93,
id: "b",
ctx: Load,
},
),
],
},
),
iter: Name(
ExprName {
range: 98..99,
id: "y",
ctx: Load,
},
),
ifs: [],
is_async: false,
},
],
},
),
},
),
Expr(
StmtExpr {
range: 117..135,
value: DictComp(
ExprDictComp {
range: 117..135,
key: Name(
ExprName {
range: 118..119,
id: "x",
ctx: Load,
},
),
value: Name(
ExprName {
range: 121..122,
id: "y",
ctx: Load,
},
),
generators: [
Comprehension {
range: 123..134,
target: Name(
ExprName {
range: 127..128,
id: "x",
ctx: Store,
},
),
iter: Starred(
ExprStarred {
range: 132..134,
value: Name(
ExprName {
range: 133..134,
id: "y",
ctx: Load,
},
),
ctx: Load,
},
),
ifs: [],
is_async: false,
},
],
},
),
},
),
Expr(
StmtExpr {
range: 136..159,
value: DictComp(
ExprDictComp {
range: 136..159,
key: Name(
ExprName {
range: 137..138,
id: "x",
ctx: Load,
},
),
value: Name(
ExprName {
range: 140..141,
id: "y",
ctx: Load,
},
),
generators: [
Comprehension {
range: 142..158,
target: Name(
ExprName {
range: 146..147,
id: "x",
ctx: Store,
},
),
iter: Yield(
ExprYield {
range: 151..158,
value: Some(
Name(
ExprName {
range: 157..158,
id: "y",
ctx: Load,
},
),
),
},
),
ifs: [],
is_async: false,
},
],
},
),
},
),
Expr(
StmtExpr {
range: 160..188,
value: DictComp(
ExprDictComp {
range: 160..188,
key: Name(
ExprName {
range: 161..162,
id: "x",
ctx: Load,
},
),
value: Name(
ExprName {
range: 164..165,
id: "y",
ctx: Load,
},
),
generators: [
Comprehension {
range: 166..187,
target: Name(
ExprName {
range: 170..171,
id: "x",
ctx: Store,
},
),
iter: YieldFrom(
ExprYieldFrom {
range: 175..187,
value: Name(
ExprName {
range: 186..187,
id: "y",
ctx: Load,
},
),
},
),
ifs: [],
is_async: false,
},
],
},
),
},
),
Expr(
StmtExpr {
range: 189..216,
value: DictComp(
ExprDictComp {
range: 189..216,
key: Name(
ExprName {
range: 190..191,
id: "x",
ctx: Load,
},
),
value: Name(
ExprName {
range: 193..194,
id: "y",
ctx: Load,
},
),
generators: [
Comprehension {
range: 195..215,
target: Name(
ExprName {
range: 199..200,
id: "x",
ctx: Store,
},
),
iter: Lambda(
ExprLambda {
range: 204..215,
parameters: Some(
Parameters {
range: 211..212,
posonlyargs: [],
args: [
ParameterWithDefault {
range: 211..212,
parameter: Parameter {
range: 211..212,
name: Identifier {
id: "y",
range: 211..212,
},
annotation: None,
},
default: None,
},
],
vararg: None,
kwonlyargs: [],
kwarg: None,
},
),
body: Name(
ExprName {
range: 214..215,
id: "y",
ctx: Load,
},
),
},
),
ifs: [],
is_async: false,
},
],
},
),
},
),
Expr(
StmtExpr {
range: 231..257,
value: DictComp(
ExprDictComp {
range: 231..257,
key: Name(
ExprName {
range: 232..233,
id: "x",
ctx: Load,
},
),
value: Name(
ExprName {
range: 235..236,
id: "y",
ctx: Load,
},
),
generators: [
Comprehension {
range: 237..256,
target: Name(
ExprName {
range: 241..242,
id: "x",
ctx: Store,
},
),
iter: Name(
ExprName {
range: 246..250,
id: "data",
ctx: Load,
},
),
ifs: [
Starred(
ExprStarred {
range: 254..256,
value: Name(
ExprName {
range: 255..256,
id: "y",
ctx: Load,
},
),
ctx: Load,
},
),
],
is_async: false,
},
],
},
),
},
),
Expr(
StmtExpr {
range: 258..289,
value: DictComp(
ExprDictComp {
range: 258..289,
key: Name(
ExprName {
range: 259..260,
id: "x",
ctx: Load,
},
),
value: Name(
ExprName {
range: 262..263,
id: "y",
ctx: Load,
},
),
generators: [
Comprehension {
range: 264..288,
target: Name(
ExprName {
range: 268..269,
id: "x",
ctx: Store,
},
),
iter: Name(
ExprName {
range: 273..277,
id: "data",
ctx: Load,
},
),
ifs: [
Yield(
ExprYield {
range: 281..288,
value: Some(
Name(
ExprName {
range: 287..288,
id: "y",
ctx: Load,
},
),
),
},
),
],
is_async: false,
},
],
},
),
},
),
Expr(
StmtExpr {
range: 290..326,
value: DictComp(
ExprDictComp {
range: 290..326,
key: Name(
ExprName {
range: 291..292,
id: "x",
ctx: Load,
},
),
value: Name(
ExprName {
range: 294..295,
id: "y",
ctx: Load,
},
),
generators: [
Comprehension {
range: 296..325,
target: Name(
ExprName {
range: 300..301,
id: "x",
ctx: Store,
},
),
iter: Name(
ExprName {
range: 305..309,
id: "data",
ctx: Load,
},
),
ifs: [
YieldFrom(
ExprYieldFrom {
range: 313..325,
value: Name(
ExprName {
range: 324..325,
id: "y",
ctx: Load,
},
),
},
),
],
is_async: false,
},
],
},
),
},
),
Expr(
StmtExpr {
range: 327..362,
value: DictComp(
ExprDictComp {
range: 327..362,
key: Name(
ExprName {
range: 328..329,
id: "x",
ctx: Load,
},
),
value: Name(
ExprName {
range: 331..332,
id: "y",
ctx: Load,
},
),
generators: [
Comprehension {
range: 333..361,
target: Name(
ExprName {
range: 337..338,
id: "x",
ctx: Store,
},
),
iter: Name(
ExprName {
range: 342..346,
id: "data",
ctx: Load,
},
),
ifs: [
Lambda(
ExprLambda {
range: 350..361,
parameters: Some(
Parameters {
range: 357..358,
posonlyargs: [],
args: [
ParameterWithDefault {
range: 357..358,
parameter: Parameter {
range: 357..358,
name: Identifier {
id: "y",
range: 357..358,
},
annotation: None,
},
default: None,
},
],
vararg: None,
kwonlyargs: [],
kwarg: None,
},
),
body: Name(
ExprName {
range: 360..361,
id: "y",
ctx: Load,
},
),
},
),
],
is_async: false,
},
],
},
),
},
),
],
},
)
```
## Errors
|
1 | # Invalid target
2 | {x: y for 1 in y}
| ^ Syntax Error: Invalid assignment target
3 | {x: y for 'a' in y}
4 | {x: y for call() in y}
|
|
1 | # Invalid target
2 | {x: y for 1 in y}
3 | {x: y for 'a' in y}
| ^^^ Syntax Error: Invalid assignment target
4 | {x: y for call() in y}
5 | {x: y for {a, b} in y}
|
|
2 | {x: y for 1 in y}
3 | {x: y for 'a' in y}
4 | {x: y for call() in y}
| ^^^^^^ Syntax Error: Invalid assignment target
5 | {x: y for {a, b} in y}
|
|
3 | {x: y for 'a' in y}
4 | {x: y for call() in y}
5 | {x: y for {a, b} in y}
| ^^^^^^ Syntax Error: Invalid assignment target
6 |
7 | # Invalid iter
|
|
7 | # Invalid iter
8 | {x: y for x in *y}
| ^^ Syntax Error: Starred expression cannot be used here
9 | {x: y for x in yield y}
10 | {x: y for x in yield from y}
|
|
7 | # Invalid iter
8 | {x: y for x in *y}
9 | {x: y for x in yield y}
| ^^^^^^^ Syntax Error: Yield expression cannot be used here
10 | {x: y for x in yield from y}
11 | {x: y for x in lambda y: y}
|
|
8 | {x: y for x in *y}
9 | {x: y for x in yield y}
10 | {x: y for x in yield from y}
| ^^^^^^^^^^^^ Syntax Error: Yield expression cannot be used here
11 | {x: y for x in lambda y: y}
|
|
9 | {x: y for x in yield y}
10 | {x: y for x in yield from y}
11 | {x: y for x in lambda y: y}
| ^^^^^^^^^^^ Syntax Error: Lambda expression cannot be used here
12 |
13 | # Invalid if
|
|
13 | # Invalid if
14 | {x: y for x in data if *y}
| ^^ Syntax Error: Starred expression cannot be used here
15 | {x: y for x in data if yield y}
16 | {x: y for x in data if yield from y}
|
|
13 | # Invalid if
14 | {x: y for x in data if *y}
15 | {x: y for x in data if yield y}
| ^^^^^^^ Syntax Error: Yield expression cannot be used here
16 | {x: y for x in data if yield from y}
17 | {x: y for x in data if lambda y: y}
|
|
14 | {x: y for x in data if *y}
15 | {x: y for x in data if yield y}
16 | {x: y for x in data if yield from y}
| ^^^^^^^^^^^^ Syntax Error: Yield expression cannot be used here
17 | {x: y for x in data if lambda y: y}
|
|
15 | {x: y for x in data if yield y}
16 | {x: y for x in data if yield from y}
17 | {x: y for x in data if lambda y: y}
| ^^^^^^^^^^^ Syntax Error: Lambda expression cannot be used here
|

View file

@ -0,0 +1,561 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/dict/double_star.py
---
## AST
```
Module(
ModModule {
range: 0..278,
body: [
Expr(
StmtExpr {
range: 125..135,
value: Dict(
ExprDict {
range: 125..135,
keys: [
None,
Some(
NumberLiteral(
ExprNumberLiteral {
range: 133..134,
value: Int(
1,
),
},
),
),
],
values: [
Name(
ExprName {
range: 128..129,
id: "x",
ctx: Load,
},
),
Name(
ExprName {
range: 134..134,
id: "",
ctx: Invalid,
},
),
],
},
),
},
),
Expr(
StmtExpr {
range: 136..162,
value: Dict(
ExprDict {
range: 136..162,
keys: [
Some(
Name(
ExprName {
range: 137..138,
id: "a",
ctx: Load,
},
),
),
None,
],
values: [
NumberLiteral(
ExprNumberLiteral {
range: 140..141,
value: Int(
1,
),
},
),
If(
ExprIf {
range: 145..161,
test: BooleanLiteral(
ExprBooleanLiteral {
range: 150..154,
value: true,
},
),
body: Name(
ExprName {
range: 145..146,
id: "x",
ctx: Load,
},
),
orelse: Name(
ExprName {
range: 160..161,
id: "y",
ctx: Load,
},
),
},
),
],
},
),
},
),
Expr(
StmtExpr {
range: 163..184,
value: Dict(
ExprDict {
range: 163..184,
keys: [
None,
Some(
Name(
ExprName {
range: 179..180,
id: "b",
ctx: Load,
},
),
),
],
values: [
Lambda(
ExprLambda {
range: 166..177,
parameters: Some(
Parameters {
range: 173..174,
posonlyargs: [],
args: [
ParameterWithDefault {
range: 173..174,
parameter: Parameter {
range: 173..174,
name: Identifier {
id: "x",
range: 173..174,
},
annotation: None,
},
default: None,
},
],
vararg: None,
kwonlyargs: [],
kwarg: None,
},
),
body: Name(
ExprName {
range: 176..177,
id: "x",
ctx: Load,
},
),
},
),
NumberLiteral(
ExprNumberLiteral {
range: 182..183,
value: Int(
2,
),
},
),
],
},
),
},
),
Expr(
StmtExpr {
range: 185..201,
value: Dict(
ExprDict {
range: 185..201,
keys: [
Some(
Name(
ExprName {
range: 186..187,
id: "a",
ctx: Load,
},
),
),
None,
],
values: [
NumberLiteral(
ExprNumberLiteral {
range: 189..190,
value: Int(
1,
),
},
),
BoolOp(
ExprBoolOp {
range: 194..200,
op: Or,
values: [
Name(
ExprName {
range: 194..195,
id: "x",
ctx: Load,
},
),
Name(
ExprName {
range: 199..200,
id: "y",
ctx: Load,
},
),
],
},
),
],
},
),
},
),
Expr(
StmtExpr {
range: 202..219,
value: Dict(
ExprDict {
range: 202..219,
keys: [
None,
Some(
Name(
ExprName {
range: 214..215,
id: "b",
ctx: Load,
},
),
),
],
values: [
BoolOp(
ExprBoolOp {
range: 205..212,
op: And,
values: [
Name(
ExprName {
range: 205..206,
id: "x",
ctx: Load,
},
),
Name(
ExprName {
range: 211..212,
id: "y",
ctx: Load,
},
),
],
},
),
NumberLiteral(
ExprNumberLiteral {
range: 217..218,
value: Int(
2,
),
},
),
],
},
),
},
),
Expr(
StmtExpr {
range: 220..241,
value: Dict(
ExprDict {
range: 220..241,
keys: [
Some(
Name(
ExprName {
range: 221..222,
id: "a",
ctx: Load,
},
),
),
None,
Some(
Name(
ExprName {
range: 236..237,
id: "b",
ctx: Load,
},
),
),
],
values: [
NumberLiteral(
ExprNumberLiteral {
range: 224..225,
value: Int(
1,
),
},
),
UnaryOp(
ExprUnaryOp {
range: 229..234,
op: Not,
operand: Name(
ExprName {
range: 233..234,
id: "x",
ctx: Load,
},
),
},
),
NumberLiteral(
ExprNumberLiteral {
range: 239..240,
value: Int(
2,
),
},
),
],
},
),
},
),
Expr(
StmtExpr {
range: 242..252,
value: Dict(
ExprDict {
range: 242..252,
keys: [
None,
],
values: [
Compare(
ExprCompare {
range: 245..251,
left: Name(
ExprName {
range: 245..246,
id: "x",
ctx: Load,
},
),
ops: [
In,
],
comparators: [
Name(
ExprName {
range: 250..251,
id: "y",
ctx: Load,
},
),
],
},
),
],
},
),
},
),
Expr(
StmtExpr {
range: 253..267,
value: Dict(
ExprDict {
range: 253..267,
keys: [
None,
],
values: [
Compare(
ExprCompare {
range: 256..266,
left: Name(
ExprName {
range: 256..257,
id: "x",
ctx: Load,
},
),
ops: [
NotIn,
],
comparators: [
Name(
ExprName {
range: 265..266,
id: "y",
ctx: Load,
},
),
],
},
),
],
},
),
},
),
Expr(
StmtExpr {
range: 268..277,
value: Dict(
ExprDict {
range: 268..277,
keys: [
None,
],
values: [
Compare(
ExprCompare {
range: 271..276,
left: Name(
ExprName {
range: 271..272,
id: "x",
ctx: Load,
},
),
ops: [
Lt,
],
comparators: [
Name(
ExprName {
range: 275..276,
id: "y",
ctx: Load,
},
),
],
},
),
],
},
),
},
),
],
},
)
```
## Errors
|
2 | # the ones which are higher than that.
3 |
4 | {**x := 1}
| ^^ Syntax Error: Expected ',', found ':='
5 | {a: 1, **x if True else y}
6 | {**lambda x: x, b: 2}
|
|
2 | # the ones which are higher than that.
3 |
4 | {**x := 1}
| ^ Syntax Error: Expected ':', found '}'
5 | {a: 1, **x if True else y}
6 | {**lambda x: x, b: 2}
|
|
4 | {**x := 1}
5 | {a: 1, **x if True else y}
| ^^^^^^^^^^^^^^^^ Syntax Error: Conditional expression cannot be used here
6 | {**lambda x: x, b: 2}
7 | {a: 1, **x or y}
|
|
4 | {**x := 1}
5 | {a: 1, **x if True else y}
6 | {**lambda x: x, b: 2}
| ^^^^^^^^^^^ Syntax Error: Lambda expression cannot be used here
7 | {a: 1, **x or y}
8 | {**x and y, b: 2}
|
|
5 | {a: 1, **x if True else y}
6 | {**lambda x: x, b: 2}
7 | {a: 1, **x or y}
| ^^^^^^ Syntax Error: Boolean expression cannot be used here
8 | {**x and y, b: 2}
9 | {a: 1, **not x, b: 2}
|
|
6 | {**lambda x: x, b: 2}
7 | {a: 1, **x or y}
8 | {**x and y, b: 2}
| ^^^^^^^ Syntax Error: Boolean expression cannot be used here
9 | {a: 1, **not x, b: 2}
10 | {**x in y}
|
|
7 | {a: 1, **x or y}
8 | {**x and y, b: 2}
9 | {a: 1, **not x, b: 2}
| ^^^^^ Syntax Error: Boolean expression cannot be used here
10 | {**x in y}
11 | {**x not in y}
|
|
8 | {**x and y, b: 2}
9 | {a: 1, **not x, b: 2}
10 | {**x in y}
| ^^^^^^ Syntax Error: Comparison expression cannot be used here
11 | {**x not in y}
12 | {**x < y}
|
|
9 | {a: 1, **not x, b: 2}
10 | {**x in y}
11 | {**x not in y}
| ^^^^^^^^^^ Syntax Error: Comparison expression cannot be used here
12 | {**x < y}
|
|
10 | {**x in y}
11 | {**x not in y}
12 | {**x < y}
| ^^^^^ Syntax Error: Comparison expression cannot be used here
|

View file

@ -0,0 +1,152 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/dict/double_star_comprehension.py
---
## AST
```
Module(
ModModule {
range: 0..358,
body: [
Expr(
StmtExpr {
range: 122..147,
value: Dict(
ExprDict {
range: 122..147,
keys: [
None,
Some(
Name(
ExprName {
range: 128..129,
id: "y",
ctx: Load,
},
),
),
Some(
Name(
ExprName {
range: 134..135,
id: "x",
ctx: Load,
},
),
),
Some(
Compare(
ExprCompare {
range: 137..146,
left: Name(
ExprName {
range: 137..138,
id: "y",
ctx: Load,
},
),
ops: [
In,
],
comparators: [
Name(
ExprName {
range: 142..146,
id: "data",
ctx: Load,
},
),
],
},
),
),
],
values: [
Name(
ExprName {
range: 125..126,
id: "x",
ctx: Load,
},
),
Name(
ExprName {
range: 130..133,
id: "for",
ctx: Load,
},
),
Name(
ExprName {
range: 135..135,
id: "",
ctx: Invalid,
},
),
Name(
ExprName {
range: 146..146,
id: "",
ctx: Invalid,
},
),
],
},
),
},
),
],
},
)
```
## Errors
|
2 | # it's actually a comprehension.
3 |
4 | {**x: y for x, y in data}
| ^ Syntax Error: Expected an expression or a '}'
5 |
6 | # TODO(dhruvmanila): This test case fails because there's no way to represent `**y`
|
|
2 | # it's actually a comprehension.
3 |
4 | {**x: y for x, y in data}
| ^^^ Syntax Error: Expected ':', found 'for'
5 |
6 | # TODO(dhruvmanila): This test case fails because there's no way to represent `**y`
|
|
2 | # it's actually a comprehension.
3 |
4 | {**x: y for x, y in data}
| ^ Syntax Error: Expected ',', found name
5 |
6 | # TODO(dhruvmanila): This test case fails because there's no way to represent `**y`
|
|
2 | # it's actually a comprehension.
3 |
4 | {**x: y for x, y in data}
| ^ Syntax Error: Expected ':', found ','
5 |
6 | # TODO(dhruvmanila): This test case fails because there's no way to represent `**y`
|
|
2 | # it's actually a comprehension.
3 |
4 | {**x: y for x, y in data}
| ^ Syntax Error: Expected ':', found '}'
5 |
6 | # TODO(dhruvmanila): This test case fails because there's no way to represent `**y`
|

View file

@ -0,0 +1,103 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/dict/missing_closing_brace_0.py
---
## AST
```
Module(
ModModule {
range: 0..24,
body: [
Expr(
StmtExpr {
range: 0..24,
value: Dict(
ExprDict {
range: 0..24,
keys: [
Some(
Name(
ExprName {
range: 1..2,
id: "x",
ctx: Load,
},
),
),
Some(
Call(
ExprCall {
range: 9..14,
func: Name(
ExprName {
range: 9..12,
id: "foo",
ctx: Load,
},
),
arguments: Arguments {
range: 12..14,
args: [],
keywords: [],
},
},
),
),
],
values: [
Name(
ExprName {
range: 5..8,
id: "def",
ctx: Load,
},
),
Name(
ExprName {
range: 20..24,
id: "pass",
ctx: Load,
},
),
],
},
),
},
),
],
},
)
```
## Errors
|
1 | {x:
2 |
3 | def foo():
| ^^^ Syntax Error: Expected an identifier, but found a keyword 'def' that cannot be used here
4 | pass
|
|
1 | {x:
2 |
3 | def foo():
| ^^^ Syntax Error: Expected ',', found name
4 | pass
|
|
3 | def foo():
4 | pass
| ^^^^ Syntax Error: Expected an identifier, but found a keyword 'pass' that cannot be used here
|
|
3 | def foo():
4 | pass
| Syntax Error: unexpected EOF while parsing
|

View file

@ -0,0 +1,68 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/dict/missing_closing_brace_1.py
---
## AST
```
Module(
ModModule {
range: 0..10,
body: [
Expr(
StmtExpr {
range: 0..10,
value: Dict(
ExprDict {
range: 0..10,
keys: [
Some(
Name(
ExprName {
range: 1..2,
id: "x",
ctx: Load,
},
),
),
],
values: [
BinOp(
ExprBinOp {
range: 5..10,
left: NumberLiteral(
ExprNumberLiteral {
range: 5..6,
value: Int(
1,
),
},
),
op: Add,
right: NumberLiteral(
ExprNumberLiteral {
range: 9..10,
value: Int(
2,
),
},
),
},
),
],
},
),
},
),
],
},
)
```
## Errors
|
1 | {x:
2 |
3 | 1 + 2
| Syntax Error: unexpected EOF while parsing
|

View file

@ -0,0 +1,90 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/dict/missing_closing_brace_2.py
---
## AST
```
Module(
ModModule {
range: 0..27,
body: [
Expr(
StmtExpr {
range: 0..6,
value: Dict(
ExprDict {
range: 0..6,
keys: [
Some(
Name(
ExprName {
range: 1..2,
id: "x",
ctx: Load,
},
),
),
],
values: [
NumberLiteral(
ExprNumberLiteral {
range: 4..5,
value: Int(
1,
),
},
),
],
},
),
},
),
FunctionDef(
StmtFunctionDef {
range: 8..27,
is_async: false,
decorator_list: [],
name: Identifier {
id: "foo",
range: 12..15,
},
type_params: None,
parameters: Parameters {
range: 15..17,
posonlyargs: [],
args: [],
vararg: None,
kwonlyargs: [],
kwarg: None,
},
returns: None,
body: [
Pass(
StmtPass {
range: 23..27,
},
),
],
},
),
],
},
)
```
## Errors
|
1 | {x: 1,
2 |
3 | def foo():
| ^^^ Syntax Error: Expected an expression or a '}'
4 | pass
|
|
3 | def foo():
4 | pass
| Syntax Error: unexpected EOF while parsing
|

View file

@ -0,0 +1,136 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/dict/named_expression_0.py
---
## AST
```
Module(
ModModule {
range: 0..84,
body: [
Expr(
StmtExpr {
range: 55..77,
value: Dict(
ExprDict {
range: 55..77,
keys: [
Some(
Named(
ExprNamed {
range: 56..62,
target: Name(
ExprName {
range: 56..57,
id: "x",
ctx: Store,
},
),
value: NumberLiteral(
ExprNumberLiteral {
range: 61..62,
value: Int(
1,
),
},
),
},
),
),
Some(
Name(
ExprName {
range: 67..68,
id: "z",
ctx: Load,
},
),
),
Some(
NumberLiteral(
ExprNumberLiteral {
range: 72..73,
value: Int(
2,
),
},
),
),
],
values: [
Name(
ExprName {
range: 64..65,
id: "y",
ctx: Load,
},
),
Name(
ExprName {
range: 68..68,
id: "",
ctx: Invalid,
},
),
Name(
ExprName {
range: 75..76,
id: "a",
ctx: Load,
},
),
],
},
),
},
),
Expr(
StmtExpr {
range: 79..84,
value: BinOp(
ExprBinOp {
range: 79..84,
left: Name(
ExprName {
range: 79..80,
id: "x",
ctx: Load,
},
),
op: Add,
right: Name(
ExprName {
range: 83..84,
id: "y",
ctx: Load,
},
),
},
),
},
),
],
},
)
```
## Errors
|
1 | # Unparenthesized named expression not allowed in key
2 |
3 | {x := 1: y, z := 2: a}
| ^^^^^^ Syntax Error: Unparenthesized named expression cannot be used here
4 |
5 | x + y
|
|
1 | # Unparenthesized named expression not allowed in key
2 |
3 | {x := 1: y, z := 2: a}
| ^^ Syntax Error: Expected ':', found ':='
4 |
5 | x + y
|

View file

@ -0,0 +1,160 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/dict/named_expression_1.py
---
## AST
```
Module(
ModModule {
range: 0..86,
body: [
Expr(
StmtExpr {
range: 57..79,
value: Dict(
ExprDict {
range: 57..79,
keys: [
Some(
Name(
ExprName {
range: 58..59,
id: "x",
ctx: Load,
},
),
),
Some(
NumberLiteral(
ExprNumberLiteral {
range: 66..67,
value: Int(
1,
),
},
),
),
Some(
Name(
ExprName {
range: 69..70,
id: "z",
ctx: Load,
},
),
),
Some(
NumberLiteral(
ExprNumberLiteral {
range: 77..78,
value: Int(
2,
),
},
),
),
],
values: [
Name(
ExprName {
range: 61..62,
id: "y",
ctx: Load,
},
),
Name(
ExprName {
range: 67..67,
id: "",
ctx: Invalid,
},
),
Name(
ExprName {
range: 72..73,
id: "a",
ctx: Load,
},
),
Name(
ExprName {
range: 78..78,
id: "",
ctx: Invalid,
},
),
],
},
),
},
),
Expr(
StmtExpr {
range: 81..86,
value: BinOp(
ExprBinOp {
range: 81..86,
left: Name(
ExprName {
range: 81..82,
id: "x",
ctx: Load,
},
),
op: Add,
right: Name(
ExprName {
range: 85..86,
id: "y",
ctx: Load,
},
),
},
),
},
),
],
},
)
```
## Errors
|
1 | # Unparenthesized named expression not allowed in value
2 |
3 | {x: y := 1, z: a := 2}
| ^^ Syntax Error: Expected ',', found ':='
4 |
5 | x + y
|
|
1 | # Unparenthesized named expression not allowed in value
2 |
3 | {x: y := 1, z: a := 2}
| ^ Syntax Error: Expected ':', found ','
4 |
5 | x + y
|
|
1 | # Unparenthesized named expression not allowed in value
2 |
3 | {x: y := 1, z: a := 2}
| ^^ Syntax Error: Expected ',', found ':='
4 |
5 | x + y
|
|
1 | # Unparenthesized named expression not allowed in value
2 |
3 | {x: y := 1, z: a := 2}
| ^ Syntax Error: Expected ':', found '}'
4 |
5 | x + y
|

View file

@ -0,0 +1,503 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/dict/recover.py
---
## AST
```
Module(
ModModule {
range: 0..346,
body: [
Expr(
StmtExpr {
range: 88..91,
value: Set(
ExprSet {
range: 88..91,
elts: [
Name(
ExprName {
range: 89..89,
id: "",
ctx: Invalid,
},
),
],
},
),
},
),
Expr(
StmtExpr {
range: 93..105,
value: Dict(
ExprDict {
range: 93..105,
keys: [
Some(
NumberLiteral(
ExprNumberLiteral {
range: 94..95,
value: Int(
1,
),
},
),
),
Some(
NumberLiteral(
ExprNumberLiteral {
range: 100..101,
value: Int(
3,
),
},
),
),
],
values: [
NumberLiteral(
ExprNumberLiteral {
range: 97..98,
value: Int(
2,
),
},
),
NumberLiteral(
ExprNumberLiteral {
range: 103..104,
value: Int(
4,
),
},
),
],
},
),
},
),
Expr(
StmtExpr {
range: 107..115,
value: Dict(
ExprDict {
range: 107..115,
keys: [
Some(
NumberLiteral(
ExprNumberLiteral {
range: 108..109,
value: Int(
1,
),
},
),
),
],
values: [
NumberLiteral(
ExprNumberLiteral {
range: 111..112,
value: Int(
2,
),
},
),
],
},
),
},
),
Expr(
StmtExpr {
range: 133..144,
value: Dict(
ExprDict {
range: 133..144,
keys: [
Some(
NumberLiteral(
ExprNumberLiteral {
range: 134..135,
value: Int(
1,
),
},
),
),
Some(
NumberLiteral(
ExprNumberLiteral {
range: 139..140,
value: Int(
3,
),
},
),
),
],
values: [
NumberLiteral(
ExprNumberLiteral {
range: 137..138,
value: Int(
2,
),
},
),
NumberLiteral(
ExprNumberLiteral {
range: 142..143,
value: Int(
4,
),
},
),
],
},
),
},
),
Expr(
StmtExpr {
range: 157..162,
value: Dict(
ExprDict {
range: 157..162,
keys: [
Some(
NumberLiteral(
ExprNumberLiteral {
range: 158..159,
value: Int(
1,
),
},
),
),
],
values: [
Name(
ExprName {
range: 160..160,
id: "",
ctx: Invalid,
},
),
],
},
),
},
),
Expr(
StmtExpr {
range: 201..205,
value: Dict(
ExprDict {
range: 201..205,
keys: [
None,
],
values: [
Name(
ExprName {
range: 204..204,
id: "",
ctx: Invalid,
},
),
],
},
),
},
),
Expr(
StmtExpr {
range: 206..222,
value: Dict(
ExprDict {
range: 206..222,
keys: [
Some(
Name(
ExprName {
range: 207..208,
id: "x",
ctx: Load,
},
),
),
None,
Some(
Name(
ExprName {
range: 217..218,
id: "a",
ctx: Load,
},
),
),
],
values: [
Name(
ExprName {
range: 210..211,
id: "y",
ctx: Load,
},
),
Name(
ExprName {
range: 215..215,
id: "",
ctx: Invalid,
},
),
Name(
ExprName {
range: 220..221,
id: "b",
ctx: Load,
},
),
],
},
),
},
),
Expr(
StmtExpr {
range: 310..330,
value: Dict(
ExprDict {
range: 310..330,
keys: [
Some(
Starred(
ExprStarred {
range: 311..313,
value: Name(
ExprName {
range: 312..313,
id: "x",
ctx: Load,
},
),
ctx: Load,
},
),
),
Some(
Name(
ExprName {
range: 318..319,
id: "z",
ctx: Load,
},
),
),
Some(
Starred(
ExprStarred {
range: 324..326,
value: Name(
ExprName {
range: 325..326,
id: "b",
ctx: Load,
},
),
ctx: Load,
},
),
),
],
values: [
Name(
ExprName {
range: 315..316,
id: "y",
ctx: Load,
},
),
Name(
ExprName {
range: 321..322,
id: "a",
ctx: Load,
},
),
Name(
ExprName {
range: 328..329,
id: "c",
ctx: Load,
},
),
],
},
),
},
),
Expr(
StmtExpr {
range: 331..345,
value: Dict(
ExprDict {
range: 331..345,
keys: [
Some(
Name(
ExprName {
range: 332..333,
id: "x",
ctx: Load,
},
),
),
Some(
Name(
ExprName {
range: 339..340,
id: "z",
ctx: Load,
},
),
),
],
values: [
Starred(
ExprStarred {
range: 335..337,
value: Name(
ExprName {
range: 336..337,
id: "y",
ctx: Load,
},
),
ctx: Load,
},
),
Starred(
ExprStarred {
range: 342..344,
value: Name(
ExprName {
range: 343..344,
id: "a",
ctx: Load,
},
),
ctx: Load,
},
),
],
},
),
},
),
],
},
)
```
## Errors
|
1 | # Test cases for dictionary expressions where the parser recovers from a syntax error.
2 |
3 | {,}
| ^ Syntax Error: Expected an expression
4 |
5 | {1: 2,,3: 4}
|
|
3 | {,}
4 |
5 | {1: 2,,3: 4}
| ^ Syntax Error: Expected an expression or a '}'
6 |
7 | {1: 2,,}
|
|
5 | {1: 2,,3: 4}
6 |
7 | {1: 2,,}
| ^ Syntax Error: Expected an expression or a '}'
8 |
9 | # Missing comma
|
|
9 | # Missing comma
10 | {1: 2 3: 4}
| ^ Syntax Error: Expected ',', found int
11 |
12 | # No value
|
|
12 | # No value
13 | {1: }
| ^ Syntax Error: Expected an expression
14 |
15 | # No value for double star unpacking
|
|
15 | # No value for double star unpacking
16 | {**}
| ^ Syntax Error: Expected an expression
17 | {x: y, **, a: b}
|
|
15 | # No value for double star unpacking
16 | {**}
17 | {x: y, **, a: b}
| ^ Syntax Error: Expected an expression
18 |
19 | # This is not a double star unpacking
|
|
22 | # Star expression not allowed here
23 | {*x: y, z: a, *b: c}
| ^^ Syntax Error: Starred expression cannot be used here
24 | {x: *y, z: *a}
|
|
22 | # Star expression not allowed here
23 | {*x: y, z: a, *b: c}
| ^^ Syntax Error: Starred expression cannot be used here
24 | {x: *y, z: *a}
|
|
22 | # Star expression not allowed here
23 | {*x: y, z: a, *b: c}
24 | {x: *y, z: *a}
| ^^ Syntax Error: Starred expression cannot be used here
|
|
22 | # Star expression not allowed here
23 | {*x: y, z: a, *b: c}
24 | {x: *y, z: *a}
| ^^ Syntax Error: Starred expression cannot be used here
|

View file

@ -0,0 +1,138 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/emoji_identifiers.py
---
## AST
```
Module(
ModModule {
range: 0..64,
body: [
Assign(
StmtAssign {
range: 0..5,
targets: [
Name(
ExprName {
range: 0..1,
id: "a",
ctx: Store,
},
),
],
value: Name(
ExprName {
range: 5..5,
id: "",
ctx: Invalid,
},
),
},
),
Assign(
StmtAssign {
range: 32..37,
targets: [
Name(
ExprName {
range: 32..33,
id: "a",
ctx: Store,
},
),
],
value: Name(
ExprName {
range: 37..37,
id: "",
ctx: Invalid,
},
),
},
),
Expr(
StmtExpr {
range: 42..43,
value: UnaryOp(
ExprUnaryOp {
range: 42..43,
op: UAdd,
operand: Name(
ExprName {
range: 43..43,
id: "",
ctx: Invalid,
},
),
},
),
},
),
],
},
)
```
## Errors
|
1 | a = (🐶
| ^^ Syntax Error: Got unexpected token 🐶
2 | # comment 🐶
3 | )
|
|
1 | a = (🐶
2 | # comment 🐶
3 | )
| ^ Syntax Error: Expected a statement
4 |
5 | a = (🐶 +
|
|
1 | a = (🐶
2 | # comment 🐶
3 | )
| ^ Syntax Error: Expected a statement
4 |
5 | a = (🐶 +
6 | # comment
|
|
3 | )
4 |
5 | a = (🐶 +
| ^^ Syntax Error: Got unexpected token 🐶
6 | # comment
7 | 🐶)
|
|
5 | a = (🐶 +
6 | # comment
7 | 🐶)
| ^^ Syntax Error: Got unexpected token 🐶
|
|
5 | a = (🐶 +
6 | # comment
7 | 🐶)
| ^ Syntax Error: Expected a statement
|
|
5 | a = (🐶 +
6 | # comment
7 | 🐶)
| ^ Syntax Error: Expected a statement
|

View file

@ -0,0 +1,20 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/emoji_statement.py
---
## AST
```
Module(
ModModule {
range: 0..5,
body: [],
},
)
```
## Errors
|
1 | 👍
| ^^ Syntax Error: Got unexpected token 👍
|

View file

@ -0,0 +1,84 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/if/missing_orelse_expr_0.py
---
## AST
```
Module(
ModModule {
range: 0..88,
body: [
Expr(
StmtExpr {
range: 53..67,
value: If(
ExprIf {
range: 53..67,
test: Name(
ExprName {
range: 58..62,
id: "expr",
ctx: Load,
},
),
body: Name(
ExprName {
range: 53..54,
id: "x",
ctx: Load,
},
),
orelse: Name(
ExprName {
range: 67..67,
id: "",
ctx: Invalid,
},
),
},
),
},
),
FunctionDef(
StmtFunctionDef {
range: 69..88,
is_async: false,
decorator_list: [],
name: Identifier {
id: "foo",
range: 73..76,
},
type_params: None,
parameters: Parameters {
range: 76..78,
posonlyargs: [],
args: [],
vararg: None,
kwonlyargs: [],
kwarg: None,
},
returns: None,
body: [
Pass(
StmtPass {
range: 84..88,
},
),
],
},
),
],
},
)
```
## Errors
|
1 | # Missing orelse expression, followed by a statement
2 | x if expr else
| ^ Syntax Error: Expected an expression
3 |
4 | def foo():
5 | pass
|

View file

@ -0,0 +1,82 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/if/missing_orelse_expr_1.py
---
## AST
```
Module(
ModModule {
range: 0..76,
body: [
Expr(
StmtExpr {
range: 55..69,
value: If(
ExprIf {
range: 55..69,
test: Name(
ExprName {
range: 60..64,
id: "expr",
ctx: Load,
},
),
body: Name(
ExprName {
range: 55..56,
id: "x",
ctx: Load,
},
),
orelse: Name(
ExprName {
range: 69..69,
id: "",
ctx: Invalid,
},
),
},
),
},
),
Expr(
StmtExpr {
range: 71..76,
value: BinOp(
ExprBinOp {
range: 71..76,
left: NumberLiteral(
ExprNumberLiteral {
range: 71..72,
value: Int(
1,
),
},
),
op: Add,
right: NumberLiteral(
ExprNumberLiteral {
range: 75..76,
value: Int(
1,
),
},
),
},
),
},
),
],
},
)
```
## Errors
|
1 | # Missing orelse expression, followed by an expression
2 | x if expr else
| ^ Syntax Error: Expected an expression
3 |
4 | 1 + 1
|

View file

@ -0,0 +1,84 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/if/missing_test_expr_0.py
---
## AST
```
Module(
ModModule {
range: 0..76,
body: [
Expr(
StmtExpr {
range: 51..55,
value: If(
ExprIf {
range: 51..55,
test: Name(
ExprName {
range: 55..55,
id: "",
ctx: Invalid,
},
),
body: Name(
ExprName {
range: 51..52,
id: "x",
ctx: Load,
},
),
orelse: Name(
ExprName {
range: 55..55,
id: "",
ctx: Invalid,
},
),
},
),
},
),
FunctionDef(
StmtFunctionDef {
range: 57..76,
is_async: false,
decorator_list: [],
name: Identifier {
id: "foo",
range: 61..64,
},
type_params: None,
parameters: Parameters {
range: 64..66,
posonlyargs: [],
args: [],
vararg: None,
kwonlyargs: [],
kwarg: None,
},
returns: None,
body: [
Pass(
StmtPass {
range: 72..76,
},
),
],
},
),
],
},
)
```
## Errors
|
1 | # Missing test expression, followed by a statement
2 | x if
| ^ Syntax Error: Expected an expression
3 |
4 | def foo():
5 | pass
|

View file

@ -0,0 +1,82 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/if/missing_test_expr_1.py
---
## AST
```
Module(
ModModule {
range: 0..64,
body: [
Expr(
StmtExpr {
range: 53..57,
value: If(
ExprIf {
range: 53..57,
test: Name(
ExprName {
range: 57..57,
id: "",
ctx: Invalid,
},
),
body: Name(
ExprName {
range: 53..54,
id: "x",
ctx: Load,
},
),
orelse: Name(
ExprName {
range: 57..57,
id: "",
ctx: Invalid,
},
),
},
),
},
),
Expr(
StmtExpr {
range: 59..64,
value: BinOp(
ExprBinOp {
range: 59..64,
left: NumberLiteral(
ExprNumberLiteral {
range: 59..60,
value: Int(
1,
),
},
),
op: Add,
right: NumberLiteral(
ExprNumberLiteral {
range: 63..64,
value: Int(
1,
),
},
),
},
),
},
),
],
},
)
```
## Errors
|
1 | # Missing test expression, followed by an expression
2 | x if
| ^ Syntax Error: Expected an expression
3 |
4 | 1 + 1
|

View file

@ -0,0 +1,360 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/if/recover.py
---
## AST
```
Module(
ModModule {
range: 0..215,
body: [
Expr(
StmtExpr {
range: 26..43,
value: If(
ExprIf {
range: 26..43,
test: Starred(
ExprStarred {
range: 31..36,
value: Name(
ExprName {
range: 32..36,
id: "expr",
ctx: Load,
},
),
ctx: Load,
},
),
body: Name(
ExprName {
range: 26..27,
id: "x",
ctx: Load,
},
),
orelse: Name(
ExprName {
range: 42..43,
id: "y",
ctx: Load,
},
),
},
),
},
),
Expr(
StmtExpr {
range: 44..67,
value: If(
ExprIf {
range: 44..67,
test: Lambda(
ExprLambda {
range: 49..60,
parameters: Some(
Parameters {
range: 56..57,
posonlyargs: [],
args: [
ParameterWithDefault {
range: 56..57,
parameter: Parameter {
range: 56..57,
name: Identifier {
id: "x",
range: 56..57,
},
annotation: None,
},
default: None,
},
],
vararg: None,
kwonlyargs: [],
kwarg: None,
},
),
body: Name(
ExprName {
range: 59..60,
id: "x",
ctx: Load,
},
),
},
),
body: Name(
ExprName {
range: 44..45,
id: "x",
ctx: Load,
},
),
orelse: Name(
ExprName {
range: 66..67,
id: "y",
ctx: Load,
},
),
},
),
},
),
Expr(
StmtExpr {
range: 68..87,
value: If(
ExprIf {
range: 68..87,
test: Yield(
ExprYield {
range: 73..80,
value: Some(
Name(
ExprName {
range: 79..80,
id: "x",
ctx: Load,
},
),
),
},
),
body: Name(
ExprName {
range: 68..69,
id: "x",
ctx: Load,
},
),
orelse: Name(
ExprName {
range: 86..87,
id: "y",
ctx: Load,
},
),
},
),
},
),
Expr(
StmtExpr {
range: 88..112,
value: If(
ExprIf {
range: 88..112,
test: YieldFrom(
ExprYieldFrom {
range: 93..105,
value: Name(
ExprName {
range: 104..105,
id: "x",
ctx: Load,
},
),
},
),
body: Name(
ExprName {
range: 88..89,
id: "x",
ctx: Load,
},
),
orelse: Name(
ExprName {
range: 111..112,
id: "y",
ctx: Load,
},
),
},
),
},
),
Expr(
StmtExpr {
range: 142..164,
value: If(
ExprIf {
range: 142..164,
test: Name(
ExprName {
range: 147..151,
id: "expr",
ctx: Load,
},
),
body: Name(
ExprName {
range: 142..143,
id: "x",
ctx: Load,
},
),
orelse: Starred(
ExprStarred {
range: 157..164,
value: Name(
ExprName {
range: 158..164,
id: "orelse",
ctx: Load,
},
),
ctx: Load,
},
),
},
),
},
),
Expr(
StmtExpr {
range: 165..187,
value: If(
ExprIf {
range: 165..187,
test: Name(
ExprName {
range: 170..174,
id: "expr",
ctx: Load,
},
),
body: Name(
ExprName {
range: 165..166,
id: "x",
ctx: Load,
},
),
orelse: Yield(
ExprYield {
range: 180..187,
value: Some(
Name(
ExprName {
range: 186..187,
id: "y",
ctx: Load,
},
),
),
},
),
},
),
},
),
Expr(
StmtExpr {
range: 188..215,
value: If(
ExprIf {
range: 188..215,
test: Name(
ExprName {
range: 193..197,
id: "expr",
ctx: Load,
},
),
body: Name(
ExprName {
range: 188..189,
id: "x",
ctx: Load,
},
),
orelse: YieldFrom(
ExprYieldFrom {
range: 203..215,
value: Name(
ExprName {
range: 214..215,
id: "y",
ctx: Load,
},
),
},
),
},
),
},
),
],
},
)
```
## Errors
|
1 | # Invalid test expression
2 | x if *expr else y
| ^^^^^ Syntax Error: Starred expression cannot be used here
3 | x if lambda x: x else y
4 | x if yield x else y
|
|
1 | # Invalid test expression
2 | x if *expr else y
3 | x if lambda x: x else y
| ^^^^^^^^^^^ Syntax Error: Lambda expression cannot be used here
4 | x if yield x else y
5 | x if yield from x else y
|
|
2 | x if *expr else y
3 | x if lambda x: x else y
4 | x if yield x else y
| ^^^^^^^ Syntax Error: Yield expression cannot be used here
5 | x if yield from x else y
|
|
3 | x if lambda x: x else y
4 | x if yield x else y
5 | x if yield from x else y
| ^^^^^^^^^^^^ Syntax Error: Yield expression cannot be used here
6 |
7 | # Invalid orelse expression
|
|
7 | # Invalid orelse expression
8 | x if expr else *orelse
| ^^^^^^^ Syntax Error: Starred expression cannot be used here
9 | x if expr else yield y
10 | x if expr else yield from y
|
|
7 | # Invalid orelse expression
8 | x if expr else *orelse
9 | x if expr else yield y
| ^^^^^^^ Syntax Error: Yield expression cannot be used here
10 | x if expr else yield from y
|
|
8 | x if expr else *orelse
9 | x if expr else yield y
10 | x if expr else yield from y
| ^^^^^^^^^^^^ Syntax Error: Yield expression cannot be used here
|

View file

@ -0,0 +1,95 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/lambda_default_parameters.py
---
## AST
```
Module(
ModModule {
range: 0..20,
body: [
Expr(
StmtExpr {
range: 0..20,
value: Lambda(
ExprLambda {
range: 0..20,
parameters: Some(
Parameters {
range: 7..17,
posonlyargs: [],
args: [
ParameterWithDefault {
range: 7..8,
parameter: Parameter {
range: 7..8,
name: Identifier {
id: "a",
range: 7..8,
},
annotation: None,
},
default: None,
},
ParameterWithDefault {
range: 10..14,
parameter: Parameter {
range: 10..11,
name: Identifier {
id: "b",
range: 10..11,
},
annotation: None,
},
default: Some(
NumberLiteral(
ExprNumberLiteral {
range: 12..14,
value: Int(
20,
),
},
),
),
},
ParameterWithDefault {
range: 16..17,
parameter: Parameter {
range: 16..17,
name: Identifier {
id: "c",
range: 16..17,
},
annotation: None,
},
default: None,
},
],
vararg: None,
kwonlyargs: [],
kwarg: None,
},
),
body: NumberLiteral(
ExprNumberLiteral {
range: 19..20,
value: Int(
1,
),
},
),
},
),
},
),
],
},
)
```
## Errors
|
1 | lambda a, b=20, c: 1
| ^ Syntax Error: Parameter without a default cannot follow a parameter with a default
|

View file

@ -0,0 +1,338 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/lambda_duplicate_parameters.py
---
## AST
```
Module(
ModModule {
range: 0..91,
body: [
Expr(
StmtExpr {
range: 0..14,
value: Lambda(
ExprLambda {
range: 0..14,
parameters: Some(
Parameters {
range: 7..11,
posonlyargs: [],
args: [
ParameterWithDefault {
range: 7..8,
parameter: Parameter {
range: 7..8,
name: Identifier {
id: "a",
range: 7..8,
},
annotation: None,
},
default: None,
},
ParameterWithDefault {
range: 10..11,
parameter: Parameter {
range: 10..11,
name: Identifier {
id: "a",
range: 10..11,
},
annotation: None,
},
default: None,
},
],
vararg: None,
kwonlyargs: [],
kwarg: None,
},
),
body: NumberLiteral(
ExprNumberLiteral {
range: 13..14,
value: Int(
1,
),
},
),
},
),
},
),
Expr(
StmtExpr {
range: 16..33,
value: Lambda(
ExprLambda {
range: 16..33,
parameters: Some(
Parameters {
range: 23..30,
posonlyargs: [],
args: [
ParameterWithDefault {
range: 23..24,
parameter: Parameter {
range: 23..24,
name: Identifier {
id: "a",
range: 23..24,
},
annotation: None,
},
default: None,
},
],
vararg: None,
kwonlyargs: [
ParameterWithDefault {
range: 29..30,
parameter: Parameter {
range: 29..30,
name: Identifier {
id: "a",
range: 29..30,
},
annotation: None,
},
default: None,
},
],
kwarg: None,
},
),
body: NumberLiteral(
ExprNumberLiteral {
range: 32..33,
value: Int(
1,
),
},
),
},
),
},
),
Expr(
StmtExpr {
range: 35..52,
value: Lambda(
ExprLambda {
range: 35..52,
parameters: Some(
Parameters {
range: 42..49,
posonlyargs: [],
args: [
ParameterWithDefault {
range: 42..43,
parameter: Parameter {
range: 42..43,
name: Identifier {
id: "a",
range: 42..43,
},
annotation: None,
},
default: None,
},
ParameterWithDefault {
range: 45..49,
parameter: Parameter {
range: 45..46,
name: Identifier {
id: "a",
range: 45..46,
},
annotation: None,
},
default: Some(
NumberLiteral(
ExprNumberLiteral {
range: 47..49,
value: Int(
20,
),
},
),
),
},
],
vararg: None,
kwonlyargs: [],
kwarg: None,
},
),
body: NumberLiteral(
ExprNumberLiteral {
range: 51..52,
value: Int(
1,
),
},
),
},
),
},
),
Expr(
StmtExpr {
range: 54..69,
value: Lambda(
ExprLambda {
range: 54..69,
parameters: Some(
Parameters {
range: 61..66,
posonlyargs: [],
args: [
ParameterWithDefault {
range: 61..62,
parameter: Parameter {
range: 61..62,
name: Identifier {
id: "a",
range: 61..62,
},
annotation: None,
},
default: None,
},
],
vararg: Some(
Parameter {
range: 64..66,
name: Identifier {
id: "a",
range: 65..66,
},
annotation: None,
},
),
kwonlyargs: [],
kwarg: None,
},
),
body: NumberLiteral(
ExprNumberLiteral {
range: 68..69,
value: Int(
1,
),
},
),
},
),
},
),
Expr(
StmtExpr {
range: 71..90,
value: Lambda(
ExprLambda {
range: 71..90,
parameters: Some(
Parameters {
range: 78..87,
posonlyargs: [],
args: [
ParameterWithDefault {
range: 78..79,
parameter: Parameter {
range: 78..79,
name: Identifier {
id: "a",
range: 78..79,
},
annotation: None,
},
default: None,
},
],
vararg: None,
kwonlyargs: [],
kwarg: Some(
Parameter {
range: 84..87,
name: Identifier {
id: "a",
range: 86..87,
},
annotation: None,
},
),
},
),
body: NumberLiteral(
ExprNumberLiteral {
range: 89..90,
value: Int(
1,
),
},
),
},
),
},
),
],
},
)
```
## Errors
|
1 | lambda a, a: 1
| ^ Syntax Error: Duplicate parameter "a"
2 |
3 | lambda a, *, a: 1
|
|
1 | lambda a, a: 1
2 |
3 | lambda a, *, a: 1
| ^ Syntax Error: Duplicate parameter "a"
4 |
5 | lambda a, a=20: 1
|
|
3 | lambda a, *, a: 1
4 |
5 | lambda a, a=20: 1
| ^ Syntax Error: Duplicate parameter "a"
6 |
7 | lambda a, *a: 1
|
|
5 | lambda a, a=20: 1
6 |
7 | lambda a, *a: 1
| ^ Syntax Error: Duplicate parameter "a"
8 |
9 | lambda a, *, **a: 1
|
|
7 | lambda a, *a: 1
8 |
9 | lambda a, *, **a: 1
| ^^^ Syntax Error: Expected one or more keyword parameter after '*' separator
|
|
7 | lambda a, *a: 1
8 |
9 | lambda a, *, **a: 1
| ^ Syntax Error: Duplicate parameter "a"
|

View file

@ -0,0 +1,796 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/list/comprehension.py
---
## AST
```
Module(
ModModule {
range: 0..376,
body: [
Expr(
StmtExpr {
range: 33..48,
value: ListComp(
ExprListComp {
range: 33..48,
elt: Starred(
ExprStarred {
range: 34..36,
value: Name(
ExprName {
range: 35..36,
id: "x",
ctx: Load,
},
),
ctx: Load,
},
),
generators: [
Comprehension {
range: 37..47,
target: Name(
ExprName {
range: 41..42,
id: "x",
ctx: Store,
},
),
iter: Name(
ExprName {
range: 46..47,
id: "y",
ctx: Load,
},
),
ifs: [],
is_async: false,
},
],
},
),
},
),
Expr(
StmtExpr {
range: 67..81,
value: ListComp(
ExprListComp {
range: 67..81,
elt: Name(
ExprName {
range: 68..69,
id: "x",
ctx: Load,
},
),
generators: [
Comprehension {
range: 70..80,
target: NumberLiteral(
ExprNumberLiteral {
range: 74..75,
value: Int(
1,
),
},
),
iter: Name(
ExprName {
range: 79..80,
id: "y",
ctx: Load,
},
),
ifs: [],
is_async: false,
},
],
},
),
},
),
Expr(
StmtExpr {
range: 82..98,
value: ListComp(
ExprListComp {
range: 82..98,
elt: Name(
ExprName {
range: 83..84,
id: "x",
ctx: Load,
},
),
generators: [
Comprehension {
range: 85..97,
target: StringLiteral(
ExprStringLiteral {
range: 89..92,
value: StringLiteralValue {
inner: Single(
StringLiteral {
range: 89..92,
value: "a",
flags: StringLiteralFlags {
quote_style: Single,
prefix: Empty,
triple_quoted: false,
},
},
),
},
},
),
iter: Name(
ExprName {
range: 96..97,
id: "y",
ctx: Load,
},
),
ifs: [],
is_async: false,
},
],
},
),
},
),
Expr(
StmtExpr {
range: 99..118,
value: ListComp(
ExprListComp {
range: 99..118,
elt: Name(
ExprName {
range: 100..101,
id: "x",
ctx: Load,
},
),
generators: [
Comprehension {
range: 102..117,
target: Call(
ExprCall {
range: 106..112,
func: Name(
ExprName {
range: 106..110,
id: "call",
ctx: Load,
},
),
arguments: Arguments {
range: 110..112,
args: [],
keywords: [],
},
},
),
iter: Name(
ExprName {
range: 116..117,
id: "y",
ctx: Load,
},
),
ifs: [],
is_async: false,
},
],
},
),
},
),
Expr(
StmtExpr {
range: 119..138,
value: ListComp(
ExprListComp {
range: 119..138,
elt: Name(
ExprName {
range: 120..121,
id: "x",
ctx: Load,
},
),
generators: [
Comprehension {
range: 122..137,
target: Set(
ExprSet {
range: 126..132,
elts: [
Name(
ExprName {
range: 127..128,
id: "a",
ctx: Load,
},
),
Name(
ExprName {
range: 130..131,
id: "b",
ctx: Load,
},
),
],
},
),
iter: Name(
ExprName {
range: 136..137,
id: "y",
ctx: Load,
},
),
ifs: [],
is_async: false,
},
],
},
),
},
),
Expr(
StmtExpr {
range: 155..170,
value: ListComp(
ExprListComp {
range: 155..170,
elt: Name(
ExprName {
range: 156..157,
id: "x",
ctx: Load,
},
),
generators: [
Comprehension {
range: 158..169,
target: Name(
ExprName {
range: 162..163,
id: "x",
ctx: Store,
},
),
iter: Starred(
ExprStarred {
range: 167..169,
value: Name(
ExprName {
range: 168..169,
id: "y",
ctx: Load,
},
),
ctx: Load,
},
),
ifs: [],
is_async: false,
},
],
},
),
},
),
Expr(
StmtExpr {
range: 171..191,
value: ListComp(
ExprListComp {
range: 171..191,
elt: Name(
ExprName {
range: 172..173,
id: "x",
ctx: Load,
},
),
generators: [
Comprehension {
range: 174..190,
target: Name(
ExprName {
range: 178..179,
id: "x",
ctx: Store,
},
),
iter: Yield(
ExprYield {
range: 183..190,
value: Some(
Name(
ExprName {
range: 189..190,
id: "y",
ctx: Load,
},
),
),
},
),
ifs: [],
is_async: false,
},
],
},
),
},
),
Expr(
StmtExpr {
range: 192..217,
value: ListComp(
ExprListComp {
range: 192..217,
elt: Name(
ExprName {
range: 193..194,
id: "x",
ctx: Load,
},
),
generators: [
Comprehension {
range: 195..216,
target: Name(
ExprName {
range: 199..200,
id: "x",
ctx: Store,
},
),
iter: YieldFrom(
ExprYieldFrom {
range: 204..216,
value: Name(
ExprName {
range: 215..216,
id: "y",
ctx: Load,
},
),
},
),
ifs: [],
is_async: false,
},
],
},
),
},
),
Expr(
StmtExpr {
range: 218..242,
value: ListComp(
ExprListComp {
range: 218..242,
elt: Name(
ExprName {
range: 219..220,
id: "x",
ctx: Load,
},
),
generators: [
Comprehension {
range: 221..241,
target: Name(
ExprName {
range: 225..226,
id: "x",
ctx: Store,
},
),
iter: Lambda(
ExprLambda {
range: 230..241,
parameters: Some(
Parameters {
range: 237..238,
posonlyargs: [],
args: [
ParameterWithDefault {
range: 237..238,
parameter: Parameter {
range: 237..238,
name: Identifier {
id: "y",
range: 237..238,
},
annotation: None,
},
default: None,
},
],
vararg: None,
kwonlyargs: [],
kwarg: None,
},
),
body: Name(
ExprName {
range: 240..241,
id: "y",
ctx: Load,
},
),
},
),
ifs: [],
is_async: false,
},
],
},
),
},
),
Expr(
StmtExpr {
range: 257..280,
value: ListComp(
ExprListComp {
range: 257..280,
elt: Name(
ExprName {
range: 258..259,
id: "x",
ctx: Load,
},
),
generators: [
Comprehension {
range: 260..279,
target: Name(
ExprName {
range: 264..265,
id: "x",
ctx: Store,
},
),
iter: Name(
ExprName {
range: 269..273,
id: "data",
ctx: Load,
},
),
ifs: [
Starred(
ExprStarred {
range: 277..279,
value: Name(
ExprName {
range: 278..279,
id: "y",
ctx: Load,
},
),
ctx: Load,
},
),
],
is_async: false,
},
],
},
),
},
),
Expr(
StmtExpr {
range: 281..309,
value: ListComp(
ExprListComp {
range: 281..309,
elt: Name(
ExprName {
range: 282..283,
id: "x",
ctx: Load,
},
),
generators: [
Comprehension {
range: 284..308,
target: Name(
ExprName {
range: 288..289,
id: "x",
ctx: Store,
},
),
iter: Name(
ExprName {
range: 293..297,
id: "data",
ctx: Load,
},
),
ifs: [
Yield(
ExprYield {
range: 301..308,
value: Some(
Name(
ExprName {
range: 307..308,
id: "y",
ctx: Load,
},
),
),
},
),
],
is_async: false,
},
],
},
),
},
),
Expr(
StmtExpr {
range: 310..343,
value: ListComp(
ExprListComp {
range: 310..343,
elt: Name(
ExprName {
range: 311..312,
id: "x",
ctx: Load,
},
),
generators: [
Comprehension {
range: 313..342,
target: Name(
ExprName {
range: 317..318,
id: "x",
ctx: Store,
},
),
iter: Name(
ExprName {
range: 322..326,
id: "data",
ctx: Load,
},
),
ifs: [
YieldFrom(
ExprYieldFrom {
range: 330..342,
value: Name(
ExprName {
range: 341..342,
id: "y",
ctx: Load,
},
),
},
),
],
is_async: false,
},
],
},
),
},
),
Expr(
StmtExpr {
range: 344..376,
value: ListComp(
ExprListComp {
range: 344..376,
elt: Name(
ExprName {
range: 345..346,
id: "x",
ctx: Load,
},
),
generators: [
Comprehension {
range: 347..375,
target: Name(
ExprName {
range: 351..352,
id: "x",
ctx: Store,
},
),
iter: Name(
ExprName {
range: 356..360,
id: "data",
ctx: Load,
},
),
ifs: [
Lambda(
ExprLambda {
range: 364..375,
parameters: Some(
Parameters {
range: 371..372,
posonlyargs: [],
args: [
ParameterWithDefault {
range: 371..372,
parameter: Parameter {
range: 371..372,
name: Identifier {
id: "y",
range: 371..372,
},
annotation: None,
},
default: None,
},
],
vararg: None,
kwonlyargs: [],
kwarg: None,
},
),
body: Name(
ExprName {
range: 374..375,
id: "y",
ctx: Load,
},
),
},
),
],
is_async: false,
},
],
},
),
},
),
],
},
)
```
## Errors
|
1 | # Iterable unpacking not allowed
2 | [*x for x in y]
| ^^ Syntax Error: Iterable unpacking cannot be used in a comprehension
3 |
4 | # Invalid target
|
|
4 | # Invalid target
5 | [x for 1 in y]
| ^ Syntax Error: Invalid assignment target
6 | [x for 'a' in y]
7 | [x for call() in y]
|
|
4 | # Invalid target
5 | [x for 1 in y]
6 | [x for 'a' in y]
| ^^^ Syntax Error: Invalid assignment target
7 | [x for call() in y]
8 | [x for {a, b} in y]
|
|
5 | [x for 1 in y]
6 | [x for 'a' in y]
7 | [x for call() in y]
| ^^^^^^ Syntax Error: Invalid assignment target
8 | [x for {a, b} in y]
|
|
6 | [x for 'a' in y]
7 | [x for call() in y]
8 | [x for {a, b} in y]
| ^^^^^^ Syntax Error: Invalid assignment target
9 |
10 | # Invalid iter
|
|
10 | # Invalid iter
11 | [x for x in *y]
| ^^ Syntax Error: Starred expression cannot be used here
12 | [x for x in yield y]
13 | [x for x in yield from y]
|
|
10 | # Invalid iter
11 | [x for x in *y]
12 | [x for x in yield y]
| ^^^^^^^ Syntax Error: Yield expression cannot be used here
13 | [x for x in yield from y]
14 | [x for x in lambda y: y]
|
|
11 | [x for x in *y]
12 | [x for x in yield y]
13 | [x for x in yield from y]
| ^^^^^^^^^^^^ Syntax Error: Yield expression cannot be used here
14 | [x for x in lambda y: y]
|
|
12 | [x for x in yield y]
13 | [x for x in yield from y]
14 | [x for x in lambda y: y]
| ^^^^^^^^^^^ Syntax Error: Lambda expression cannot be used here
15 |
16 | # Invalid if
|
|
16 | # Invalid if
17 | [x for x in data if *y]
| ^^ Syntax Error: Starred expression cannot be used here
18 | [x for x in data if yield y]
19 | [x for x in data if yield from y]
|
|
16 | # Invalid if
17 | [x for x in data if *y]
18 | [x for x in data if yield y]
| ^^^^^^^ Syntax Error: Yield expression cannot be used here
19 | [x for x in data if yield from y]
20 | [x for x in data if lambda y: y]
|
|
17 | [x for x in data if *y]
18 | [x for x in data if yield y]
19 | [x for x in data if yield from y]
| ^^^^^^^^^^^^ Syntax Error: Yield expression cannot be used here
20 | [x for x in data if lambda y: y]
|
|
18 | [x for x in data if yield y]
19 | [x for x in data if yield from y]
20 | [x for x in data if lambda y: y]
| ^^^^^^^^^^^ Syntax Error: Lambda expression cannot be used here
|

View file

@ -0,0 +1,43 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/list/missing_closing_bracket_0.py
---
## AST
```
Module(
ModModule {
range: 0..43,
body: [
Expr(
StmtExpr {
range: 42..43,
value: List(
ExprList {
range: 42..43,
elts: [
Name(
ExprName {
range: 43..43,
id: "",
ctx: Invalid,
},
),
],
ctx: Load,
},
),
},
),
],
},
)
```
## Errors
|
1 | # Missing closing bracket 0: No elements
2 |
3 | [
| Syntax Error: unexpected EOF while parsing
|

View file

@ -0,0 +1,56 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/list/missing_closing_bracket_1.py
---
## AST
```
Module(
ModModule {
range: 0..133,
body: [
Expr(
StmtExpr {
range: 125..133,
value: List(
ExprList {
range: 125..133,
elts: [
BinOp(
ExprBinOp {
range: 128..133,
left: Name(
ExprName {
range: 128..129,
id: "x",
ctx: Load,
},
),
op: Add,
right: Name(
ExprName {
range: 132..133,
id: "y",
ctx: Load,
},
),
},
),
],
ctx: Load,
},
),
},
),
],
},
)
```
## Errors
|
4 | [
5 |
6 | x + y
| Syntax Error: unexpected EOF while parsing
|

View file

@ -0,0 +1,64 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/list/missing_closing_bracket_2.py
---
## AST
```
Module(
ModModule {
range: 0..141,
body: [
Expr(
StmtExpr {
range: 131..141,
value: List(
ExprList {
range: 131..141,
elts: [
NumberLiteral(
ExprNumberLiteral {
range: 132..133,
value: Int(
1,
),
},
),
BinOp(
ExprBinOp {
range: 136..141,
left: Name(
ExprName {
range: 136..137,
id: "x",
ctx: Load,
},
),
op: Add,
right: Name(
ExprName {
range: 140..141,
id: "y",
ctx: Load,
},
),
},
),
],
ctx: Load,
},
),
},
),
],
},
)
```
## Errors
|
4 | [1,
5 |
6 | x + y
| Syntax Error: unexpected EOF while parsing
|

View file

@ -0,0 +1,88 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/list/missing_closing_bracket_3.py
---
## AST
```
Module(
ModModule {
range: 0..140,
body: [
Expr(
StmtExpr {
range: 114..119,
value: List(
ExprList {
range: 114..119,
elts: [
NumberLiteral(
ExprNumberLiteral {
range: 115..116,
value: Int(
1,
),
},
),
NumberLiteral(
ExprNumberLiteral {
range: 118..119,
value: Int(
2,
),
},
),
],
ctx: Load,
},
),
},
),
FunctionDef(
StmtFunctionDef {
range: 121..140,
is_async: false,
decorator_list: [],
name: Identifier {
id: "foo",
range: 125..128,
},
type_params: None,
parameters: Parameters {
range: 128..130,
posonlyargs: [],
args: [],
vararg: None,
kwonlyargs: [],
kwarg: None,
},
returns: None,
body: [
Pass(
StmtPass {
range: 136..140,
},
),
],
},
),
],
},
)
```
## Errors
|
4 | [1, 2
5 |
6 | def foo():
| ^^^ Syntax Error: Expected ',', found 'def'
7 | pass
|
|
6 | def foo():
7 | pass
| Syntax Error: unexpected EOF while parsing
|

View file

@ -0,0 +1,314 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/invalid/expressions/list/recover.py
---
## AST
```
Module(
ModModule {
range: 0..208,
body: [
Expr(
StmtExpr {
range: 82..85,
value: List(
ExprList {
range: 82..85,
elts: [
Name(
ExprName {
range: 83..83,
id: "",
ctx: Invalid,
},
),
],
ctx: Load,
},
),
},
),
Expr(
StmtExpr {
range: 87..93,
value: List(
ExprList {
range: 87..93,
elts: [
NumberLiteral(
ExprNumberLiteral {
range: 88..89,
value: Int(
1,
),
},
),
NumberLiteral(
ExprNumberLiteral {
range: 91..92,
value: Int(
2,
),
},
),
],
ctx: Load,
},
),
},
),
Expr(
StmtExpr {
range: 95..100,
value: List(
ExprList {
range: 95..100,
elts: [
NumberLiteral(
ExprNumberLiteral {
range: 96..97,
value: Int(
1,
),
},
),
],
ctx: Load,
},
),
},
),
Expr(
StmtExpr {
range: 118..123,
value: List(
ExprList {
range: 118..123,
elts: [
NumberLiteral(
ExprNumberLiteral {
range: 119..120,
value: Int(
1,
),
},
),
NumberLiteral(
ExprNumberLiteral {
range: 121..122,
value: Int(
2,
),
},
),
],
ctx: Load,
},
),
},
),
Expr(
StmtExpr {
range: 156..162,
value: List(
ExprList {
range: 156..162,
elts: [
NumberLiteral(
ExprNumberLiteral {
range: 157..158,
value: Int(
1,
),
},
),
NumberLiteral(
ExprNumberLiteral {
range: 160..161,
value: Int(
2,
),
},
),
],
ctx: Load,
},
),
},
),
Expr(
StmtExpr {
range: 185..194,
value: List(
ExprList {
range: 185..194,
elts: [
NumberLiteral(
ExprNumberLiteral {
range: 186..187,
value: Int(
1,
),
},
),
BinOp(
ExprBinOp {
range: 189..192,
left: Name(
ExprName {
range: 189..190,
id: "x",
ctx: Load,
},
),
op: Add,
right: Name(
ExprName {
range: 192..192,
id: "",
ctx: Invalid,
},
),
},
),
],
ctx: Load,
},
),
},
),
Expr(
StmtExpr {
range: 196..202,
value: List(
ExprList {
range: 196..202,
elts: [
NumberLiteral(
ExprNumberLiteral {
range: 197..198,
value: Int(
1,
),
},
),
NumberLiteral(
ExprNumberLiteral {
range: 200..201,
value: Int(
2,
),
},
),
],
ctx: Load,
},
),
},
),
Expr(
StmtExpr {
range: 204..207,
value: List(
ExprList {
range: 204..207,
elts: [
Starred(
ExprStarred {
range: 205..206,
value: Name(
ExprName {
range: 206..206,
id: "",
ctx: Invalid,
},
),
ctx: Load,
},
),
],
ctx: Load,
},
),
},
),
],
},
)
```
## Errors
|
1 | # Test cases for list expressions where the parser recovers from a syntax error.
2 |
3 | [,]
| ^ Syntax Error: Expected an expression
4 |
5 | [1,,2]
|
|
3 | [,]
4 |
5 | [1,,2]
| ^ Syntax Error: Expected an expression or a ']'
6 |
7 | [1,,]
|
|
5 | [1,,2]
6 |
7 | [1,,]
| ^ Syntax Error: Expected an expression or a ']'
8 |
9 | # Missing comma
|
|
9 | # Missing comma
10 | [1 2]
| ^ Syntax Error: Expected ',', found int
11 |
12 | # Dictionary element in a list
|
|
12 | # Dictionary element in a list
13 | [1: 2]
| ^ Syntax Error: Expected an expression or a ']'
14 |
15 | # Missing expression
|
|
15 | # Missing expression
16 | [1, x + ]
| ^ Syntax Error: Expected an expression
17 |
18 | [1; 2]
|
|
16 | [1, x + ]
17 |
18 | [1; 2]
| ^ Syntax Error: Expected an expression or a ']'
19 |
20 | [*]
|
|
18 | [1; 2]
19 |
20 | [*]
| ^ Syntax Error: Expected an expression
|

Some files were not shown because too many files have changed in this diff Show more