Awesome Reviewers expert instructions

domains / / pallets/flask#x

Robust environment-based configuration

Configuration driven by environment variables or `.env` files must be parsed defensively and documented as the single source of truth. - When interpreting boolean-like flags (e.g. `FLASK_DEBUG`), normalize case before comparing instead of listing every casing variant:

raw .md Configurations Python

Configuration driven by environment variables or .env files must be parsed defensively and documented as the single source of truth.

  • When interpreting boolean-like flags (e.g. FLASK_DEBUG), normalize case before comparing instead of listing every casing variant:
    val = os.environ.get('FLASK_DEBUG')
    if not val:
        return default
    return val.lower() not in ('0', 'false', 'no')
    
  • When parsing .env files, be defensive: strip surrounding whitespace from both key and value, skip or explicitly reject malformed lines (e.g. multi-line values that would otherwise be silently truncated), and be careful with encoding when reading in binary mode and splitting with native strings (especially under Python 3). Prefer failing loudly over silently producing incorrect values.
  • Provide reasonable configurability around file/environment loading, such as allowing an optional directory argument for locating config/dotenv files instead of hardcoding discovery logic.
  • For environment-style settings (e.g. FLASK_ENV controlling development/production), keep comparisons simple and consistent (env == 'development'), and consider supporting common shorthand aliases where it doesn’t break compatibility with established conventions used by other tools.
  • Document clearly that derived runtime flags (like DEBUG) are intended to be set only via their corresponding environment variable, not mutated directly in code, since other parts of the app may already have configured behavior based on the initial value. Make the documentation precise about what the flag actually triggers, avoiding vague or misleading descriptions.

Following these practices prevents subtle bugs from case-sensitive comparisons, malformed config files, encoding issues, and misleading documentation about how configuration values should be set and what they control.