Skip to content

Commit 72d74ae

Browse files
CopilotCopilot
authored andcommitted
Python: document why Assignment subclasses are empty
Explain that the shared library's Assignment / CompoundAssignment hierarchy extends BinaryExpr, so it cannot host Python's statement- level assignment forms (Assign, AugAssign), and that Python has no short-circuiting compound operators (&&=, ||=, ??=) so all subclasses remain empty. No behaviour change; doc comments only. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 1e51c82 commit 72d74ae

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

python/ql/lib/semmle/python/controlflow/internal/AstNodeImpl.qll

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,19 +695,41 @@ module Ast implements AstSig<Py::Location> {
695695
/** A logical `not` expression. */
696696
class LogicalNotExpr extends UnaryExpr { }
697697

698-
/** An assignment expression. Python's walrus is modelled separately. */
698+
/**
699+
* An assignment expression.
700+
*
701+
* Empty in Python: `x = y` and `x += y` are statements (`AssignStmt` and
702+
* `AugAssignStmt`), not expressions, and the walrus `x := y` is modeled
703+
* separately as `NamedExpr`. The shared library's `Assignment` extends
704+
* `BinaryExpr`, so it cannot share instances with our `Stmt`-based
705+
* assignment forms.
706+
*/
699707
class Assignment extends BinaryExpr {
700708
Assignment() { none() }
701709
}
702710

711+
/** A simple assignment expression. Empty in Python (see `Assignment`). */
703712
class AssignExpr extends Assignment { }
704713

714+
/** A compound assignment expression. Empty in Python (see `Assignment`). */
705715
class CompoundAssignment extends Assignment { }
706716

717+
/**
718+
* A short-circuiting logical AND compound assignment expression (`&&=`).
719+
* Python has no such operator.
720+
*/
707721
class AssignLogicalAndExpr extends CompoundAssignment { }
708722

723+
/**
724+
* A short-circuiting logical OR compound assignment expression (`||=`).
725+
* Python has no such operator.
726+
*/
709727
class AssignLogicalOrExpr extends CompoundAssignment { }
710728

729+
/**
730+
* A short-circuiting null-coalescing compound assignment expression
731+
* (`??=`). Python has no such operator.
732+
*/
711733
class AssignNullCoalescingExpr extends CompoundAssignment { }
712734

713735
/** A boolean literal expression (`True` or `False`). */

0 commit comments

Comments
 (0)