Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -34,39 +34,41 @@ class ErrorReporter(Reporter):
|
|
| 34 |
def check_code_with_pyflakes(code_str: str) -> str:
|
| 35 |
"""
|
| 36 |
Analyzes a string of Python code using pyflakes and returns a formatted error report.
|
| 37 |
-
|
| 38 |
Returns an empty string if no definite errors are found.
|
| 39 |
"""
|
| 40 |
reporter = ErrorReporter()
|
| 41 |
check(code_str, "scene.py", reporter=reporter)
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
filtered_errors = []
|
| 44 |
for err in reporter.errors:
|
| 45 |
err_str = str(err)
|
| 46 |
-
#
|
| 47 |
-
|
| 48 |
-
is_star_import_warning = "may be undefined, or defined from star imports" in err_str
|
| 49 |
-
is_general_import_warning = "'undefined names' found" in err_str
|
| 50 |
-
|
| 51 |
-
if not is_star_import_warning and not is_general_import_warning:
|
| 52 |
filtered_errors.append(err_str)
|
| 53 |
-
# --- END: Updated Filtering Logic ---
|
| 54 |
|
| 55 |
if not filtered_errors:
|
| 56 |
-
return "" # No errors found
|
| 57 |
|
| 58 |
-
# Format the filtered error list into a user-friendly string
|
| 59 |
error_report = "Static analysis found potential errors:\n"
|
| 60 |
for err in filtered_errors:
|
| 61 |
-
#
|
| 62 |
-
|
| 63 |
-
if
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
| 67 |
else:
|
| 68 |
-
|
| 69 |
-
error_report += f"- {err}\n"
|
| 70 |
|
| 71 |
return error_report
|
| 72 |
|
|
|
|
| 34 |
def check_code_with_pyflakes(code_str: str) -> str:
|
| 35 |
"""
|
| 36 |
Analyzes a string of Python code using pyflakes and returns a formatted error report.
|
| 37 |
+
This version uses a robust blocklist to filter out all warnings related to star imports.
|
| 38 |
Returns an empty string if no definite errors are found.
|
| 39 |
"""
|
| 40 |
reporter = ErrorReporter()
|
| 41 |
check(code_str, "scene.py", reporter=reporter)
|
| 42 |
|
| 43 |
+
# A blocklist of warning substrings to completely ignore.
|
| 44 |
+
IGNORE_SUBSTRINGS = [
|
| 45 |
+
"may be undefined, or defined from star imports",
|
| 46 |
+
"undefined names"
|
| 47 |
+
]
|
| 48 |
+
|
| 49 |
filtered_errors = []
|
| 50 |
for err in reporter.errors:
|
| 51 |
err_str = str(err)
|
| 52 |
+
# If the error message contains any of the substrings in our blocklist, we ignore it.
|
| 53 |
+
if not any(sub in err_str for sub in IGNORE_SUBSTRINGS):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
filtered_errors.append(err_str)
|
|
|
|
| 55 |
|
| 56 |
if not filtered_errors:
|
| 57 |
+
return "" # No real errors found
|
| 58 |
|
|
|
|
| 59 |
error_report = "Static analysis found potential errors:\n"
|
| 60 |
for err in filtered_errors:
|
| 61 |
+
# Use a simpler, more robust formatting logic
|
| 62 |
+
parts = err.split(':', 2)
|
| 63 |
+
if len(parts) == 3:
|
| 64 |
+
try:
|
| 65 |
+
line_num = parts[1]
|
| 66 |
+
message = parts[2].strip()
|
| 67 |
+
error_report += f"- Line {line_num}: {message}\n"
|
| 68 |
+
except:
|
| 69 |
+
error_report += f"- {err}\n" # Fallback for unexpected format
|
| 70 |
else:
|
| 71 |
+
error_report += f"- {err}\n" # Fallback
|
|
|
|
| 72 |
|
| 73 |
return error_report
|
| 74 |
|