Skip to content

Assertion-Based Genre Validation Disabled by Python -O Flag #132

@CyberSecDef

Description

@CyberSecDef

Problem

Both names.py and voice.py use assert statements to validate genre coverage at import time. When Python runs with -O (optimize flag), all assert statements are compiled out.

# names.py lines 53-56
assert not _missing_name_genres, (...)

# voice.py lines 247-250
assert not _missing_voice_genres, (...)

Why It Matters

If someone adds a genre to ALLOWED_GENRES without adding mappings:

  • names.py returns the "contemporary" name pool (culturally inappropriate names)
  • voice.py produces unweighted random voice selection (no genre bias)

No error visible to the user.

Recommended Fix

Replace assertions with explicit if checks that raise ValueError:

_missing_name_genres = ALLOWED_GENRES - _GENRE_GROUP.keys()
if _missing_name_genres:
    raise ValueError(f"Genres missing from _GENRE_GROUP: {sorted(_missing_name_genres)}")

Metadata

Metadata

Labels

bugSomething isn't workingpriority:criticalCritical priority

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions