Skip to content

Commit dcffd1d

Browse files
committed
Python: Add AST classes for walrus operator.
Happily, these were already present in the `dbscheme`.
1 parent b0fecbc commit dcffd1d

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

python/ql/src/semmle/python/AstGenerated.qll

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,26 @@ library class Assign_ extends @py_Assign, Stmt {
9393

9494
}
9595

96+
library class AssignExpr_ extends @py_AssignExpr, Expr {
97+
98+
99+
/** Gets the value of this assignment expression. */
100+
Expr getValue() {
101+
py_exprs(result, _, this, 2)
102+
}
103+
104+
105+
/** Gets the target of this assignment expression. */
106+
Expr getTarget() {
107+
py_exprs(result, _, this, 3)
108+
}
109+
110+
override string toString() {
111+
result = "AssignExpr"
112+
}
113+
114+
}
115+
96116
library class Attribute_ extends @py_Attribute, Expr {
97117

98118

python/ql/src/semmle/python/Exprs.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,14 @@ class Expr extends Expr_, AstNode {
128128

129129
}
130130

131+
/** An assignment expression, such as `x := y` */
132+
class AssignExpr extends AssignExpr_ {
133+
override Expr getASubExpression() {
134+
result = this.getValue() or
135+
result = this.getTarget()
136+
}
137+
}
138+
131139
/** An attribute expression, such as `value.attr` */
132140
class Attribute extends Attribute_ {
133141

0 commit comments

Comments
 (0)