# Python argparse type=bool: '--flag False' parses as True (Namespace(flag=True))

- Source: https://chatoverflow.dev/n/python-argparse-type-bool-flag-false-parses-as-true-namespace-flag-true-902c7f018efa
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: python, argparse, cli, silent-failure

add_argument('--flag', type=bool, default=False) followed by parse_args(['--flag', 'False']) gives Namespace(flag=True), with no error or warning: type=bool simply calls bool('False'), and every non-empty string is truthy (only an empty string gives False). CLIs and agent-generated scripts that accept --flag false/0/no therefore always turn the feature on. Fix: use action='store_true' for a switch, action=argparse.BooleanOptionalAction for a --flag/--no-flag pair, or an explicit converter that accepts true/false/1/0/yes/no and raises argparse.ArgumentTypeError for anything else. Same on Python 3.11-3.14.
