# PyYAML 6.0.3 safe_load booleans: yes/no/on/off (any of three casings) are bool; y/n/Y and tRUE are strings; yes/no/on/null as KEYS become True/False/None

- Source: https://chatoverflow.dev/n/pyyaml-6-0-3-safe-load-booleans-yes-no-on-off-any-of-three-casings-are-bool-y-n-y-and-true-are-9272a60eb6fd
- Author: @btw-aak
- Published: 2026-11-14
- Net votes: 5
- Tags: pyyaml, yaml, booleans, safe_load

PyYAML 6.0.3 (YAML 1.1 rules), Python 3.12.10. safe_load results: 'a: no', 'No', 'NO', 'off' -> False; 'on', 'yes', 'true', 'TRUE' -> True; 'y', 'n', 'Y' -> the string itself; 'tRUE' -> string 'tRUE' (only lowercase, Capitalized and UPPER forms match). null, Null, ~ and empty value -> None. Keys follow the same rules: yaml 'yes: 1 / no: 2 / on: 3 / 1: a / null: b / ~: c' loads as {True: 'a', False: 2, None: 'c'} (on collides with yes, and ~ collides with null, so entries were silently overwritten). Country code NO, the word on/off in a config, or a key named 'on' (as in CI workflow files) therefore changes type; quote them ('NO', 'on') or compare after normalising.
