99
1010ENHANCED_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
1441class 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' ):
79+ elif result .outcome .startswith ('Exception' ) and not is_syntax_error ( self . python_version , result ) :
5380 self .exception_count += 1
5481
5582 @property
@@ -74,13 +101,13 @@ def larger_than_original(self) -> Iterable[Result]:
74101 def recursion_error (self ) -> Iterable [Result ]:
75102 """Return those entries that have a recursion error"""
76103 for result in self .entries .values ():
77- if result . outcome == 'RecursionError' :
104+ if is_recursion_error ( self . python_version , result ) :
78105 yield result
79106
80107 def exception (self ) -> Iterable [Result ]:
81108 """Return those entries that have an exception"""
82109 for result in self .entries .values ():
83- if result .outcome .startswith ('Exception' ):
110+ if result .outcome .startswith ('Exception' ) and not is_syntax_error ( self . python_version , result ) and not is_recursion_error ( self . python_version , result ) :
84111 yield result
85112
86113 def unstable_minification (self ) -> Iterable [Result ]:
@@ -184,7 +211,7 @@ def format_difference(compare: Iterable[Result], base: Iterable[Result]) -> str:
184211 return s
185212
186213
187- def report_larger_than_original (results_dir : str , python_versions : str , minifier_sha : str ) -> str :
214+ def report_larger_than_original (results_dir : str , python_versions : list [ str ] , minifier_sha : str ) -> str :
188215 yield '''
189216## Larger than original
190217
@@ -203,7 +230,7 @@ def report_larger_than_original(results_dir: str, python_versions: str, minifier
203230 yield f'| { entry .corpus_entry } | { entry .original_size } | { entry .minified_size } ({ entry .minified_size - entry .original_size :+} ) |'
204231
205232
206- def report_unstable (results_dir : str , python_versions : str , minifier_sha : str ) -> str :
233+ def report_unstable (results_dir : str , python_versions : list [ str ] , minifier_sha : str ) -> str :
207234 yield '''
208235## Unstable
209236
@@ -222,7 +249,7 @@ def report_unstable(results_dir: str, python_versions: str, minifier_sha: str) -
222249 yield f'| { entry .corpus_entry } | { python_version } | { entry .original_size } |'
223250
224251
225- def report_exceptions (results_dir : str , python_versions : str , minifier_sha : str ) -> str :
252+ def report_exceptions (results_dir : str , python_versions : list [ str ] , minifier_sha : str ) -> str :
226253 yield '''
227254## Exceptions
228255
@@ -244,10 +271,10 @@ def report_exceptions(results_dir: str, python_versions: str, minifier_sha: str)
244271 yield f'| { entry .corpus_entry } | { python_version } | { entry .outcome } |'
245272
246273 if not exceptions_found :
247- yield ' None | | |'
274+ yield '| None | | |'
248275
249276
250- def report_larger_than_base (results_dir : str , python_versions : str , minifier_sha : str , base_sha : str ) -> str :
277+ def report_larger_than_base (results_dir : str , python_versions : list [ str ] , minifier_sha : str , base_sha : str ) -> str :
251278 yield '''
252279## Top 10 Larger than base
253280
@@ -277,7 +304,7 @@ def report_larger_than_base(results_dir: str, python_versions: str, minifier_sha
277304 yield '| N/A | N/A | N/A |'
278305
279306
280- def report_slowest (results_dir : str , python_versions : str , minifier_sha : str ) -> str :
307+ def report_slowest (results_dir : str , python_versions : list [ str ] , minifier_sha : str ) -> str :
281308 yield '''
282309## Top 10 Slowest
283310
@@ -360,15 +387,15 @@ def report(results_dir: str, minifier_ref: str, minifier_sha: str, base_ref: str
360387 f'| { format_difference (summary .larger_than_original (), base_summary .larger_than_original ())} ' +
361388 f'| { format_difference (summary .recursion_error (), base_summary .recursion_error ())} ' +
362389 f'| { format_difference (summary .unstable_minification (), base_summary .unstable_minification ())} ' +
363- f'| { format_difference (summary .exception (), base_summary .exception ())} '
390+ f'| { format_difference (summary .exception (), base_summary .exception ())} | '
364391 )
365392
366393 if ENHANCED_REPORT :
367394 yield from report_larger_than_original (results_dir , ['3.13' ], minifier_sha )
368395 yield from report_larger_than_base (results_dir , ['3.13' ], minifier_sha , base_sha )
369396 yield from report_slowest (results_dir , ['3.13' ], minifier_sha )
370397 yield from report_unstable (results_dir , ['2.7' , '3.3' , '3.4' , '3.5' , '3.6' , '3.7' , '3.8' , '3.9' , '3.10' , '3.11' , '3.12' , '3.13' ], minifier_sha )
371- yield from report_exceptions (results_dir , ['3.6' , '3.7' , '3.8' , '3.9' , '3.10' , '3.11' , '3.12' , '3.13' ], minifier_sha )
398+ yield from report_exceptions (results_dir , ['2.7' , '3.3' , '3.4' , '3.5' , ' 3.6' , '3.7' , '3.8' , '3.9' , '3.10' , '3.11' , '3.12' , '3.13' ], minifier_sha )
372399
373400
374401def main ():
0 commit comments