diff --git a/codeflash/languages/python/support.py b/codeflash/languages/python/support.py index b5a6596b3..a5cfae99a 100644 --- a/codeflash/languages/python/support.py +++ b/codeflash/languages/python/support.py @@ -685,11 +685,7 @@ def validate_syntax(self, source: str, file_path: Path | None = None) -> bool: True if valid, False otherwise. """ - try: - compile(source, "", "exec") - return True - except SyntaxError: - return False + return _compile_ok(source) def normalize_code(self, source: str) -> str: from codeflash.languages.python.normalizer import normalize_python_code @@ -1361,3 +1357,12 @@ def generate_concolic_tests( end_time = time.perf_counter() logger.debug("Generated concolic tests in %.2f seconds", end_time - start_time) return function_to_concolic_tests, concolic_test_suite_code + + +def _compile_ok(source: str) -> bool: + # Keep behavior identical to the original: use compile() and only catch SyntaxError. + try: + compile(source, "", "exec") + return True + except SyntaxError: + return False