Popping pybuild into a debugger and stepping through, the assertion in the middle of this block fails:

/--- dhpython/tools.py:262 [execute()]

    with ExitStack() as stack:
        output: TextIO | int | None
        if log_output is False:
            output = None
        elif log_output is None:
            output = PIPE
        elif log_output:
            if isinstance(log_output, str):
                log_output = stack.enter_context(
                    open(log_output, "a", encoding="utf-8")
                )
            assert isinstance(log_output, TextIO)
log_output.write(f"\n# command executed on {datetime.now().isoformat()}")
            log_output.write(f"\n$ {command}\n")
            log_output.flush()
            output = log_output

---/

log_output is initially a str:

(Pdb) p log_output
'/build/python-idna-W7e44C/python-idna-3.11/.pybuild/cpython3_3.14/build_wheel_cmd.log'


but its rebirth as a TextIO does not work as intended:

> /usr/share/dh-python/dhpython/tools.py(291)execute()
-> assert isinstance(log_output, TextIO)
(Pdb)
AssertionError
> /usr/share/dh-python/dhpython/tools.py(291)execute()
-> assert isinstance(log_output, TextIO)
(Pdb) p log_output
<_io.TextIOWrapper name='/build/python-idna-W7e44C/python-idna-3.11/.pybuild/cpython3_3.14/build_wheel_cmd.log' mode='a' encoding='utf-8'>


it's actually a TextIOWrapper; changing the assertion to

        assert isinstance(log_output, io.TextIOBase)

is enough to get it working. I guess this is a case where the typehint TextIO is not quite enough for the isinstance check.

The failed assertion should probably generate some more useful noise too (perhaps raising a TypeError or ValueError if the log_output is neither the desired type nor coercible into a usable type?

regards
Stuart


--
Stuart Prescott   http://www.nanonanonano.net/ [email protected]
Debian Developer  http://www.debian.org/       [email protected]
GPG fingerprint   90E2 D2C1 AD14 6A1B 7EBB 891D BBC1 7EBB 1396 F2F7

Reply via email to