Skip to content

fix: Bare except clause and improper None comparison in run_majority_vote_aime24.py #12040

@edenfunf

Description

@edenfunf

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 = 1

Per 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)
  • == None is 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 == Noneis None

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions