@@ -68,14 +68,20 @@ def _is_valid_code_response(text: str) -> tuple[bool, str]:
6868 Returns (is_valid, reason) where reason explains why validation failed.
6969 """
7070 if len (text ) < _MIN_CODE_LENGTH :
71- return False , f"Response too short ({ len (text )} chars, minimum { _MIN_CODE_LENGTH } )"
71+ return (
72+ False ,
73+ f"Response too short ({ len (text )} chars, minimum { _MIN_CODE_LENGTH } )" ,
74+ )
7275
7376 for pattern in _NON_CODE_ERROR_PATTERNS :
7477 if pattern .match (text .strip ()):
7578 return False , f"Response looks like an error message: { text [:80 ]!r} "
7679
7780 if not any (indicator in text for indicator in _CODE_INDICATORS ):
78- return False , "Response contains no code indicators (def, class, print, =, import)"
81+ return (
82+ False ,
83+ "Response contains no code indicators (def, class, print, =, import)" ,
84+ )
7985
8086 return True , ""
8187
@@ -99,11 +105,13 @@ def _errors_are_equivalent(err1: Optional[str], err2: Optional[str]) -> bool:
99105 """
100106 if not err1 or not err2 :
101107 return False
108+
102109 # Normalize: strip whitespace, collapse spaces, remove file:line:col refs
103110 def normalize (s : str ) -> str :
104- s = re .sub (r' -->\s*\S+:\d+:\d+' , '' , s ) # Remove file:line:col
105- s = re .sub (r' \s+' , ' ' , s ).strip ()
111+ s = re .sub (r" -->\s*\S+:\d+:\d+" , "" , s ) # Remove file:line:col
112+ s = re .sub (r" \s+" , " " , s ).strip ()
106113 return s
114+
107115 return normalize (err1 ) == normalize (err2 )
108116
109117
@@ -279,14 +287,14 @@ async def _verify_expected_with_python(
279287 "str?" ,
280288 "float?" ,
281289 "bool?" ,
282- "property " , # Sharpy properties (auto or function-style)
290+ "property " , # Sharpy properties (auto or function-style)
283291 "property get " ,
284292 "property set " ,
285293 "property init " ,
286- "with " , # Sharpy with statement uses IDisposable, not Python __enter__/__exit__
287- "from System" , # .NET interop imports
294+ "with " , # Sharpy with statement uses IDisposable, not Python __enter__/__exit__
295+ "from System" , # .NET interop imports
288296 "from system" ,
289- "type " , # Named tuple type aliases (type Point = tuple[x: ...])
297+ "type " , # Named tuple type aliases (type Point = tuple[x: ...])
290298 ]
291299 if any (feature in code for feature in sharpy_only_features ):
292300 return True , None , "Sharpy-specific features - skipping Python verification"
@@ -1209,7 +1217,9 @@ async def _generate_and_validate_code(
12091217 return GenerationResult (
12101218 success = False ,
12111219 code = code ,
1212- expected_output = extract_expected_output_from_response (gen_result .output ),
1220+ expected_output = extract_expected_output_from_response (
1221+ gen_result .output
1222+ ),
12131223 skip_reason = f"Repeated identical error (likely compiler bug): { prevalidation_error } " ,
12141224 backend_used = backend_used ,
12151225 generation_duration = total_duration ,
@@ -1226,7 +1236,9 @@ async def _generate_and_validate_code(
12261236 return GenerationResult (
12271237 success = False ,
12281238 code = code ,
1229- expected_output = extract_expected_output_from_response (gen_result .output ),
1239+ expected_output = extract_expected_output_from_response (
1240+ gen_result .output
1241+ ),
12301242 skip_reason = f"Pre-validation failed after { attempt } attempts: { prevalidation_error } " ,
12311243 backend_used = backend_used ,
12321244 generation_duration = total_duration ,
@@ -1245,7 +1257,9 @@ async def _generate_and_validate_code(
12451257 return GenerationResult (
12461258 success = False ,
12471259 code = code ,
1248- expected_output = extract_expected_output_from_response (gen_result .output ),
1260+ expected_output = extract_expected_output_from_response (
1261+ gen_result .output
1262+ ),
12491263 skip_reason = f"Internal compiler error: { semantic_error } " ,
12501264 backend_used = backend_used ,
12511265 generation_duration = total_duration ,
@@ -1266,7 +1280,9 @@ async def _generate_and_validate_code(
12661280 return GenerationResult (
12671281 success = False ,
12681282 code = code ,
1269- expected_output = extract_expected_output_from_response (gen_result .output ),
1283+ expected_output = extract_expected_output_from_response (
1284+ gen_result .output
1285+ ),
12701286 skip_reason = f"Repeated identical compiler error (likely compiler bug): { semantic_error } " ,
12711287 backend_used = backend_used ,
12721288 generation_duration = total_duration ,
@@ -1283,7 +1299,9 @@ async def _generate_and_validate_code(
12831299 return GenerationResult (
12841300 success = False ,
12851301 code = code ,
1286- expected_output = extract_expected_output_from_response (gen_result .output ),
1302+ expected_output = extract_expected_output_from_response (
1303+ gen_result .output
1304+ ),
12871305 skip_reason = f"Sharpy compiler error after { attempt } attempts: { semantic_error } " ,
12881306 backend_used = backend_used ,
12891307 generation_duration = total_duration ,
@@ -1335,7 +1353,11 @@ async def _generate_and_validate_code(
13351353 return GenerationResult (
13361354 success = False ,
13371355 code = last_code ,
1338- expected_output = extract_expected_output_from_response (last_raw_output ) if last_raw_output else None ,
1356+ expected_output = (
1357+ extract_expected_output_from_response (last_raw_output )
1358+ if last_raw_output
1359+ else None
1360+ ),
13391361 skip_reason = "Generation failed after all retry attempts" ,
13401362 backend_used = backend_used ,
13411363 generation_duration = total_duration ,
@@ -1469,9 +1491,7 @@ async def _generate_and_validate_multifile_code(
14691491 )
14701492
14711493 # Step 1.4: Validate that the response looks like actual code
1472- is_valid_code , invalid_reason = _is_valid_code_response (
1473- gen_result .output
1474- )
1494+ is_valid_code , invalid_reason = _is_valid_code_response (gen_result .output )
14751495 if not is_valid_code :
14761496 print (
14771497 f" Non-code response detected: { invalid_reason } " , file = sys .stderr
0 commit comments