-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Open
Labels
Description
Description
examples/scaffolding/run_majority_vote_aime24.py contains two code issues:
1. Bare except: clause (line 112)
try:
answer = int(extracted_answer)
print(f'Answer={answer}, reference={ref_answer}')
if answer == ref_answer:
correct_count += 1
except:
print(f'extracted_answer={extracted_answer}, not integer.')The bare except: catches all exceptions including KeyboardInterrupt and SystemExit, which makes it impossible to cleanly interrupt the program during evaluation. Since int() can only raise ValueError or TypeError, the except clause should be narrowed to except (ValueError, TypeError):.
2. Improper None comparison (line 79)
if args.concurrency == None:
args.concurrency = 1Per PEP 8, comparisons to None should use is / is not, not == / !=. The == operator can be overridden by __eq__, leading to unexpected behavior.
Why this needs to be fixed
- The bare
except:can mask unexpected errors and prevent clean process termination (e.g., Ctrl+C during long evaluations) == Noneis a well-known Python anti-pattern that can produce incorrect results with custom objects
Proposed fix
- Line 112: Change
except:→except (ValueError, TypeError): - Line 79: Change
== None→is None
Reactions are currently unavailable