pub enum PyExpr {
Show 19 variants
Literal(PyLiteral),
Name(String),
BinOp {
left: Box<PyExpr>,
op: BinOp,
right: Box<PyExpr>,
},
UnaryOp {
op: UnaryOp,
operand: Box<PyExpr>,
},
Call {
func: Box<PyExpr>,
args: Vec<PyExpr>,
kwargs: HashMap<String, PyExpr>,
},
Attribute {
value: Box<PyExpr>,
attr: String,
},
Subscript {
value: Box<PyExpr>,
index: Box<PyExpr>,
},
Slice {
value: Box<PyExpr>,
lower: Option<Box<PyExpr>>,
upper: Option<Box<PyExpr>>,
step: Option<Box<PyExpr>>,
},
List(Vec<PyExpr>),
Tuple(Vec<PyExpr>),
Dict {
keys: Vec<PyExpr>,
values: Vec<PyExpr>,
},
Set(Vec<PyExpr>),
ListComp {
element: Box<PyExpr>,
generators: Vec<Comprehension>,
},
IfExp {
test: Box<PyExpr>,
body: Box<PyExpr>,
orelse: Box<PyExpr>,
},
Lambda {
args: Vec<String>,
body: Box<PyExpr>,
},
Compare {
left: Box<PyExpr>,
op: CmpOp,
right: Box<PyExpr>,
},
BoolOp {
op: BoolOp,
left: Box<PyExpr>,
right: Box<PyExpr>,
},
Await(Box<PyExpr>),
Yield(Option<Box<PyExpr>>),
}Expand description
Python expression types
Variants§
Literal(PyLiteral)
Literal value
Name(String)
Variable name
BinOp
Binary operation: a + b, x * y
UnaryOp
Unary operation: -x, not y
Call
Function call: func(args)
Attribute
Attribute access: obj.attr
Subscript
Subscript: list[0], dict[“key”]
Slice
Slice: list[1:3], list[:5], list[2:], list[1:10:2]
Fields
List(Vec<PyExpr>)
List literal: [1, 2, 3]
Tuple(Vec<PyExpr>)
Tuple literal: (1, 2, 3)
Dict
Dict literal: {“a”: 1, “b”: 2}
Set(Vec<PyExpr>)
Set literal: {1, 2, 3}
ListComp
List comprehension: [x*2 for x in range(10)]
IfExp
Conditional expression: x if condition else y
Lambda
Lambda: lambda x: x + 1
Compare
Comparison: x == y, a < b
BoolOp
Boolean operation: and, or
Await(Box<PyExpr>)
Await expression: await expr
Yield(Option<Box<PyExpr>>)
Yield expression: yield expr
Trait Implementations§
Source§impl<'de> Deserialize<'de> for PyExpr
impl<'de> Deserialize<'de> for PyExpr
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for PyExpr
Auto Trait Implementations§
impl Freeze for PyExpr
impl RefUnwindSafe for PyExpr
impl Send for PyExpr
impl Sync for PyExpr
impl Unpin for PyExpr
impl UnwindSafe for PyExpr
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more