Skip to content

Commit 4ddbb8f

Browse files
committed
Properly classify recursion error on Python <=3.4
1 parent 7ca34e2 commit 4ddbb8f

1 file changed

Lines changed: 29 additions & 2 deletions

File tree

corpus_test/generate_report.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,33 @@
99

1010
ENHANCED_REPORT = os.environ.get('ENHANCED_REPORT', True)
1111

12+
def is_recursion_error(python_version: str, result: Result) -> bool:
13+
"""
14+
Check if the result is a recursion error
15+
"""
16+
if result.outcome == 'RecursionError':
17+
return True
18+
19+
if python_version in ['2.7', '3.3', '3.4']:
20+
# In these versions, the recursion error is raised as an Exception
21+
return result.outcome.startswith('Exception: maximum recursion depth exceeded')
22+
23+
return False
24+
25+
def is_syntax_error(python_version: str, result: Result) -> bool:
26+
"""
27+
Check if the result is a syntax error
28+
"""
29+
if result.outcome == 'SyntaxError':
30+
return True
31+
32+
if python_version == '2.7' and result.outcome == 'Exception: compile() expected string without null bytes':
33+
return True
34+
35+
if python_version != '2.7' and result.outcome == 'Exception: source code string cannot contain null bytes':
36+
return True
37+
38+
return False
1239

1340
@dataclass
1441
class ResultSet:
@@ -45,11 +72,11 @@ def add(self, result: Result):
4572
if result.original_size < result.minified_size:
4673
self.larger_than_original_count += 1
4774

48-
if result.outcome == 'RecursionError':
75+
if is_recursion_error(self.python_version, result):
4976
self.recursion_error_count += 1
5077
elif result.outcome == 'UnstableMinification':
5178
self.unstable_minification_count += 1
52-
elif result.outcome.startswith('Exception') and result.outcome != 'Exception: source code string cannot contain null bytes':
79+
elif result.outcome.startswith('Exception') is not is_syntax_error(self.python_version, result):
5380
self.exception_count += 1
5481

5582
@property

0 commit comments

Comments
 (0)