From 05aa8debc442151180fefd7c1daf4a99258e09a4 Mon Sep 17 00:00:00 2001 From: yoff Date: Mon, 27 Jul 2026 16:23:30 +0200 Subject: [PATCH] python: make `LoopStmt` final --- .../python/controlflow/internal/AstNodeImpl.qll | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/python/ql/lib/semmle/python/controlflow/internal/AstNodeImpl.qll b/python/ql/lib/semmle/python/controlflow/internal/AstNodeImpl.qll index 8199008e88c..891ba8c1318 100644 --- a/python/ql/lib/semmle/python/controlflow/internal/AstNodeImpl.qll +++ b/python/ql/lib/semmle/python/controlflow/internal/AstNodeImpl.qll @@ -593,8 +593,10 @@ module Ast implements AstSig { } /** A loop statement. */ - class LoopStmt extends Stmt { - LoopStmt() { + final class LoopStmt = LoopStmtImpl; + + abstract private class LoopStmtImpl extends Stmt { + LoopStmtImpl() { this = TPyStmt(any(Py::While w)) or this = TPyStmt(any(Py::For f)) @@ -605,7 +607,7 @@ module Ast implements AstSig { } /** A `while` loop statement. */ - class WhileStmt extends LoopStmt { + class WhileStmt extends LoopStmtImpl { private Py::While whileStmt; WhileStmt() { this = TPyStmt(whileStmt) } @@ -630,21 +632,21 @@ module Ast implements AstSig { /** * A `do-while` loop statement. Python has no do-while construct. */ - class DoStmt extends LoopStmt { + class DoStmt extends LoopStmtImpl { DoStmt() { none() } Expr getCondition() { none() } } /** An `until` loop. Python has no `until` loop. */ - class UntilStmt extends LoopStmt { + class UntilStmt extends LoopStmtImpl { UntilStmt() { none() } Expr getCondition() { none() } } /** A C-style `for` loop. Python has no C-style for loop. */ - class ForStmt extends LoopStmt { + class ForStmt extends LoopStmtImpl { ForStmt() { none() } AstNode getInit(int index) { none() } @@ -655,7 +657,7 @@ module Ast implements AstSig { } /** A for-each loop (`for x in iterable:`). */ - class ForeachStmt extends LoopStmt { + class ForeachStmt extends LoopStmtImpl { private Py::For forStmt; ForeachStmt() { this = TPyStmt(forStmt) }