The validation.py module#
Summary#
Validate Python source code before it is executed in a CFX session. |
|
Replace common non-Python literal tokens in generated Python code. |
Description#
Static code validation shared across backends.
Phase 2: AST parse + a few cheap heuristics. Backends with a live solver session can layer real semantic checks on top by extending validate_code in their own implementation.
Module detail#
- validation.validate_python_source(code: str, *, forbidden_calls: Iterable[str] = _FORBIDDEN_CALLS, strict: bool = False, extra_allowed_names: Iterable[str] = ()) ansys.cfx.mcp.common.models.RunCodeResult#
Validate Python source code before it is executed in a CFX session.
- Parameters:
- code
str Python source code submitted for validation, grounding, or execution.
- forbidden_calls
Iterable[str],optional Dotted call names that must be rejected by the validator. Default is
_FORBIDDEN_CALLS.- strictbool,
optional Whether to enforce import and name allow-lists in addition to syntax checks. Default is
False.- extra_allowed_names
Iterable[str],optional Additional top-level names allowed when strict validation is enabled. Default is
().
- code
- Returns:
RunCodeResultValidation result describing whether the submitted Python source is acceptable.