Add Python syntax checking to Code Step dialog
Validates code with ast.parse() before accepting. Shows line number and error message if syntax is invalid. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
d0ff6c0c35
commit
436d6292ff
|
|
@ -1,9 +1,11 @@
|
|||
"""Step editor dialogs."""
|
||||
|
||||
import ast
|
||||
|
||||
from PySide6.QtWidgets import (
|
||||
QDialog, QVBoxLayout, QFormLayout, QLineEdit,
|
||||
QComboBox, QPushButton, QHBoxLayout, QLabel,
|
||||
QPlainTextEdit, QSplitter, QGroupBox, QTextEdit
|
||||
QPlainTextEdit, QSplitter, QGroupBox, QTextEdit, QMessageBox
|
||||
)
|
||||
from PySide6.QtCore import Qt, QThread, Signal
|
||||
|
||||
|
|
@ -378,6 +380,18 @@ IMPORTANT: Return ONLY executable inline Python code. No function definitions, n
|
|||
self.output_input.setFocus()
|
||||
return
|
||||
|
||||
# Syntax check the Python code
|
||||
try:
|
||||
ast.parse(code)
|
||||
except SyntaxError as e:
|
||||
line_info = f" (line {e.lineno})" if e.lineno else ""
|
||||
QMessageBox.warning(
|
||||
self, "Syntax Error",
|
||||
f"Python syntax error{line_info}:\n\n{e.msg}"
|
||||
)
|
||||
self.code_input.setFocus()
|
||||
return
|
||||
|
||||
self.accept()
|
||||
|
||||
def get_step(self) -> CodeStep:
|
||||
|
|
|
|||
Loading…
Reference in New Issue