🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.debian.bugs.dist
Article #676

Bug#1150754: python3-pytoolconfig: fails with postponed annotations: subtables, Enum and command line flags broken

#676
From: Nico Della Torre
Date: Tue, 13 Oct 2026 10:00
94 lines
4253 bytes
Package: python3-pytoolconfig
Version: 1.3.1-5
Severity: normal
Tags: upstream

With `from __future__ import annotations` in the module defining the
configuration model, `dataclasses.Field.type` is a string instead of the
actual type. pytoolconfig uses it directly, so subtables are left as
plain dicts, Enum values are not converted, and setting up command line
flags raises an exception.

This is upstream issue #2, which only mentions subtables.

pyproject.toml:

    [tool.t]
    mode = "fast"

    [tool.t.sub]
    x = 5

test.py:

    from __future__ import annotations

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

    from pytoolconfig import PyToolConfig, field

    class Mode(enum.Enum):
        fast = "fast"
        slow = "slow"

    @dataclass
    class Sub:
        x: int = 1

    @dataclass
    class Config:
        mode: Mode = Mode.slow
        sub: Sub = field(default_factory=Sub)
        n: int = field(1, command_line=("--n",))

    config = PyToolConfig("t", Path("."), Config).parse()
    print(repr(config.mode), repr(config.sub))

    PyToolConfig("t", Path("."), Config, arg_parser=ArgumentParser())

Actual:

    'fast' {'x': 5}
    TypeError: 'int' is not callable

(`ValueError` instead of `TypeError` on Python 3.13.) The same code
without the `__future__` import works as expected.

Expected:

    <Mode.fast: 'fast'> Sub(x=5)

and the argument parser to be set up without errors.

Affected code:

- `utils._subtables()` and `utils._dict_to_dataclass()` (`is_dataclass`,
  `isinstance(keytype, EnumMeta)` on a string)
- `PyToolConfig._setup_arg_parser()` (`type=field._type`)
- `documentation._subtables()`

Resolving the annotations once with `typing.get_type_hints(model)` and
using the result instead of `Field.type` should fix all of them.

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).

Already reported upstream:
https://github.com/bageljrkhanofemus/pytoolconfig/issues/2


-- 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
Technical Details
Message-ID: <NNHsB-5f87-1@gated-at.bofh.it>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!news.corradoroberto.it!bofh.it!news.nic.it!robomod

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!news.corradoroberto.it!bofh.it!news.nic.it!robomod
From: Nico Della Torre <nicoz91@ubuntu.com>
Newsgroups: linux.debian.bugs.dist
Subject: Bug#1150754: python3-pytoolconfig: fails with postponed annotations: subtables, Enum and command line flags broken
Date: Tue, 13 Oct 2026 12:00:01 +0200
Message-ID: <NNHsB-5f87-1@gated-at.bofh.it>
X-Original-To: Debian Bug Tracking System <submit@bugs.debian.org>
X-Mailbox-Line: From debian-bugs-dist-request@lists.debian.org  Tue Oct 13 09:51:10 2026
Old-Return-Path: <debbugs@buxtehude.debian.org>
X-Spam-Flag: NO
X-Spam-Score: -1.651
Reply-To: Nico Della Torre <nicoz91@ubuntu.com>, 1150754@bugs.debian.org
Resent-To: debian-bugs-dist@lists.debian.org
Resent-Cc: team+python@tracker.debian.org
X-Debian-Pr-Message: report 1150754
X-Debian-Pr-Package: python3-pytoolconfig
X-Debian-Pr-Keywords: upstream
X-Debian-Pr-Source: pytoolconfig
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Mailer: reportbug 13.2.0+nmu1
X-Debian-Message: from BTS
X-Mailing-List: <debian-bugs-dist@lists.debian.org> archive/latest/1996527
List-ID: <debian-bugs-dist.lists.debian.org>
List-URL: <https://lists.debian.org/debian-bugs-dist/>
Approved: robomod@news.nic.it
Lines: 94
Organization: linux.* mail to news gateway
Sender: robomod@news.nic.it
X-Original-Date: Tue, 13 Oct 2026 11:48:59 +0200
X-Original-Message-ID: <179188493931.272034.9178668761826130253.reportbug@ryzendeb.linuxlab>