Package: python3-pytoolconfig
Version: 1.3.1-5
Severity: normal
Tags: upstream

`PyToolConfig._setup_arg_parser()` passes the field type directly to
argparse as `type=`. For `bool` fields this means `bool(<string>)`,
which is `True` for any non-empty string, so a boolean option cannot be
disabled from the command line.

test.py:

    from argparse import ArgumentParser
    from dataclasses import dataclass
    from pathlib import Path

    from pytoolconfig import PyToolConfig, field

    @dataclass
    class Config:
        verbose: bool = field(False, command_line=("--verbose",))

    config = PyToolConfig("t", Path("."), Config, arg_parser=ArgumentParser())
    print(config.parse(["--verbose", "False"]).verbose)

Actual: `True`

Expected: `False`

`--verbose 0` and `--verbose no` give `True` as well; only an empty
string gives `False`.

Possible fixes: register `bool` fields with
`action=argparse.BooleanOptionalAction` (Python 3.9+), or with a
converter that accepts the usual true/false strings.

Reproduced with python3-pytoolconfig 1.3.1-5 (code unchanged in 1.3.1-6)
on Python 3.13 and 3.14, and with upstream main (bee6db4).

This is an upstream bug, it will be forwarded.


-- System Information:
Debian Release: forky/sid
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 7.2.9+deb14-amd64 (SMP w/12 CPU threads; PREEMPT)
Locale: LANG=it_IT.UTF-8, LC_CTYPE=it_IT.UTF-8 (charmap=UTF-8), LANGUAGE=it
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Reply via email to