mirror of https://github.com/astral-sh/ruff
Reuse Arena in lexer
This commit is contained in:
parent
811dd2bb68
commit
678f8732e4
|
|
@ -2,6 +2,7 @@ use codspeed_criterion_compat::{
|
||||||
criterion_group, criterion_main, measurement::WallTime, BenchmarkId, Criterion, Throughput,
|
criterion_group, criterion_main, measurement::WallTime, BenchmarkId, Criterion, Throughput,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use ruff_allocator::Allocator;
|
||||||
use ruff_benchmark::{TestCase, TestFile, TestFileDownloadError};
|
use ruff_benchmark::{TestCase, TestFile, TestFileDownloadError};
|
||||||
use ruff_python_parser::{lexer, Mode, TokenKind};
|
use ruff_python_parser::{lexer, Mode, TokenKind};
|
||||||
|
|
||||||
|
|
@ -48,7 +49,8 @@ fn benchmark_lexer(criterion: &mut Criterion<WallTime>) {
|
||||||
&case,
|
&case,
|
||||||
|b, case| {
|
|b, case| {
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
let mut lexer = lexer::lex(case.code(), Mode::Module);
|
let allocator = Allocator::new();
|
||||||
|
let mut lexer = lexer::lex(case.code(), Mode::Module, &allocator);
|
||||||
loop {
|
loop {
|
||||||
let token = lexer.next_token();
|
let token = lexer.next_token();
|
||||||
match token {
|
match token {
|
||||||
|
|
|
||||||
|
|
@ -346,14 +346,14 @@ impl From<&ast::Singleton> for ComparableSingleton {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||||
pub enum ComparableNumber<'a> {
|
pub enum ComparableNumber<'a, 'ast> {
|
||||||
Int(&'a ast::Int),
|
Int(&'a ast::Int<'ast>),
|
||||||
Float(u64),
|
Float(u64),
|
||||||
Complex { real: u64, imag: u64 },
|
Complex { real: u64, imag: u64 },
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'ast> From<&'a ast::Number> for ComparableNumber<'a> {
|
impl<'a, 'ast> From<&'a ast::Number<'ast>> for ComparableNumber<'a, 'ast> {
|
||||||
fn from(number: &'a ast::Number) -> Self {
|
fn from(number: &'a ast::Number<'ast>) -> Self {
|
||||||
match number {
|
match number {
|
||||||
ast::Number::Int(value) => Self::Int(&value),
|
ast::Number::Int(value) => Self::Int(&value),
|
||||||
ast::Number::Float(value) => Self::Float(value.to_bits()),
|
ast::Number::Float(value) => Self::Float(value.to_bits()),
|
||||||
|
|
@ -581,7 +581,7 @@ pub enum ComparableLiteral<'a, 'ast> {
|
||||||
Bool(bool),
|
Bool(bool),
|
||||||
Str(Vec<ComparableStringLiteral<'ast>>),
|
Str(Vec<ComparableStringLiteral<'ast>>),
|
||||||
Bytes(Vec<ComparableBytesLiteral<'ast>>),
|
Bytes(Vec<ComparableBytesLiteral<'ast>>),
|
||||||
Number(ComparableNumber<'a>),
|
Number(ComparableNumber<'a, 'ast>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'ast> From<ast::LiteralExpressionRef<'a, 'ast>> for ComparableLiteral<'a, 'ast> {
|
impl<'a, 'ast> From<ast::LiteralExpressionRef<'a, 'ast>> for ComparableLiteral<'a, 'ast> {
|
||||||
|
|
@ -799,8 +799,8 @@ pub struct ExprBytesLiteral<'ast> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||||
pub struct ExprNumberLiteral<'a> {
|
pub struct ExprNumberLiteral<'a, 'ast> {
|
||||||
value: ComparableNumber<'a>,
|
value: ComparableNumber<'a, 'ast>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||||
|
|
@ -876,7 +876,7 @@ pub enum ComparableExpr<'a, 'ast> {
|
||||||
FString(ExprFString<'a, 'ast>),
|
FString(ExprFString<'a, 'ast>),
|
||||||
StringLiteral(ExprStringLiteral<'ast>),
|
StringLiteral(ExprStringLiteral<'ast>),
|
||||||
BytesLiteral(ExprBytesLiteral<'ast>),
|
BytesLiteral(ExprBytesLiteral<'ast>),
|
||||||
NumberLiteral(ExprNumberLiteral<'a>),
|
NumberLiteral(ExprNumberLiteral<'a, 'ast>),
|
||||||
BoolLiteral(ExprBoolLiteral),
|
BoolLiteral(ExprBoolLiteral),
|
||||||
NoneLiteral,
|
NoneLiteral,
|
||||||
EllipsisLiteral,
|
EllipsisLiteral,
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ pub enum ExpressionRef<'a, 'ast> {
|
||||||
FString(&'a ast::ExprFString<'ast>),
|
FString(&'a ast::ExprFString<'ast>),
|
||||||
StringLiteral(&'a ast::ExprStringLiteral<'ast>),
|
StringLiteral(&'a ast::ExprStringLiteral<'ast>),
|
||||||
BytesLiteral(&'a ast::ExprBytesLiteral<'ast>),
|
BytesLiteral(&'a ast::ExprBytesLiteral<'ast>),
|
||||||
NumberLiteral(&'a ast::ExprNumberLiteral),
|
NumberLiteral(&'a ast::ExprNumberLiteral<'ast>),
|
||||||
BooleanLiteral(&'a ast::ExprBooleanLiteral),
|
BooleanLiteral(&'a ast::ExprBooleanLiteral),
|
||||||
NoneLiteral(&'a ast::ExprNoneLiteral),
|
NoneLiteral(&'a ast::ExprNoneLiteral),
|
||||||
EllipsisLiteral(&'a ast::ExprEllipsisLiteral),
|
EllipsisLiteral(&'a ast::ExprEllipsisLiteral),
|
||||||
|
|
@ -186,8 +186,8 @@ impl<'a, 'ast> From<&'a ast::ExprBytesLiteral<'ast>> for ExpressionRef<'a, 'ast>
|
||||||
Self::BytesLiteral(value)
|
Self::BytesLiteral(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<'a> From<&'a ast::ExprNumberLiteral> for ExpressionRef<'a, '_> {
|
impl<'a, 'ast> From<&'a ast::ExprNumberLiteral<'ast>> for ExpressionRef<'a, 'ast> {
|
||||||
fn from(value: &'a ast::ExprNumberLiteral) -> Self {
|
fn from(value: &'a ast::ExprNumberLiteral<'ast>) -> Self {
|
||||||
Self::NumberLiteral(value)
|
Self::NumberLiteral(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -335,7 +335,7 @@ impl Ranged for ExpressionRef<'_, '_> {
|
||||||
pub enum LiteralExpressionRef<'a, 'ast> {
|
pub enum LiteralExpressionRef<'a, 'ast> {
|
||||||
StringLiteral(&'a ast::ExprStringLiteral<'ast>),
|
StringLiteral(&'a ast::ExprStringLiteral<'ast>),
|
||||||
BytesLiteral(&'a ast::ExprBytesLiteral<'ast>),
|
BytesLiteral(&'a ast::ExprBytesLiteral<'ast>),
|
||||||
NumberLiteral(&'a ast::ExprNumberLiteral),
|
NumberLiteral(&'a ast::ExprNumberLiteral<'ast>),
|
||||||
BooleanLiteral(&'a ast::ExprBooleanLiteral),
|
BooleanLiteral(&'a ast::ExprBooleanLiteral),
|
||||||
NoneLiteral(&'a ast::ExprNoneLiteral),
|
NoneLiteral(&'a ast::ExprNoneLiteral),
|
||||||
EllipsisLiteral(&'a ast::ExprEllipsisLiteral),
|
EllipsisLiteral(&'a ast::ExprEllipsisLiteral),
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,12 @@
|
||||||
|
use ruff_allocator::Allocator;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::str::FromStr;
|
|
||||||
|
|
||||||
/// A Python integer literal. Represents both small (fits in an `i64`) and large integers.
|
/// A Python integer literal. Represents both small (fits in an `i64`) and large integers.
|
||||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct Int(Number);
|
pub struct Int<'ast>(Number<'ast>);
|
||||||
|
|
||||||
impl FromStr for Int {
|
impl<'ast> Int<'ast> {
|
||||||
type Err = std::num::ParseIntError;
|
pub fn from_str(s: &str, allocator: &'ast Allocator) -> Result<Self, std::num::ParseIntError> {
|
||||||
|
|
||||||
/// Parse an [`Int`] from a string.
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
||||||
match s.parse::<u64>() {
|
match s.parse::<u64>() {
|
||||||
Ok(value) => Ok(Int::small(value)),
|
Ok(value) => Ok(Int::small(value)),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|
@ -17,7 +14,7 @@ impl FromStr for Int {
|
||||||
err.kind(),
|
err.kind(),
|
||||||
std::num::IntErrorKind::PosOverflow | std::num::IntErrorKind::NegOverflow
|
std::num::IntErrorKind::PosOverflow | std::num::IntErrorKind::NegOverflow
|
||||||
) {
|
) {
|
||||||
Ok(Int::big(s))
|
Ok(Int::big(allocator.alloc_str(s)))
|
||||||
} else {
|
} else {
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
|
|
@ -26,9 +23,9 @@ impl FromStr for Int {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Int {
|
impl<'ast> Int<'ast> {
|
||||||
pub const ZERO: Int = Int(Number::Small(0));
|
pub const ZERO: Int<'static> = Int(Number::Small(0));
|
||||||
pub const ONE: Int = Int(Number::Small(1));
|
pub const ONE: Int<'static> = Int(Number::Small(1));
|
||||||
|
|
||||||
/// Create an [`Int`] to represent a value that can be represented as an `i64`.
|
/// Create an [`Int`] to represent a value that can be represented as an `i64`.
|
||||||
fn small(value: u64) -> Self {
|
fn small(value: u64) -> Self {
|
||||||
|
|
@ -36,8 +33,8 @@ impl Int {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create an [`Int`] to represent a value that cannot be represented as an `i64`.
|
/// Create an [`Int`] to represent a value that cannot be represented as an `i64`.
|
||||||
fn big(value: impl Into<Box<str>>) -> Self {
|
fn big(value: &'ast str) -> Self {
|
||||||
Self(Number::Big(value.into()))
|
Self(Number::Big(value))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse an [`Int`] from a string with a given radix, like `0x95D`.
|
/// Parse an [`Int`] from a string with a given radix, like `0x95D`.
|
||||||
|
|
@ -48,6 +45,7 @@ impl Int {
|
||||||
number: &str,
|
number: &str,
|
||||||
radix: u32,
|
radix: u32,
|
||||||
token: &str,
|
token: &str,
|
||||||
|
allocator: &'ast Allocator,
|
||||||
) -> Result<Self, std::num::ParseIntError> {
|
) -> Result<Self, std::num::ParseIntError> {
|
||||||
match u64::from_str_radix(number, radix) {
|
match u64::from_str_radix(number, radix) {
|
||||||
Ok(value) => Ok(Int::small(value)),
|
Ok(value) => Ok(Int::small(value)),
|
||||||
|
|
@ -56,7 +54,7 @@ impl Int {
|
||||||
err.kind(),
|
err.kind(),
|
||||||
std::num::IntErrorKind::PosOverflow | std::num::IntErrorKind::NegOverflow
|
std::num::IntErrorKind::PosOverflow | std::num::IntErrorKind::NegOverflow
|
||||||
) {
|
) {
|
||||||
Ok(Int::big(token))
|
Ok(Int::big(allocator.alloc_str(token)))
|
||||||
} else {
|
} else {
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
|
|
@ -129,93 +127,93 @@ impl Int {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for Int {
|
impl std::fmt::Display for Int<'_> {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
write!(f, "{}", self.0)
|
write!(f, "{}", self.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Debug for Int {
|
impl Debug for Int<'_> {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
std::fmt::Display::fmt(self, f)
|
std::fmt::Display::fmt(self, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq<u8> for Int {
|
impl<'a> PartialEq<u8> for Int<'a> {
|
||||||
fn eq(&self, other: &u8) -> bool {
|
fn eq(&self, other: &u8) -> bool {
|
||||||
self.as_u8() == Some(*other)
|
self.as_u8() == Some(*other)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq<u16> for Int {
|
impl<'a> PartialEq<u16> for Int<'a> {
|
||||||
fn eq(&self, other: &u16) -> bool {
|
fn eq(&self, other: &u16) -> bool {
|
||||||
self.as_u16() == Some(*other)
|
self.as_u16() == Some(*other)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq<u32> for Int {
|
impl<'a> PartialEq<u32> for Int<'a> {
|
||||||
fn eq(&self, other: &u32) -> bool {
|
fn eq(&self, other: &u32) -> bool {
|
||||||
self.as_u32() == Some(*other)
|
self.as_u32() == Some(*other)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq<i8> for Int {
|
impl<'a> PartialEq<i8> for Int<'a> {
|
||||||
fn eq(&self, other: &i8) -> bool {
|
fn eq(&self, other: &i8) -> bool {
|
||||||
self.as_i8() == Some(*other)
|
self.as_i8() == Some(*other)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq<i16> for Int {
|
impl<'a> PartialEq<i16> for Int<'a> {
|
||||||
fn eq(&self, other: &i16) -> bool {
|
fn eq(&self, other: &i16) -> bool {
|
||||||
self.as_i16() == Some(*other)
|
self.as_i16() == Some(*other)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq<i32> for Int {
|
impl<'a> PartialEq<i32> for Int<'a> {
|
||||||
fn eq(&self, other: &i32) -> bool {
|
fn eq(&self, other: &i32) -> bool {
|
||||||
self.as_i32() == Some(*other)
|
self.as_i32() == Some(*other)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq<i64> for Int {
|
impl<'a> PartialEq<i64> for Int<'a> {
|
||||||
fn eq(&self, other: &i64) -> bool {
|
fn eq(&self, other: &i64) -> bool {
|
||||||
self.as_i64() == Some(*other)
|
self.as_i64() == Some(*other)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<u8> for Int {
|
impl From<u8> for Int<'static> {
|
||||||
fn from(value: u8) -> Self {
|
fn from(value: u8) -> Self {
|
||||||
Self::small(u64::from(value))
|
Self::small(u64::from(value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<u16> for Int {
|
impl From<u16> for Int<'static> {
|
||||||
fn from(value: u16) -> Self {
|
fn from(value: u16) -> Self {
|
||||||
Self::small(u64::from(value))
|
Self::small(u64::from(value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<u32> for Int {
|
impl From<u32> for Int<'static> {
|
||||||
fn from(value: u32) -> Self {
|
fn from(value: u32) -> Self {
|
||||||
Self::small(u64::from(value))
|
Self::small(u64::from(value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<u64> for Int {
|
impl From<u64> for Int<'static> {
|
||||||
fn from(value: u64) -> Self {
|
fn from(value: u64) -> Self {
|
||||||
Self::small(value)
|
Self::small(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
enum Number {
|
enum Number<'ast> {
|
||||||
/// A "small" number that can be represented as an `u64`.
|
/// A "small" number that can be represented as an `u64`.
|
||||||
Small(u64),
|
Small(u64),
|
||||||
/// A "large" number that cannot be represented as an `u64`.
|
/// A "large" number that cannot be represented as an `u64`.
|
||||||
Big(Box<str>),
|
Big(&'ast str),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for Number {
|
impl std::fmt::Display for Number<'_> {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Number::Small(value) => write!(f, "{value}"),
|
Number::Small(value) => write!(f, "{value}"),
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,7 @@ pub enum AnyNode<'ast> {
|
||||||
ExprFString(ast::ExprFString<'ast>),
|
ExprFString(ast::ExprFString<'ast>),
|
||||||
ExprStringLiteral(ast::ExprStringLiteral<'ast>),
|
ExprStringLiteral(ast::ExprStringLiteral<'ast>),
|
||||||
ExprBytesLiteral(ast::ExprBytesLiteral<'ast>),
|
ExprBytesLiteral(ast::ExprBytesLiteral<'ast>),
|
||||||
ExprNumberLiteral(ast::ExprNumberLiteral),
|
ExprNumberLiteral(ast::ExprNumberLiteral<'ast>),
|
||||||
ExprBooleanLiteral(ast::ExprBooleanLiteral),
|
ExprBooleanLiteral(ast::ExprBooleanLiteral),
|
||||||
ExprNoneLiteral(ast::ExprNoneLiteral),
|
ExprNoneLiteral(ast::ExprNoneLiteral),
|
||||||
ExprEllipsisLiteral(ast::ExprEllipsisLiteral),
|
ExprEllipsisLiteral(ast::ExprEllipsisLiteral),
|
||||||
|
|
@ -3103,7 +3103,7 @@ impl<'ast> AstNode<'ast> for ast::ExprBytesLiteral<'ast> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<'ast> AstNode<'ast> for ast::ExprNumberLiteral {
|
impl<'ast> AstNode<'ast> for ast::ExprNumberLiteral<'ast> {
|
||||||
type Ref<'a> = &'a Self where 'ast: 'a;
|
type Ref<'a> = &'a Self where 'ast: 'a;
|
||||||
fn cast(kind: AnyNode<'ast>) -> Option<Self>
|
fn cast(kind: AnyNode<'ast>) -> Option<Self>
|
||||||
where
|
where
|
||||||
|
|
@ -3138,7 +3138,6 @@ impl<'ast> AstNode<'ast> for ast::ExprNumberLiteral {
|
||||||
|
|
||||||
fn visit_source_order<'a, V>(&'a self, _visitor: &mut V)
|
fn visit_source_order<'a, V>(&'a self, _visitor: &mut V)
|
||||||
where
|
where
|
||||||
'ast: 'a,
|
|
||||||
V: SourceOrderVisitor<'a, 'ast> + ?Sized,
|
V: SourceOrderVisitor<'a, 'ast> + ?Sized,
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
@ -5851,8 +5850,8 @@ impl<'ast> From<ast::ExprBytesLiteral<'ast>> for AnyNode<'ast> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'ast> From<ast::ExprNumberLiteral> for AnyNode<'ast> {
|
impl<'ast> From<ast::ExprNumberLiteral<'ast>> for AnyNode<'ast> {
|
||||||
fn from(node: ast::ExprNumberLiteral) -> Self {
|
fn from(node: ast::ExprNumberLiteral<'ast>) -> Self {
|
||||||
AnyNode::ExprNumberLiteral(node)
|
AnyNode::ExprNumberLiteral(node)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -6230,7 +6229,7 @@ pub enum AnyNodeRef<'a, 'ast> {
|
||||||
ExprFString(&'a ast::ExprFString<'ast>),
|
ExprFString(&'a ast::ExprFString<'ast>),
|
||||||
ExprStringLiteral(&'a ast::ExprStringLiteral<'ast>),
|
ExprStringLiteral(&'a ast::ExprStringLiteral<'ast>),
|
||||||
ExprBytesLiteral(&'a ast::ExprBytesLiteral<'ast>),
|
ExprBytesLiteral(&'a ast::ExprBytesLiteral<'ast>),
|
||||||
ExprNumberLiteral(&'a ast::ExprNumberLiteral),
|
ExprNumberLiteral(&'a ast::ExprNumberLiteral<'ast>),
|
||||||
ExprBooleanLiteral(&'a ast::ExprBooleanLiteral),
|
ExprBooleanLiteral(&'a ast::ExprBooleanLiteral),
|
||||||
ExprNoneLiteral(&'a ast::ExprNoneLiteral),
|
ExprNoneLiteral(&'a ast::ExprNoneLiteral),
|
||||||
ExprEllipsisLiteral(&'a ast::ExprEllipsisLiteral),
|
ExprEllipsisLiteral(&'a ast::ExprEllipsisLiteral),
|
||||||
|
|
@ -7548,8 +7547,8 @@ impl<'a, 'ast> From<&'a ast::ExprBytesLiteral<'ast>> for AnyNodeRef<'a, 'ast> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'ast> From<&'a ast::ExprNumberLiteral> for AnyNodeRef<'a, 'ast> {
|
impl<'a, 'ast> From<&'a ast::ExprNumberLiteral<'ast>> for AnyNodeRef<'a, 'ast> {
|
||||||
fn from(node: &'a ast::ExprNumberLiteral) -> Self {
|
fn from(node: &'a ast::ExprNumberLiteral<'ast>) -> Self {
|
||||||
AnyNodeRef::ExprNumberLiteral(node)
|
AnyNodeRef::ExprNumberLiteral(node)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -605,7 +605,7 @@ pub enum Expr<'ast> {
|
||||||
#[is(name = "bytes_literal_expr")]
|
#[is(name = "bytes_literal_expr")]
|
||||||
BytesLiteral(ExprBytesLiteral<'ast>),
|
BytesLiteral(ExprBytesLiteral<'ast>),
|
||||||
#[is(name = "number_literal_expr")]
|
#[is(name = "number_literal_expr")]
|
||||||
NumberLiteral(ExprNumberLiteral),
|
NumberLiteral(ExprNumberLiteral<'ast>),
|
||||||
#[is(name = "boolean_literal_expr")]
|
#[is(name = "boolean_literal_expr")]
|
||||||
BooleanLiteral(ExprBooleanLiteral),
|
BooleanLiteral(ExprBooleanLiteral),
|
||||||
#[is(name = "none_literal_expr")]
|
#[is(name = "none_literal_expr")]
|
||||||
|
|
@ -2616,26 +2616,26 @@ impl From<FStringFlags> for AnyStringFlags {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct ExprNumberLiteral {
|
pub struct ExprNumberLiteral<'ast> {
|
||||||
pub range: TextRange,
|
pub range: TextRange,
|
||||||
pub value: Number,
|
pub value: Number<'ast>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<ExprNumberLiteral> for Expr<'_> {
|
impl<'ast> From<ExprNumberLiteral<'ast>> for Expr<'ast> {
|
||||||
fn from(payload: ExprNumberLiteral) -> Self {
|
fn from(payload: ExprNumberLiteral<'ast>) -> Self {
|
||||||
Expr::NumberLiteral(payload)
|
Expr::NumberLiteral(payload)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Ranged for ExprNumberLiteral {
|
impl Ranged for ExprNumberLiteral<'_> {
|
||||||
fn range(&self) -> TextRange {
|
fn range(&self) -> TextRange {
|
||||||
self.range
|
self.range
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, is_macro::Is)]
|
#[derive(Clone, Debug, PartialEq, is_macro::Is)]
|
||||||
pub enum Number {
|
pub enum Number<'ast> {
|
||||||
Int(int::Int),
|
Int(int::Int<'ast>),
|
||||||
Float(f64),
|
Float(f64),
|
||||||
Complex { real: f64, imag: f64 },
|
Complex { real: f64, imag: f64 },
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -4,7 +4,6 @@ use std::ops::Deref;
|
||||||
use bitflags::bitflags;
|
use bitflags::bitflags;
|
||||||
use rustc_hash::{FxBuildHasher, FxHashSet};
|
use rustc_hash::{FxBuildHasher, FxHashSet};
|
||||||
|
|
||||||
use ruff_python_ast::name::Name;
|
|
||||||
use ruff_python_ast::{
|
use ruff_python_ast::{
|
||||||
self as ast, BoolOp, CmpOp, ConversionFlag, Expr, ExprContext, FStringElement, FStringElements,
|
self as ast, BoolOp, CmpOp, ConversionFlag, Expr, ExprContext, FStringElement, FStringElements,
|
||||||
IpyEscapeKind, Number, Operator, UnaryOp,
|
IpyEscapeKind, Number, Operator, UnaryOp,
|
||||||
|
|
@ -478,17 +477,14 @@ impl<'src, 'ast> Parser<'src, 'ast> {
|
||||||
let TokenValue::Name(name) = self.bump_value(TokenKind::Name) else {
|
let TokenValue::Name(name) = self.bump_value(TokenKind::Name) else {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
};
|
};
|
||||||
return ast::Identifier {
|
return ast::Identifier { id: name, range };
|
||||||
id: self.allocator.alloc_str(&name),
|
|
||||||
range,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.current_token_kind().is_soft_keyword() {
|
if self.current_token_kind().is_soft_keyword() {
|
||||||
let id = Name::new(self.src_text(range));
|
let id = self.src_text(range);
|
||||||
self.bump_soft_keyword_as_name();
|
self.bump_soft_keyword_as_name();
|
||||||
return ast::Identifier {
|
return ast::Identifier {
|
||||||
id: self.allocator.alloc_str(&id),
|
id: self.alloc_str(id),
|
||||||
range,
|
range,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -2287,7 +2283,7 @@ impl<'src, 'ast> Parser<'src, 'ast> {
|
||||||
let command = ast::ExprIpyEscapeCommand {
|
let command = ast::ExprIpyEscapeCommand {
|
||||||
range: self.node_range(start),
|
range: self.node_range(start),
|
||||||
kind,
|
kind,
|
||||||
value: self.alloc_str(&value),
|
value,
|
||||||
};
|
};
|
||||||
|
|
||||||
if self.mode != Mode::Ipython {
|
if self.mode != Mode::Ipython {
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ pub(crate) struct Parser<'src, 'ast> {
|
||||||
source: &'src str,
|
source: &'src str,
|
||||||
|
|
||||||
/// Token source for the parser that skips over any non-trivia token.
|
/// Token source for the parser that skips over any non-trivia token.
|
||||||
tokens: TokenSource<'src>,
|
tokens: TokenSource<'src, 'ast>,
|
||||||
|
|
||||||
/// Stores all the syntax errors found during the parsing.
|
/// Stores all the syntax errors found during the parsing.
|
||||||
errors: Vec<ParseError>,
|
errors: Vec<ParseError>,
|
||||||
|
|
@ -64,7 +64,7 @@ impl<'src, 'ast> Parser<'src, 'ast> {
|
||||||
start_offset: TextSize,
|
start_offset: TextSize,
|
||||||
allocator: &'ast Allocator,
|
allocator: &'ast Allocator,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let tokens = TokenSource::from_source(source, mode, start_offset);
|
let tokens = TokenSource::from_source(source, mode, start_offset, allocator);
|
||||||
|
|
||||||
Parser {
|
Parser {
|
||||||
mode,
|
mode,
|
||||||
|
|
@ -355,7 +355,7 @@ impl<'src, 'ast> Parser<'src, 'ast> {
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// If the current token is not of the given kind.
|
/// If the current token is not of the given kind.
|
||||||
fn bump_value(&mut self, kind: TokenKind) -> TokenValue {
|
fn bump_value(&mut self, kind: TokenKind) -> TokenValue<'ast> {
|
||||||
let value = self.tokens.take_value();
|
let value = self.tokens.take_value();
|
||||||
self.bump(kind);
|
self.bump(kind);
|
||||||
value
|
value
|
||||||
|
|
@ -668,7 +668,7 @@ impl<'src, 'ast> Parser<'src, 'ast> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a checkpoint to which the parser can later return to using [`Self::rewind`].
|
/// Creates a checkpoint to which the parser can later return to using [`Self::rewind`].
|
||||||
fn checkpoint(&self) -> ParserCheckpoint {
|
fn checkpoint(&self) -> ParserCheckpoint<'ast> {
|
||||||
ParserCheckpoint {
|
ParserCheckpoint {
|
||||||
tokens: self.tokens.checkpoint(),
|
tokens: self.tokens.checkpoint(),
|
||||||
errors_position: self.errors.len(),
|
errors_position: self.errors.len(),
|
||||||
|
|
@ -679,7 +679,7 @@ impl<'src, 'ast> Parser<'src, 'ast> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Restore the parser to the given checkpoint.
|
/// Restore the parser to the given checkpoint.
|
||||||
fn rewind(&mut self, checkpoint: ParserCheckpoint) {
|
fn rewind(&mut self, checkpoint: ParserCheckpoint<'ast>) {
|
||||||
let ParserCheckpoint {
|
let ParserCheckpoint {
|
||||||
tokens,
|
tokens,
|
||||||
errors_position,
|
errors_position,
|
||||||
|
|
@ -696,8 +696,8 @@ impl<'src, 'ast> Parser<'src, 'ast> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ParserCheckpoint {
|
struct ParserCheckpoint<'ast> {
|
||||||
tokens: TokenSourceCheckpoint,
|
tokens: TokenSourceCheckpoint<'ast>,
|
||||||
errors_position: usize,
|
errors_position: usize,
|
||||||
current_token_id: TokenId,
|
current_token_id: TokenId,
|
||||||
prev_token_end: TextSize,
|
prev_token_end: TextSize,
|
||||||
|
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/src/parser/tests.rs
|
|
||||||
assertion_line: 56
|
|
||||||
expression: parsed.expr()
|
|
||||||
---
|
|
||||||
Name(
|
|
||||||
ExprName {
|
|
||||||
range: 0..5,
|
|
||||||
id: "first",
|
|
||||||
ctx: Load,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
@ -1,400 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/src/parser/tests.rs
|
|
||||||
assertion_line: 144
|
|
||||||
expression: parsed.syntax()
|
|
||||||
---
|
|
||||||
Module(
|
|
||||||
ModModule {
|
|
||||||
range: 0..929,
|
|
||||||
body: [
|
|
||||||
Expr(
|
|
||||||
StmtExpr {
|
|
||||||
range: 21..42,
|
|
||||||
value: BinOp(
|
|
||||||
ExprBinOp {
|
|
||||||
range: 27..40,
|
|
||||||
left: Name(
|
|
||||||
ExprName {
|
|
||||||
range: 27..28,
|
|
||||||
id: "a",
|
|
||||||
ctx: Load,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
op: Mod,
|
|
||||||
right: Name(
|
|
||||||
ExprName {
|
|
||||||
range: 39..40,
|
|
||||||
id: "b",
|
|
||||||
ctx: Load,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
IpyEscapeCommand(
|
|
||||||
StmtIpyEscapeCommand {
|
|
||||||
range: 66..73,
|
|
||||||
kind: Help2,
|
|
||||||
value: "a.foo",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
IpyEscapeCommand(
|
|
||||||
StmtIpyEscapeCommand {
|
|
||||||
range: 74..80,
|
|
||||||
kind: Help,
|
|
||||||
value: "a.foo",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
IpyEscapeCommand(
|
|
||||||
StmtIpyEscapeCommand {
|
|
||||||
range: 81..88,
|
|
||||||
kind: Help,
|
|
||||||
value: "a.foo",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
IpyEscapeCommand(
|
|
||||||
StmtIpyEscapeCommand {
|
|
||||||
range: 89..100,
|
|
||||||
kind: Help2,
|
|
||||||
value: "a.foo()",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
IpyEscapeCommand(
|
|
||||||
StmtIpyEscapeCommand {
|
|
||||||
range: 115..128,
|
|
||||||
kind: Magic,
|
|
||||||
value: "timeit a = b",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
IpyEscapeCommand(
|
|
||||||
StmtIpyEscapeCommand {
|
|
||||||
range: 129..147,
|
|
||||||
kind: Magic,
|
|
||||||
value: "timeit foo(b) % 3",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
IpyEscapeCommand(
|
|
||||||
StmtIpyEscapeCommand {
|
|
||||||
range: 148..176,
|
|
||||||
kind: Magic,
|
|
||||||
value: "alias showPath pwd && ls -a",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
IpyEscapeCommand(
|
|
||||||
StmtIpyEscapeCommand {
|
|
||||||
range: 177..205,
|
|
||||||
kind: Magic,
|
|
||||||
value: "timeit a = foo(b); b = 2",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
IpyEscapeCommand(
|
|
||||||
StmtIpyEscapeCommand {
|
|
||||||
range: 206..226,
|
|
||||||
kind: Magic,
|
|
||||||
value: "matplotlib --inline",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
IpyEscapeCommand(
|
|
||||||
StmtIpyEscapeCommand {
|
|
||||||
range: 227..253,
|
|
||||||
kind: Magic,
|
|
||||||
value: "matplotlib --inline",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
IpyEscapeCommand(
|
|
||||||
StmtIpyEscapeCommand {
|
|
||||||
range: 277..309,
|
|
||||||
kind: Shell,
|
|
||||||
value: "pwd && ls -a | sed 's/^/\\ /'",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
IpyEscapeCommand(
|
|
||||||
StmtIpyEscapeCommand {
|
|
||||||
range: 310..347,
|
|
||||||
kind: Shell,
|
|
||||||
value: "pwd && ls -a | sed 's/^/\\\\ /'",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
IpyEscapeCommand(
|
|
||||||
StmtIpyEscapeCommand {
|
|
||||||
range: 348..393,
|
|
||||||
kind: ShCap,
|
|
||||||
value: "cd /Users/foo/Library/Application\\ Support/",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
FunctionDef(
|
|
||||||
StmtFunctionDef {
|
|
||||||
range: 566..626,
|
|
||||||
is_async: false,
|
|
||||||
decorator_list: [],
|
|
||||||
name: Identifier {
|
|
||||||
id: "foo",
|
|
||||||
range: 570..573,
|
|
||||||
},
|
|
||||||
type_params: None,
|
|
||||||
parameters: Parameters {
|
|
||||||
range: 573..575,
|
|
||||||
posonlyargs: [],
|
|
||||||
args: [],
|
|
||||||
vararg: None,
|
|
||||||
kwonlyargs: [],
|
|
||||||
kwarg: None,
|
|
||||||
},
|
|
||||||
returns: None,
|
|
||||||
body: [
|
|
||||||
Return(
|
|
||||||
StmtReturn {
|
|
||||||
range: 581..626,
|
|
||||||
value: Some(
|
|
||||||
Compare(
|
|
||||||
ExprCompare {
|
|
||||||
range: 598..620,
|
|
||||||
left: Name(
|
|
||||||
ExprName {
|
|
||||||
range: 598..599,
|
|
||||||
id: "a",
|
|
||||||
ctx: Load,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
ops: [
|
|
||||||
NotEq,
|
|
||||||
],
|
|
||||||
comparators: [
|
|
||||||
Name(
|
|
||||||
ExprName {
|
|
||||||
range: 619..620,
|
|
||||||
id: "b",
|
|
||||||
ctx: Load,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
),
|
|
||||||
IpyEscapeCommand(
|
|
||||||
StmtIpyEscapeCommand {
|
|
||||||
range: 656..664,
|
|
||||||
kind: Paren,
|
|
||||||
value: "foo 1 2",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
IpyEscapeCommand(
|
|
||||||
StmtIpyEscapeCommand {
|
|
||||||
range: 665..673,
|
|
||||||
kind: Quote2,
|
|
||||||
value: "foo 1 2",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
IpyEscapeCommand(
|
|
||||||
StmtIpyEscapeCommand {
|
|
||||||
range: 674..682,
|
|
||||||
kind: Quote,
|
|
||||||
value: "foo 1 2",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
For(
|
|
||||||
StmtFor {
|
|
||||||
range: 711..737,
|
|
||||||
is_async: false,
|
|
||||||
target: Name(
|
|
||||||
ExprName {
|
|
||||||
range: 715..716,
|
|
||||||
id: "a",
|
|
||||||
ctx: Store,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
iter: Call(
|
|
||||||
ExprCall {
|
|
||||||
range: 720..728,
|
|
||||||
func: Name(
|
|
||||||
ExprName {
|
|
||||||
range: 720..725,
|
|
||||||
id: "range",
|
|
||||||
ctx: Load,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
arguments: Arguments {
|
|
||||||
range: 725..728,
|
|
||||||
args: [
|
|
||||||
NumberLiteral(
|
|
||||||
ExprNumberLiteral {
|
|
||||||
range: 726..727,
|
|
||||||
value: Int(
|
|
||||||
5,
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
keywords: [],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
body: [
|
|
||||||
IpyEscapeCommand(
|
|
||||||
StmtIpyEscapeCommand {
|
|
||||||
range: 734..737,
|
|
||||||
kind: Shell,
|
|
||||||
value: "ls",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
orelse: [],
|
|
||||||
},
|
|
||||||
),
|
|
||||||
Assign(
|
|
||||||
StmtAssign {
|
|
||||||
range: 739..748,
|
|
||||||
targets: [
|
|
||||||
Name(
|
|
||||||
ExprName {
|
|
||||||
range: 739..741,
|
|
||||||
id: "p1",
|
|
||||||
ctx: Store,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
value: IpyEscapeCommand(
|
|
||||||
ExprIpyEscapeCommand {
|
|
||||||
range: 744..748,
|
|
||||||
kind: Shell,
|
|
||||||
value: "pwd",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
AnnAssign(
|
|
||||||
StmtAnnAssign {
|
|
||||||
range: 749..763,
|
|
||||||
target: Name(
|
|
||||||
ExprName {
|
|
||||||
range: 749..751,
|
|
||||||
id: "p2",
|
|
||||||
ctx: Store,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
annotation: Name(
|
|
||||||
ExprName {
|
|
||||||
range: 753..756,
|
|
||||||
id: "str",
|
|
||||||
ctx: Load,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
value: Some(
|
|
||||||
IpyEscapeCommand(
|
|
||||||
ExprIpyEscapeCommand {
|
|
||||||
range: 759..763,
|
|
||||||
kind: Shell,
|
|
||||||
value: "pwd",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
simple: true,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
Assign(
|
|
||||||
StmtAssign {
|
|
||||||
range: 764..784,
|
|
||||||
targets: [
|
|
||||||
Name(
|
|
||||||
ExprName {
|
|
||||||
range: 764..767,
|
|
||||||
id: "foo",
|
|
||||||
ctx: Store,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
value: IpyEscapeCommand(
|
|
||||||
ExprIpyEscapeCommand {
|
|
||||||
range: 770..784,
|
|
||||||
kind: Magic,
|
|
||||||
value: "foo bar",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
IpyEscapeCommand(
|
|
||||||
StmtIpyEscapeCommand {
|
|
||||||
range: 786..791,
|
|
||||||
kind: Magic,
|
|
||||||
value: " foo",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
Assign(
|
|
||||||
StmtAssign {
|
|
||||||
range: 792..813,
|
|
||||||
targets: [
|
|
||||||
Name(
|
|
||||||
ExprName {
|
|
||||||
range: 792..795,
|
|
||||||
id: "foo",
|
|
||||||
ctx: Store,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
value: IpyEscapeCommand(
|
|
||||||
ExprIpyEscapeCommand {
|
|
||||||
range: 798..813,
|
|
||||||
kind: Magic,
|
|
||||||
value: "foo # comment",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
IpyEscapeCommand(
|
|
||||||
StmtIpyEscapeCommand {
|
|
||||||
range: 838..842,
|
|
||||||
kind: Help,
|
|
||||||
value: "foo",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
IpyEscapeCommand(
|
|
||||||
StmtIpyEscapeCommand {
|
|
||||||
range: 843..852,
|
|
||||||
kind: Help2,
|
|
||||||
value: "foo.bar",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
IpyEscapeCommand(
|
|
||||||
StmtIpyEscapeCommand {
|
|
||||||
range: 853..865,
|
|
||||||
kind: Help,
|
|
||||||
value: "foo.bar.baz",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
IpyEscapeCommand(
|
|
||||||
StmtIpyEscapeCommand {
|
|
||||||
range: 866..874,
|
|
||||||
kind: Help2,
|
|
||||||
value: "foo[0]",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
IpyEscapeCommand(
|
|
||||||
StmtIpyEscapeCommand {
|
|
||||||
range: 875..885,
|
|
||||||
kind: Help,
|
|
||||||
value: "foo[0][1]",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
IpyEscapeCommand(
|
|
||||||
StmtIpyEscapeCommand {
|
|
||||||
range: 886..905,
|
|
||||||
kind: Help2,
|
|
||||||
value: "foo.bar[0].baz[1]",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
IpyEscapeCommand(
|
|
||||||
StmtIpyEscapeCommand {
|
|
||||||
range: 906..929,
|
|
||||||
kind: Help2,
|
|
||||||
value: "foo.bar[0].baz[2].egg",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/src/parser/tests.rs
|
|
||||||
assertion_line: 66
|
|
||||||
expression: suite
|
|
||||||
---
|
|
||||||
[
|
|
||||||
Assign(
|
|
||||||
StmtAssign {
|
|
||||||
range: 0..37,
|
|
||||||
targets: [
|
|
||||||
Name(
|
|
||||||
ExprName {
|
|
||||||
range: 0..1,
|
|
||||||
id: "x",
|
|
||||||
ctx: Store,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
value: StringLiteral(
|
|
||||||
ExprStringLiteral {
|
|
||||||
range: 4..37,
|
|
||||||
value: StringLiteralValue {
|
|
||||||
inner: Single(
|
|
||||||
StringLiteral {
|
|
||||||
range: 4..37,
|
|
||||||
value: "\u{8}another cool trick",
|
|
||||||
flags: StringLiteralFlags {
|
|
||||||
quote_style: Double,
|
|
||||||
prefix: Empty,
|
|
||||||
triple_quoted: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
@ -920,11 +920,7 @@ impl<'src, 'ast> Parser<'src, 'ast> {
|
||||||
self.add_error(ParseErrorType::UnexpectedIpythonEscapeCommand, range);
|
self.add_error(ParseErrorType::UnexpectedIpythonEscapeCommand, range);
|
||||||
}
|
}
|
||||||
|
|
||||||
ast::StmtIpyEscapeCommand {
|
ast::StmtIpyEscapeCommand { range, kind, value }
|
||||||
range,
|
|
||||||
kind,
|
|
||||||
value: self.alloc_str(&value),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parses an IPython help end escape command at the statement level.
|
/// Parses an IPython help end escape command at the statement level.
|
||||||
|
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/src/string.rs
|
|
||||||
assertion_line: 869
|
|
||||||
expression: suite
|
|
||||||
---
|
|
||||||
[
|
|
||||||
Assign(
|
|
||||||
StmtAssign {
|
|
||||||
range: 0..16,
|
|
||||||
targets: [
|
|
||||||
Name(
|
|
||||||
ExprName {
|
|
||||||
range: 0..4,
|
|
||||||
id: "bold",
|
|
||||||
ctx: Store,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
value: StringLiteral(
|
|
||||||
ExprStringLiteral {
|
|
||||||
range: 7..16,
|
|
||||||
value: StringLiteralValue {
|
|
||||||
inner: Single(
|
|
||||||
StringLiteral {
|
|
||||||
range: 7..16,
|
|
||||||
value: "\u{3}8[1m",
|
|
||||||
flags: StringLiteralFlags {
|
|
||||||
quote_style: Single,
|
|
||||||
prefix: Empty,
|
|
||||||
triple_quoted: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
@ -1,81 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/src/string.rs
|
|
||||||
assertion_line: 802
|
|
||||||
expression: suite
|
|
||||||
---
|
|
||||||
[
|
|
||||||
Expr(
|
|
||||||
StmtExpr {
|
|
||||||
range: 0..22,
|
|
||||||
value: FString(
|
|
||||||
ExprFString {
|
|
||||||
range: 0..22,
|
|
||||||
value: FStringValue {
|
|
||||||
inner: Single(
|
|
||||||
FString(
|
|
||||||
FString {
|
|
||||||
range: 0..22,
|
|
||||||
elements: [
|
|
||||||
Literal(
|
|
||||||
FStringLiteralElement {
|
|
||||||
range: 2..5,
|
|
||||||
value: "aaa",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
Expression(
|
|
||||||
FStringExpressionElement {
|
|
||||||
range: 5..10,
|
|
||||||
expression: Name(
|
|
||||||
ExprName {
|
|
||||||
range: 6..9,
|
|
||||||
id: "bbb",
|
|
||||||
ctx: Load,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
debug_text: None,
|
|
||||||
conversion: None,
|
|
||||||
format_spec: None,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
Literal(
|
|
||||||
FStringLiteralElement {
|
|
||||||
range: 10..13,
|
|
||||||
value: "ccc",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
Expression(
|
|
||||||
FStringExpressionElement {
|
|
||||||
range: 13..18,
|
|
||||||
expression: Name(
|
|
||||||
ExprName {
|
|
||||||
range: 14..17,
|
|
||||||
id: "ddd",
|
|
||||||
ctx: Load,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
debug_text: None,
|
|
||||||
conversion: None,
|
|
||||||
format_spec: None,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
Literal(
|
|
||||||
FStringLiteralElement {
|
|
||||||
range: 18..21,
|
|
||||||
value: "eee",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
flags: FStringFlags {
|
|
||||||
quote_style: Double,
|
|
||||||
prefix: Regular,
|
|
||||||
triple_quoted: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
@ -1,54 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/src/string.rs
|
|
||||||
assertion_line: 819
|
|
||||||
expression: suite
|
|
||||||
---
|
|
||||||
[
|
|
||||||
Expr(
|
|
||||||
StmtExpr {
|
|
||||||
range: 0..8,
|
|
||||||
value: FString(
|
|
||||||
ExprFString {
|
|
||||||
range: 0..8,
|
|
||||||
value: FStringValue {
|
|
||||||
inner: Single(
|
|
||||||
FString(
|
|
||||||
FString {
|
|
||||||
range: 0..8,
|
|
||||||
elements: [
|
|
||||||
Literal(
|
|
||||||
FStringLiteralElement {
|
|
||||||
range: 2..4,
|
|
||||||
value: "\\",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
Expression(
|
|
||||||
FStringExpressionElement {
|
|
||||||
range: 4..7,
|
|
||||||
expression: Name(
|
|
||||||
ExprName {
|
|
||||||
range: 5..6,
|
|
||||||
id: "x",
|
|
||||||
ctx: Load,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
debug_text: None,
|
|
||||||
conversion: None,
|
|
||||||
format_spec: None,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
flags: FStringFlags {
|
|
||||||
quote_style: Double,
|
|
||||||
prefix: Regular,
|
|
||||||
triple_quoted: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
@ -1,54 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/src/string.rs
|
|
||||||
assertion_line: 794
|
|
||||||
expression: suite
|
|
||||||
---
|
|
||||||
[
|
|
||||||
Expr(
|
|
||||||
StmtExpr {
|
|
||||||
range: 0..8,
|
|
||||||
value: FString(
|
|
||||||
ExprFString {
|
|
||||||
range: 0..8,
|
|
||||||
value: FStringValue {
|
|
||||||
inner: Single(
|
|
||||||
FString(
|
|
||||||
FString {
|
|
||||||
range: 0..8,
|
|
||||||
elements: [
|
|
||||||
Literal(
|
|
||||||
FStringLiteralElement {
|
|
||||||
range: 2..4,
|
|
||||||
value: "\n",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
Expression(
|
|
||||||
FStringExpressionElement {
|
|
||||||
range: 4..7,
|
|
||||||
expression: Name(
|
|
||||||
ExprName {
|
|
||||||
range: 5..6,
|
|
||||||
id: "x",
|
|
||||||
ctx: Load,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
debug_text: None,
|
|
||||||
conversion: None,
|
|
||||||
format_spec: None,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
flags: FStringFlags {
|
|
||||||
quote_style: Double,
|
|
||||||
prefix: Regular,
|
|
||||||
triple_quoted: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
@ -1,56 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/src/string.rs
|
|
||||||
assertion_line: 844
|
|
||||||
expression: suite
|
|
||||||
---
|
|
||||||
[
|
|
||||||
Expr(
|
|
||||||
StmtExpr {
|
|
||||||
range: 0..9,
|
|
||||||
value: FString(
|
|
||||||
ExprFString {
|
|
||||||
range: 0..9,
|
|
||||||
value: FStringValue {
|
|
||||||
inner: Single(
|
|
||||||
FString(
|
|
||||||
FString {
|
|
||||||
range: 0..9,
|
|
||||||
elements: [
|
|
||||||
Literal(
|
|
||||||
FStringLiteralElement {
|
|
||||||
range: 3..5,
|
|
||||||
value: "\\\n",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
Expression(
|
|
||||||
FStringExpressionElement {
|
|
||||||
range: 5..8,
|
|
||||||
expression: Name(
|
|
||||||
ExprName {
|
|
||||||
range: 6..7,
|
|
||||||
id: "x",
|
|
||||||
ctx: Load,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
debug_text: None,
|
|
||||||
conversion: None,
|
|
||||||
format_spec: None,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
flags: FStringFlags {
|
|
||||||
quote_style: Double,
|
|
||||||
prefix: Raw {
|
|
||||||
uppercase_r: false,
|
|
||||||
},
|
|
||||||
triple_quoted: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
@ -1,53 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/src/string.rs
|
|
||||||
assertion_line: 569
|
|
||||||
expression: suite
|
|
||||||
---
|
|
||||||
[
|
|
||||||
Expr(
|
|
||||||
StmtExpr {
|
|
||||||
range: 0..10,
|
|
||||||
value: FString(
|
|
||||||
ExprFString {
|
|
||||||
range: 0..10,
|
|
||||||
value: FStringValue {
|
|
||||||
inner: Single(
|
|
||||||
FString(
|
|
||||||
FString {
|
|
||||||
range: 0..10,
|
|
||||||
elements: [
|
|
||||||
Expression(
|
|
||||||
FStringExpressionElement {
|
|
||||||
range: 2..9,
|
|
||||||
expression: Name(
|
|
||||||
ExprName {
|
|
||||||
range: 3..7,
|
|
||||||
id: "user",
|
|
||||||
ctx: Load,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
debug_text: Some(
|
|
||||||
DebugText {
|
|
||||||
leading: "",
|
|
||||||
trailing: "=",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
conversion: None,
|
|
||||||
format_spec: None,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
flags: FStringFlags {
|
|
||||||
quote_style: Double,
|
|
||||||
prefix: Regular,
|
|
||||||
triple_quoted: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
@ -1,85 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/src/string.rs
|
|
||||||
assertion_line: 577
|
|
||||||
expression: suite
|
|
||||||
---
|
|
||||||
[
|
|
||||||
Expr(
|
|
||||||
StmtExpr {
|
|
||||||
range: 0..38,
|
|
||||||
value: FString(
|
|
||||||
ExprFString {
|
|
||||||
range: 0..38,
|
|
||||||
value: FStringValue {
|
|
||||||
inner: Single(
|
|
||||||
FString(
|
|
||||||
FString {
|
|
||||||
range: 0..38,
|
|
||||||
elements: [
|
|
||||||
Literal(
|
|
||||||
FStringLiteralElement {
|
|
||||||
range: 2..6,
|
|
||||||
value: "mix ",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
Expression(
|
|
||||||
FStringExpressionElement {
|
|
||||||
range: 6..13,
|
|
||||||
expression: Name(
|
|
||||||
ExprName {
|
|
||||||
range: 7..11,
|
|
||||||
id: "user",
|
|
||||||
ctx: Load,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
debug_text: Some(
|
|
||||||
DebugText {
|
|
||||||
leading: "",
|
|
||||||
trailing: "=",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
conversion: None,
|
|
||||||
format_spec: None,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
Literal(
|
|
||||||
FStringLiteralElement {
|
|
||||||
range: 13..28,
|
|
||||||
value: " with text and ",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
Expression(
|
|
||||||
FStringExpressionElement {
|
|
||||||
range: 28..37,
|
|
||||||
expression: Name(
|
|
||||||
ExprName {
|
|
||||||
range: 29..35,
|
|
||||||
id: "second",
|
|
||||||
ctx: Load,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
debug_text: Some(
|
|
||||||
DebugText {
|
|
||||||
leading: "",
|
|
||||||
trailing: "=",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
conversion: None,
|
|
||||||
format_spec: None,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
flags: FStringFlags {
|
|
||||||
quote_style: Double,
|
|
||||||
prefix: Regular,
|
|
||||||
triple_quoted: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
@ -1,65 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/src/string.rs
|
|
||||||
assertion_line: 585
|
|
||||||
expression: suite
|
|
||||||
---
|
|
||||||
[
|
|
||||||
Expr(
|
|
||||||
StmtExpr {
|
|
||||||
range: 0..14,
|
|
||||||
value: FString(
|
|
||||||
ExprFString {
|
|
||||||
range: 0..14,
|
|
||||||
value: FStringValue {
|
|
||||||
inner: Single(
|
|
||||||
FString(
|
|
||||||
FString {
|
|
||||||
range: 0..14,
|
|
||||||
elements: [
|
|
||||||
Expression(
|
|
||||||
FStringExpressionElement {
|
|
||||||
range: 2..13,
|
|
||||||
expression: Name(
|
|
||||||
ExprName {
|
|
||||||
range: 3..7,
|
|
||||||
id: "user",
|
|
||||||
ctx: Load,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
debug_text: Some(
|
|
||||||
DebugText {
|
|
||||||
leading: "",
|
|
||||||
trailing: "=",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
conversion: None,
|
|
||||||
format_spec: Some(
|
|
||||||
FStringFormatSpec {
|
|
||||||
range: 9..12,
|
|
||||||
elements: [
|
|
||||||
Literal(
|
|
||||||
FStringLiteralElement {
|
|
||||||
range: 9..12,
|
|
||||||
value: ">10",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
flags: FStringFlags {
|
|
||||||
quote_style: Double,
|
|
||||||
prefix: Regular,
|
|
||||||
triple_quoted: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
@ -1,54 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/src/string.rs
|
|
||||||
assertion_line: 811
|
|
||||||
expression: suite
|
|
||||||
---
|
|
||||||
[
|
|
||||||
Expr(
|
|
||||||
StmtExpr {
|
|
||||||
range: 0..11,
|
|
||||||
value: FString(
|
|
||||||
ExprFString {
|
|
||||||
range: 0..11,
|
|
||||||
value: FStringValue {
|
|
||||||
inner: Single(
|
|
||||||
FString(
|
|
||||||
FString {
|
|
||||||
range: 0..11,
|
|
||||||
elements: [
|
|
||||||
Literal(
|
|
||||||
FStringLiteralElement {
|
|
||||||
range: 4..5,
|
|
||||||
value: "\n",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
Expression(
|
|
||||||
FStringExpressionElement {
|
|
||||||
range: 5..8,
|
|
||||||
expression: Name(
|
|
||||||
ExprName {
|
|
||||||
range: 6..7,
|
|
||||||
id: "x",
|
|
||||||
ctx: Load,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
debug_text: None,
|
|
||||||
conversion: None,
|
|
||||||
format_spec: None,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
flags: FStringFlags {
|
|
||||||
quote_style: Double,
|
|
||||||
prefix: Regular,
|
|
||||||
triple_quoted: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
@ -1,69 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/src/string.rs
|
|
||||||
assertion_line: 537
|
|
||||||
expression: suite
|
|
||||||
---
|
|
||||||
[
|
|
||||||
Expr(
|
|
||||||
StmtExpr {
|
|
||||||
range: 0..18,
|
|
||||||
value: FString(
|
|
||||||
ExprFString {
|
|
||||||
range: 0..18,
|
|
||||||
value: FStringValue {
|
|
||||||
inner: Single(
|
|
||||||
FString(
|
|
||||||
FString {
|
|
||||||
range: 0..18,
|
|
||||||
elements: [
|
|
||||||
Expression(
|
|
||||||
FStringExpressionElement {
|
|
||||||
range: 2..5,
|
|
||||||
expression: Name(
|
|
||||||
ExprName {
|
|
||||||
range: 3..4,
|
|
||||||
id: "a",
|
|
||||||
ctx: Load,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
debug_text: None,
|
|
||||||
conversion: None,
|
|
||||||
format_spec: None,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
Expression(
|
|
||||||
FStringExpressionElement {
|
|
||||||
range: 5..10,
|
|
||||||
expression: Name(
|
|
||||||
ExprName {
|
|
||||||
range: 7..8,
|
|
||||||
id: "b",
|
|
||||||
ctx: Load,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
debug_text: None,
|
|
||||||
conversion: None,
|
|
||||||
format_spec: None,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
Literal(
|
|
||||||
FStringLiteralElement {
|
|
||||||
range: 10..17,
|
|
||||||
value: "{foo}",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
flags: FStringFlags {
|
|
||||||
quote_style: Double,
|
|
||||||
prefix: Regular,
|
|
||||||
triple_quoted: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
@ -1,94 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/src/string.rs
|
|
||||||
assertion_line: 860
|
|
||||||
expression: suite
|
|
||||||
---
|
|
||||||
[
|
|
||||||
Expr(
|
|
||||||
StmtExpr {
|
|
||||||
range: 0..16,
|
|
||||||
value: FString(
|
|
||||||
ExprFString {
|
|
||||||
range: 0..16,
|
|
||||||
value: FStringValue {
|
|
||||||
inner: Single(
|
|
||||||
FString(
|
|
||||||
FString {
|
|
||||||
range: 0..16,
|
|
||||||
elements: [
|
|
||||||
Expression(
|
|
||||||
FStringExpressionElement {
|
|
||||||
range: 2..15,
|
|
||||||
expression: Name(
|
|
||||||
ExprName {
|
|
||||||
range: 3..6,
|
|
||||||
id: "foo",
|
|
||||||
ctx: Load,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
debug_text: None,
|
|
||||||
conversion: None,
|
|
||||||
format_spec: Some(
|
|
||||||
FStringFormatSpec {
|
|
||||||
range: 7..14,
|
|
||||||
elements: [
|
|
||||||
Expression(
|
|
||||||
FStringExpressionElement {
|
|
||||||
range: 7..14,
|
|
||||||
expression: StringLiteral(
|
|
||||||
ExprStringLiteral {
|
|
||||||
range: 8..13,
|
|
||||||
value: StringLiteralValue {
|
|
||||||
inner: Concatenated(
|
|
||||||
ConcatenatedStringLiteral {
|
|
||||||
strings: [
|
|
||||||
StringLiteral {
|
|
||||||
range: 8..10,
|
|
||||||
value: "",
|
|
||||||
flags: StringLiteralFlags {
|
|
||||||
quote_style: Single,
|
|
||||||
prefix: Empty,
|
|
||||||
triple_quoted: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
StringLiteral {
|
|
||||||
range: 11..13,
|
|
||||||
value: "",
|
|
||||||
flags: StringLiteralFlags {
|
|
||||||
quote_style: Single,
|
|
||||||
prefix: Empty,
|
|
||||||
triple_quoted: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
value: "",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
debug_text: None,
|
|
||||||
conversion: None,
|
|
||||||
format_spec: None,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
flags: FStringFlags {
|
|
||||||
quote_style: Double,
|
|
||||||
prefix: Regular,
|
|
||||||
triple_quoted: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
@ -1,69 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/src/string.rs
|
|
||||||
assertion_line: 545
|
|
||||||
expression: suite
|
|
||||||
---
|
|
||||||
[
|
|
||||||
Expr(
|
|
||||||
StmtExpr {
|
|
||||||
range: 0..15,
|
|
||||||
value: FString(
|
|
||||||
ExprFString {
|
|
||||||
range: 0..15,
|
|
||||||
value: FStringValue {
|
|
||||||
inner: Single(
|
|
||||||
FString(
|
|
||||||
FString {
|
|
||||||
range: 0..15,
|
|
||||||
elements: [
|
|
||||||
Expression(
|
|
||||||
FStringExpressionElement {
|
|
||||||
range: 2..14,
|
|
||||||
expression: Name(
|
|
||||||
ExprName {
|
|
||||||
range: 3..6,
|
|
||||||
id: "foo",
|
|
||||||
ctx: Load,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
debug_text: None,
|
|
||||||
conversion: None,
|
|
||||||
format_spec: Some(
|
|
||||||
FStringFormatSpec {
|
|
||||||
range: 7..13,
|
|
||||||
elements: [
|
|
||||||
Expression(
|
|
||||||
FStringExpressionElement {
|
|
||||||
range: 7..13,
|
|
||||||
expression: Name(
|
|
||||||
ExprName {
|
|
||||||
range: 8..12,
|
|
||||||
id: "spec",
|
|
||||||
ctx: Load,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
debug_text: None,
|
|
||||||
conversion: None,
|
|
||||||
format_spec: None,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
flags: FStringFlags {
|
|
||||||
quote_style: Double,
|
|
||||||
prefix: Regular,
|
|
||||||
triple_quoted: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
@ -1,80 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/src/string.rs
|
|
||||||
assertion_line: 852
|
|
||||||
expression: suite
|
|
||||||
---
|
|
||||||
[
|
|
||||||
Expr(
|
|
||||||
StmtExpr {
|
|
||||||
range: 0..13,
|
|
||||||
value: FString(
|
|
||||||
ExprFString {
|
|
||||||
range: 0..13,
|
|
||||||
value: FStringValue {
|
|
||||||
inner: Single(
|
|
||||||
FString(
|
|
||||||
FString {
|
|
||||||
range: 0..13,
|
|
||||||
elements: [
|
|
||||||
Expression(
|
|
||||||
FStringExpressionElement {
|
|
||||||
range: 2..12,
|
|
||||||
expression: Name(
|
|
||||||
ExprName {
|
|
||||||
range: 3..6,
|
|
||||||
id: "foo",
|
|
||||||
ctx: Load,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
debug_text: None,
|
|
||||||
conversion: None,
|
|
||||||
format_spec: Some(
|
|
||||||
FStringFormatSpec {
|
|
||||||
range: 7..11,
|
|
||||||
elements: [
|
|
||||||
Expression(
|
|
||||||
FStringExpressionElement {
|
|
||||||
range: 7..11,
|
|
||||||
expression: StringLiteral(
|
|
||||||
ExprStringLiteral {
|
|
||||||
range: 8..10,
|
|
||||||
value: StringLiteralValue {
|
|
||||||
inner: Single(
|
|
||||||
StringLiteral {
|
|
||||||
range: 8..10,
|
|
||||||
value: "",
|
|
||||||
flags: StringLiteralFlags {
|
|
||||||
quote_style: Single,
|
|
||||||
prefix: Empty,
|
|
||||||
triple_quoted: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
debug_text: None,
|
|
||||||
conversion: None,
|
|
||||||
format_spec: None,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
flags: FStringFlags {
|
|
||||||
quote_style: Double,
|
|
||||||
prefix: Regular,
|
|
||||||
triple_quoted: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
@ -1,60 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/src/string.rs
|
|
||||||
assertion_line: 553
|
|
||||||
expression: suite
|
|
||||||
---
|
|
||||||
[
|
|
||||||
Expr(
|
|
||||||
StmtExpr {
|
|
||||||
range: 0..13,
|
|
||||||
value: FString(
|
|
||||||
ExprFString {
|
|
||||||
range: 0..13,
|
|
||||||
value: FStringValue {
|
|
||||||
inner: Single(
|
|
||||||
FString(
|
|
||||||
FString {
|
|
||||||
range: 0..13,
|
|
||||||
elements: [
|
|
||||||
Expression(
|
|
||||||
FStringExpressionElement {
|
|
||||||
range: 2..12,
|
|
||||||
expression: Name(
|
|
||||||
ExprName {
|
|
||||||
range: 3..6,
|
|
||||||
id: "foo",
|
|
||||||
ctx: Load,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
debug_text: None,
|
|
||||||
conversion: None,
|
|
||||||
format_spec: Some(
|
|
||||||
FStringFormatSpec {
|
|
||||||
range: 7..11,
|
|
||||||
elements: [
|
|
||||||
Literal(
|
|
||||||
FStringLiteralElement {
|
|
||||||
range: 7..11,
|
|
||||||
value: "spec",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
flags: FStringFlags {
|
|
||||||
quote_style: Double,
|
|
||||||
prefix: Regular,
|
|
||||||
triple_quoted: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
@ -1,53 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/src/string.rs
|
|
||||||
assertion_line: 639
|
|
||||||
expression: suite
|
|
||||||
---
|
|
||||||
[
|
|
||||||
Expr(
|
|
||||||
StmtExpr {
|
|
||||||
range: 0..10,
|
|
||||||
value: FString(
|
|
||||||
ExprFString {
|
|
||||||
range: 0..10,
|
|
||||||
value: FStringValue {
|
|
||||||
inner: Single(
|
|
||||||
FString(
|
|
||||||
FString {
|
|
||||||
range: 0..10,
|
|
||||||
elements: [
|
|
||||||
Expression(
|
|
||||||
FStringExpressionElement {
|
|
||||||
range: 2..9,
|
|
||||||
expression: Name(
|
|
||||||
ExprName {
|
|
||||||
range: 3..4,
|
|
||||||
id: "x",
|
|
||||||
ctx: Load,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
debug_text: Some(
|
|
||||||
DebugText {
|
|
||||||
leading: "",
|
|
||||||
trailing: " =",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
conversion: None,
|
|
||||||
format_spec: None,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
flags: FStringFlags {
|
|
||||||
quote_style: Double,
|
|
||||||
prefix: Regular,
|
|
||||||
triple_quoted: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
@ -1,53 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/src/string.rs
|
|
||||||
assertion_line: 647
|
|
||||||
expression: suite
|
|
||||||
---
|
|
||||||
[
|
|
||||||
Expr(
|
|
||||||
StmtExpr {
|
|
||||||
range: 0..10,
|
|
||||||
value: FString(
|
|
||||||
ExprFString {
|
|
||||||
range: 0..10,
|
|
||||||
value: FStringValue {
|
|
||||||
inner: Single(
|
|
||||||
FString(
|
|
||||||
FString {
|
|
||||||
range: 0..10,
|
|
||||||
elements: [
|
|
||||||
Expression(
|
|
||||||
FStringExpressionElement {
|
|
||||||
range: 2..9,
|
|
||||||
expression: Name(
|
|
||||||
ExprName {
|
|
||||||
range: 3..4,
|
|
||||||
id: "x",
|
|
||||||
ctx: Load,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
debug_text: Some(
|
|
||||||
DebugText {
|
|
||||||
leading: "",
|
|
||||||
trailing: "= ",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
conversion: None,
|
|
||||||
format_spec: None,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
flags: FStringFlags {
|
|
||||||
quote_style: Double,
|
|
||||||
prefix: Regular,
|
|
||||||
triple_quoted: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
@ -1,50 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/src/string.rs
|
|
||||||
assertion_line: 827
|
|
||||||
expression: suite
|
|
||||||
---
|
|
||||||
[
|
|
||||||
Expr(
|
|
||||||
StmtExpr {
|
|
||||||
range: 0..7,
|
|
||||||
value: FString(
|
|
||||||
ExprFString {
|
|
||||||
range: 0..7,
|
|
||||||
value: FStringValue {
|
|
||||||
inner: Single(
|
|
||||||
FString(
|
|
||||||
FString {
|
|
||||||
range: 0..7,
|
|
||||||
elements: [
|
|
||||||
Expression(
|
|
||||||
FStringExpressionElement {
|
|
||||||
range: 3..6,
|
|
||||||
expression: Name(
|
|
||||||
ExprName {
|
|
||||||
range: 4..5,
|
|
||||||
id: "x",
|
|
||||||
ctx: Load,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
debug_text: None,
|
|
||||||
conversion: None,
|
|
||||||
format_spec: None,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
flags: FStringFlags {
|
|
||||||
quote_style: Double,
|
|
||||||
prefix: Raw {
|
|
||||||
uppercase_r: false,
|
|
||||||
},
|
|
||||||
triple_quoted: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
@ -1,50 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/src/string.rs
|
|
||||||
assertion_line: 835
|
|
||||||
expression: suite
|
|
||||||
---
|
|
||||||
[
|
|
||||||
Expr(
|
|
||||||
StmtExpr {
|
|
||||||
range: 0..11,
|
|
||||||
value: FString(
|
|
||||||
ExprFString {
|
|
||||||
range: 0..11,
|
|
||||||
value: FStringValue {
|
|
||||||
inner: Single(
|
|
||||||
FString(
|
|
||||||
FString {
|
|
||||||
range: 0..11,
|
|
||||||
elements: [
|
|
||||||
Expression(
|
|
||||||
FStringExpressionElement {
|
|
||||||
range: 5..8,
|
|
||||||
expression: Name(
|
|
||||||
ExprName {
|
|
||||||
range: 6..7,
|
|
||||||
id: "x",
|
|
||||||
ctx: Load,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
debug_text: None,
|
|
||||||
conversion: None,
|
|
||||||
format_spec: None,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
flags: FStringFlags {
|
|
||||||
quote_style: Double,
|
|
||||||
prefix: Raw {
|
|
||||||
uppercase_r: false,
|
|
||||||
},
|
|
||||||
triple_quoted: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
@ -9,7 +9,6 @@ use std::fmt;
|
||||||
|
|
||||||
use bitflags::bitflags;
|
use bitflags::bitflags;
|
||||||
|
|
||||||
use ruff_python_ast::name::Name;
|
|
||||||
use ruff_python_ast::str::Quote;
|
use ruff_python_ast::str::Quote;
|
||||||
use ruff_python_ast::str_prefix::{
|
use ruff_python_ast::str_prefix::{
|
||||||
AnyStringPrefix, ByteStringPrefix, FStringPrefix, StringLiteralPrefix,
|
AnyStringPrefix, ByteStringPrefix, FStringPrefix, StringLiteralPrefix,
|
||||||
|
|
@ -774,16 +773,16 @@ impl TokenFlags {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Clone, Debug, Default)]
|
||||||
pub(crate) enum TokenValue {
|
pub(crate) enum TokenValue<'ast> {
|
||||||
#[default]
|
#[default]
|
||||||
None,
|
None,
|
||||||
/// Token value for a name, commonly known as an identifier.
|
/// Token value for a name, commonly known as an identifier.
|
||||||
///
|
///
|
||||||
/// Unicode names are NFKC-normalized by the lexer,
|
/// Unicode names are NFKC-normalized by the lexer,
|
||||||
/// matching [the behaviour of Python's lexer](https://docs.python.org/3/reference/lexical_analysis.html#identifiers)
|
/// matching [the behaviour of Python's lexer](https://docs.python.org/3/reference/lexical_analysis.html#identifiers)
|
||||||
Name(Name),
|
Name(&'ast str),
|
||||||
/// Token value for an integer.
|
/// Token value for an integer.
|
||||||
Int(Int),
|
Int(Int<'ast>),
|
||||||
/// Token value for a floating point number.
|
/// Token value for a floating point number.
|
||||||
Float(f64),
|
Float(f64),
|
||||||
/// Token value for a complex number.
|
/// Token value for a complex number.
|
||||||
|
|
@ -794,15 +793,15 @@ pub(crate) enum TokenValue {
|
||||||
imag: f64,
|
imag: f64,
|
||||||
},
|
},
|
||||||
/// Token value for a string.
|
/// Token value for a string.
|
||||||
String(Box<str>),
|
String(&'ast str),
|
||||||
/// Token value that includes the portion of text inside the f-string that's not
|
/// Token value that includes the portion of text inside the f-string that's not
|
||||||
/// part of the expression part and isn't an opening or closing brace.
|
/// part of the expression part and isn't an opening or closing brace.
|
||||||
FStringMiddle(Box<str>),
|
FStringMiddle(&'ast str),
|
||||||
/// Token value for IPython escape commands. These are recognized by the lexer
|
/// Token value for IPython escape commands. These are recognized by the lexer
|
||||||
/// only when the mode is [`Mode::Ipython`].
|
/// only when the mode is [`Mode::Ipython`].
|
||||||
IpyEscapeCommand {
|
IpyEscapeCommand {
|
||||||
/// The magic command value.
|
/// The magic command value.
|
||||||
value: Box<str>,
|
value: &'ast str,
|
||||||
/// The kind of magic command.
|
/// The kind of magic command.
|
||||||
kind: IpyEscapeKind,
|
kind: IpyEscapeKind,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
use ruff_allocator::Allocator;
|
||||||
use ruff_text_size::{Ranged, TextRange, TextSize};
|
use ruff_text_size::{Ranged, TextRange, TextSize};
|
||||||
|
|
||||||
use crate::error::LexicalError;
|
use crate::error::LexicalError;
|
||||||
|
|
@ -7,9 +8,9 @@ use crate::Mode;
|
||||||
|
|
||||||
/// Token source for the parser that skips over any trivia tokens.
|
/// Token source for the parser that skips over any trivia tokens.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct TokenSource<'src> {
|
pub(crate) struct TokenSource<'src, 'ast> {
|
||||||
/// The underlying source for the tokens.
|
/// The underlying source for the tokens.
|
||||||
lexer: Lexer<'src>,
|
lexer: Lexer<'src, 'ast>,
|
||||||
|
|
||||||
/// A vector containing all the tokens emitted by the lexer. This is returned when the parser
|
/// A vector containing all the tokens emitted by the lexer. This is returned when the parser
|
||||||
/// is finished consuming all the tokens. Note that unlike the emitted tokens, this vector
|
/// is finished consuming all the tokens. Note that unlike the emitted tokens, this vector
|
||||||
|
|
@ -17,9 +18,9 @@ pub(crate) struct TokenSource<'src> {
|
||||||
tokens: Vec<Token>,
|
tokens: Vec<Token>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'src> TokenSource<'src> {
|
impl<'src, 'ast> TokenSource<'src, 'ast> {
|
||||||
/// Create a new token source for the given lexer.
|
/// Create a new token source for the given lexer.
|
||||||
pub(crate) fn new(lexer: Lexer<'src>) -> Self {
|
pub(crate) fn new(lexer: Lexer<'src, 'ast>) -> Self {
|
||||||
// TODO(dhruvmanila): Use `allocate_tokens_vec`
|
// TODO(dhruvmanila): Use `allocate_tokens_vec`
|
||||||
TokenSource {
|
TokenSource {
|
||||||
lexer,
|
lexer,
|
||||||
|
|
@ -28,8 +29,13 @@ impl<'src> TokenSource<'src> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new token source from the given source code which starts at the given offset.
|
/// Create a new token source from the given source code which starts at the given offset.
|
||||||
pub(crate) fn from_source(source: &'src str, mode: Mode, start_offset: TextSize) -> Self {
|
pub(crate) fn from_source(
|
||||||
let lexer = Lexer::new(source, mode, start_offset);
|
source: &'src str,
|
||||||
|
mode: Mode,
|
||||||
|
start_offset: TextSize,
|
||||||
|
allocator: &'ast Allocator,
|
||||||
|
) -> Self {
|
||||||
|
let lexer = Lexer::new(source, mode, start_offset, allocator);
|
||||||
let mut source = TokenSource::new(lexer);
|
let mut source = TokenSource::new(lexer);
|
||||||
|
|
||||||
// Initialize the token source so that the current token is set correctly.
|
// Initialize the token source so that the current token is set correctly.
|
||||||
|
|
@ -56,7 +62,7 @@ impl<'src> TokenSource<'src> {
|
||||||
/// for more info.
|
/// for more info.
|
||||||
///
|
///
|
||||||
/// [`take_value`]: Lexer::take_value
|
/// [`take_value`]: Lexer::take_value
|
||||||
pub(crate) fn take_value(&mut self) -> TokenValue {
|
pub(crate) fn take_value(&mut self) -> TokenValue<'ast> {
|
||||||
self.lexer.take_value()
|
self.lexer.take_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -148,7 +154,7 @@ impl<'src> TokenSource<'src> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a checkpoint to which the token source can later return to using [`Self::rewind`].
|
/// Creates a checkpoint to which the token source can later return to using [`Self::rewind`].
|
||||||
pub(crate) fn checkpoint(&self) -> TokenSourceCheckpoint {
|
pub(crate) fn checkpoint(&self) -> TokenSourceCheckpoint<'ast> {
|
||||||
TokenSourceCheckpoint {
|
TokenSourceCheckpoint {
|
||||||
lexer_checkpoint: self.lexer.checkpoint(),
|
lexer_checkpoint: self.lexer.checkpoint(),
|
||||||
tokens_position: self.tokens.len(),
|
tokens_position: self.tokens.len(),
|
||||||
|
|
@ -156,7 +162,7 @@ impl<'src> TokenSource<'src> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Restore the token source to the given checkpoint.
|
/// Restore the token source to the given checkpoint.
|
||||||
pub(crate) fn rewind(&mut self, checkpoint: TokenSourceCheckpoint) {
|
pub(crate) fn rewind(&mut self, checkpoint: TokenSourceCheckpoint<'ast>) {
|
||||||
let TokenSourceCheckpoint {
|
let TokenSourceCheckpoint {
|
||||||
lexer_checkpoint,
|
lexer_checkpoint,
|
||||||
tokens_position,
|
tokens_position,
|
||||||
|
|
@ -186,8 +192,8 @@ impl<'src> TokenSource<'src> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct TokenSourceCheckpoint {
|
pub(crate) struct TokenSourceCheckpoint<'ast> {
|
||||||
lexer_checkpoint: LexerCheckpoint,
|
lexer_checkpoint: LexerCheckpoint<'ast>,
|
||||||
tokens_position: usize,
|
tokens_position: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,201 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,509 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,223 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,111 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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..7,
|
|
||||||
target: Name(
|
|
||||||
ExprName {
|
|
||||||
range: 0..1,
|
|
||||||
id: "a",
|
|
||||||
ctx: Store,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
annotation: Name(
|
|
||||||
ExprName {
|
|
||||||
range: 3..7,
|
|
||||||
id: "type",
|
|
||||||
ctx: Load,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
value: None,
|
|
||||||
simple: true,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
Assign(
|
|
||||||
StmtAssign {
|
|
||||||
range: 8..15,
|
|
||||||
targets: [
|
|
||||||
Name(
|
|
||||||
ExprName {
|
|
||||||
range: 8..9,
|
|
||||||
id: "X",
|
|
||||||
ctx: Store,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
value: Name(
|
|
||||||
ExprName {
|
|
||||||
range: 12..15,
|
|
||||||
id: "int",
|
|
||||||
ctx: Load,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
Expr(
|
|
||||||
StmtExpr {
|
|
||||||
range: 16..28,
|
|
||||||
value: Lambda(
|
|
||||||
ExprLambda {
|
|
||||||
range: 16..28,
|
|
||||||
parameters: None,
|
|
||||||
body: Name(
|
|
||||||
ExprName {
|
|
||||||
range: 24..28,
|
|
||||||
id: "type",
|
|
||||||
ctx: Load,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
Assign(
|
|
||||||
StmtAssign {
|
|
||||||
range: 29..36,
|
|
||||||
targets: [
|
|
||||||
Name(
|
|
||||||
ExprName {
|
|
||||||
range: 29..30,
|
|
||||||
id: "X",
|
|
||||||
ctx: Store,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
value: Name(
|
|
||||||
ExprName {
|
|
||||||
range: 33..36,
|
|
||||||
id: "int",
|
|
||||||
ctx: Load,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
)
|
|
||||||
```
|
|
||||||
## Errors
|
|
||||||
|
|
||||||
|
|
|
||||||
1 | a: type X = int
|
|
||||||
| ^ Syntax Error: Simple statements must be separated by newlines or semicolons
|
|
||||||
2 | lambda: type X = int
|
|
||||||
|
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
1 | a: type X = int
|
|
||||||
2 | lambda: type X = int
|
|
||||||
| ^ Syntax Error: Simple statements must be separated by newlines or semicolons
|
|
||||||
|
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,161 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,149 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,259 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,257 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,146 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,203 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,203 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
input_file: crates/ruff_python_parser/resources/inline/err/async_unexpected_token.py
|
|
||||||
---
|
|
||||||
## AST
|
|
||||||
|
|
||||||
```
|
|
||||||
Module(
|
|
||||||
ModModule {
|
|
||||||
range: 0..116,
|
|
||||||
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,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
),
|
|
||||||
Match(
|
|
||||||
StmtMatch {
|
|
||||||
range: 88..115,
|
|
||||||
subject: Name(
|
|
||||||
ExprName {
|
|
||||||
range: 94..98,
|
|
||||||
id: "test",
|
|
||||||
ctx: Load,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
cases: [
|
|
||||||
MatchCase {
|
|
||||||
range: 104..115,
|
|
||||||
pattern: MatchAs(
|
|
||||||
PatternMatchAs {
|
|
||||||
range: 109..110,
|
|
||||||
pattern: None,
|
|
||||||
name: None,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
guard: None,
|
|
||||||
body: [
|
|
||||||
Expr(
|
|
||||||
StmtExpr {
|
|
||||||
range: 112..115,
|
|
||||||
value: EllipsisLiteral(
|
|
||||||
ExprEllipsisLiteral {
|
|
||||||
range: 112..115,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
)
|
|
||||||
```
|
|
||||||
## 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 | async match test:
|
|
||||||
|
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
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 | async match test:
|
|
||||||
6 | case _: ...
|
|
||||||
|
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
3 | async x = 1
|
|
||||||
4 | async async def foo(): ...
|
|
||||||
5 | async match test:
|
|
||||||
| ^^^^^ Syntax Error: Expected 'def', 'with' or 'for' to follow 'async', found 'match'
|
|
||||||
6 | case _: ...
|
|
||||||
|
|
|
||||||
|
|
@ -1,233 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,252 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,137 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,85 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
input_file: crates/ruff_python_parser/resources/inline/err/case_expect_indented_block.py
|
|
||||||
---
|
|
||||||
## AST
|
|
||||||
|
|
||||||
```
|
|
||||||
Module(
|
|
||||||
ModModule {
|
|
||||||
range: 0..43,
|
|
||||||
body: [
|
|
||||||
Match(
|
|
||||||
StmtMatch {
|
|
||||||
range: 0..42,
|
|
||||||
subject: Name(
|
|
||||||
ExprName {
|
|
||||||
range: 6..13,
|
|
||||||
id: "subject",
|
|
||||||
ctx: Load,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
cases: [
|
|
||||||
MatchCase {
|
|
||||||
range: 19..26,
|
|
||||||
pattern: MatchValue(
|
|
||||||
PatternMatchValue {
|
|
||||||
range: 24..25,
|
|
||||||
value: NumberLiteral(
|
|
||||||
ExprNumberLiteral {
|
|
||||||
range: 24..25,
|
|
||||||
value: Int(
|
|
||||||
1,
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
guard: None,
|
|
||||||
body: [],
|
|
||||||
},
|
|
||||||
MatchCase {
|
|
||||||
range: 31..42,
|
|
||||||
pattern: MatchValue(
|
|
||||||
PatternMatchValue {
|
|
||||||
range: 36..37,
|
|
||||||
value: NumberLiteral(
|
|
||||||
ExprNumberLiteral {
|
|
||||||
range: 36..37,
|
|
||||||
value: Int(
|
|
||||||
2,
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
guard: None,
|
|
||||||
body: [
|
|
||||||
Expr(
|
|
||||||
StmtExpr {
|
|
||||||
range: 39..42,
|
|
||||||
value: EllipsisLiteral(
|
|
||||||
ExprEllipsisLiteral {
|
|
||||||
range: 39..42,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
)
|
|
||||||
```
|
|
||||||
## Errors
|
|
||||||
|
|
||||||
|
|
|
||||||
1 | match subject:
|
|
||||||
2 | case 1:
|
|
||||||
3 | case 2: ...
|
|
||||||
| ^^^^ Syntax Error: Expected an indented block after `case` block
|
|
||||||
|
|
|
||||||
|
|
@ -1,86 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,141 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,113 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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..33,
|
|
||||||
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,
|
|
||||||
default: None,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
TypeVarTuple(
|
|
||||||
TypeParamTypeVarTuple {
|
|
||||||
range: 14..17,
|
|
||||||
name: Identifier {
|
|
||||||
id: "T2",
|
|
||||||
range: 15..17,
|
|
||||||
},
|
|
||||||
default: None,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
),
|
|
||||||
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,71 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
input_file: crates/ruff_python_parser/resources/inline/err/comma_separated_missing_comma.py
|
|
||||||
---
|
|
||||||
## AST
|
|
||||||
|
|
||||||
```
|
|
||||||
Module(
|
|
||||||
ModModule {
|
|
||||||
range: 0..15,
|
|
||||||
body: [
|
|
||||||
Expr(
|
|
||||||
StmtExpr {
|
|
||||||
range: 0..14,
|
|
||||||
value: Call(
|
|
||||||
ExprCall {
|
|
||||||
range: 0..14,
|
|
||||||
func: Name(
|
|
||||||
ExprName {
|
|
||||||
range: 0..4,
|
|
||||||
id: "call",
|
|
||||||
ctx: Load,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
arguments: Arguments {
|
|
||||||
range: 4..14,
|
|
||||||
args: [
|
|
||||||
NumberLiteral(
|
|
||||||
ExprNumberLiteral {
|
|
||||||
range: 12..13,
|
|
||||||
value: Int(
|
|
||||||
1,
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
keywords: [
|
|
||||||
Keyword {
|
|
||||||
range: 5..8,
|
|
||||||
arg: None,
|
|
||||||
value: Name(
|
|
||||||
ExprName {
|
|
||||||
range: 7..8,
|
|
||||||
id: "x",
|
|
||||||
ctx: Load,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
)
|
|
||||||
```
|
|
||||||
## Errors
|
|
||||||
|
|
||||||
|
|
|
||||||
1 | call(**x := 1)
|
|
||||||
| ^^ Syntax Error: Expected ',', found ':='
|
|
||||||
|
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
1 | call(**x := 1)
|
|
||||||
| ^ Syntax Error: Positional argument cannot follow keyword argument unpacking
|
|
||||||
|
|
|
||||||
|
|
@ -1,53 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
input_file: crates/ruff_python_parser/resources/inline/err/comma_separated_missing_first_element.py
|
|
||||||
---
|
|
||||||
## AST
|
|
||||||
|
|
||||||
```
|
|
||||||
Module(
|
|
||||||
ModModule {
|
|
||||||
range: 0..10,
|
|
||||||
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: [
|
|
||||||
NumberLiteral(
|
|
||||||
ExprNumberLiteral {
|
|
||||||
range: 7..8,
|
|
||||||
value: Int(
|
|
||||||
1,
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
keywords: [],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
)
|
|
||||||
```
|
|
||||||
## Errors
|
|
||||||
|
|
||||||
|
|
|
||||||
1 | call(= 1)
|
|
||||||
| ^ Syntax Error: Expected an expression or a ')'
|
|
||||||
|
|
|
||||||
|
|
@ -1,81 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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: Name(
|
|
||||||
ExprName {
|
|
||||||
range: 1..6,
|
|
||||||
id: "async",
|
|
||||||
ctx: Load,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
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 identifier, but found a keyword 'async' that cannot be used here
|
|
||||||
2 | (x async x in iter)
|
|
||||||
|
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
1 | (async)
|
|
||||||
2 | (x async x in iter)
|
|
||||||
| ^ Syntax Error: Expected 'for', found name
|
|
||||||
|
|
|
||||||
|
|
@ -1,176 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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(): ...
|
|
||||||
|
|
|
||||||
|
|
@ -1,190 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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(): ...
|
|
||||||
|
|
|
||||||
|
|
@ -1,163 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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'
|
|
||||||
|
|
|
||||||
|
|
@ -1,86 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,125 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,89 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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: Simple statements must be separated by newlines or semicolons
|
|
||||||
|
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
1 | import a..b
|
|
||||||
2 | import a...b
|
|
||||||
| ^ Syntax Error: Simple statements must be separated by newlines or semicolons
|
|
||||||
|
|
|
||||||
|
|
@ -1,126 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,96 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,156 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,251 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,222 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,136 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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"
|
|
||||||
|
|
|
||||||
|
|
@ -1,200 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,230 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,305 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,59 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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 ')'
|
|
||||||
|
|
|
||||||
|
|
@ -1,59 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,167 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,187 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,75 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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(
|
|
||||||
| ^ Syntax Error: Expected ')', found newline
|
|
||||||
2 |
|
|
||||||
3 | def foo():
|
|
||||||
4 | pass
|
|
||||||
|
|
|
||||||
|
|
@ -1,83 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
| ^ Syntax Error: Expected ')', found newline
|
|
||||||
2 |
|
|
||||||
3 | def foo():
|
|
||||||
4 | pass
|
|
||||||
|
|
|
||||||
|
|
@ -1,83 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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,
|
|
||||||
| ^ Syntax Error: Expected ')', found newline
|
|
||||||
2 |
|
|
||||||
3 | def foo():
|
|
||||||
4 | pass
|
|
||||||
|
|
|
||||||
|
|
@ -1,147 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,154 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,89 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,67 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,71 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,328 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,117 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,63 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,77 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,105 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,150 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,123 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,92 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,121 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,78 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,108 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,96 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,169 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,125 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,63 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
||||||
assertion_line: 122
|
|
||||||
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
|
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue