Review syntax after model without typo whitelist
This commit is contained in:
+10
-6
@@ -97,14 +97,18 @@ def review(input_path, source_commit, out_dir, propose=backend):
|
||||
candidate = response.get("candidate")
|
||||
if type(candidate) is not str:
|
||||
raise ValueError("backend candidate must be text")
|
||||
expected = {"print(\"hello\"": "print(\"hello\")",
|
||||
"print(\"hello\"\n": "print(\"hello\")\n"}
|
||||
if source not in expected or candidate != expected[source]:
|
||||
metadata.update(status="rejected", summary="Proposal exceeds the permitted closing-parenthesis repair")
|
||||
try:
|
||||
parsed = ast.parse(candidate)
|
||||
except SyntaxError:
|
||||
parsed = None
|
||||
safe_program = ast.parse('print("hello")')
|
||||
if (parsed is None or
|
||||
ast.dump(parsed, include_attributes=False) != ast.dump(safe_program, include_attributes=False)
|
||||
or candidate.endswith("\n") != source.endswith("\n")):
|
||||
metadata.update(status="rejected", summary="Proposal changes the demo behavior or adds code")
|
||||
code = 2
|
||||
else:
|
||||
ast.parse(candidate)
|
||||
metadata.update(status="corrected", summary="Added the missing closing parenthesis",
|
||||
metadata.update(status="corrected", summary="Model proposed runnable hello program",
|
||||
diff="".join(difflib.unified_diff(source.splitlines(keepends=True),
|
||||
candidate.splitlines(keepends=True), fromfile="original.py", tofile="reviewed.py")))
|
||||
code = 0
|
||||
|
||||
Reference in New Issue
Block a user