Skip to content

Commit

Permalink
Create code_errors_fixer.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored May 15, 2024
1 parent f9d563c commit de8a50f
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions code_errors_fixer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import ast

def find_syntax_errors(code: str) -> list:
"""
Finds syntax errors in a string of Python code.
Args:
- code (str): The string of Python code to parse.
Returns:
- A list of syntax errors found in the code.
"""

try:
# Parse the code using the ast module
tree = ast.parse(code)
except SyntaxError as e:
# Return the syntax error as a list
return [str(e)]
else:
# If the code is syntactically correct, return an empty list
return []

0 comments on commit de8a50f

Please sign in to comment.