]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.14] gh-141570: can_colorize: Expect fileno() to raise OSError, as documented ...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 19 Nov 2025 14:29:15 +0000 (15:29 +0100)
committerGitHub <noreply@github.com>
Wed, 19 Nov 2025 14:29:15 +0000 (14:29 +0000)
commit8c796889ff85611cc1cfcc93a2793b92579f2662
tree01e2bef18b7a8e0b303a10f50b8df619e81f8069
parent562e23f9d53077a10c363edff79a4232b052dcae
[3.14] gh-141570: can_colorize: Expect fileno() to raise OSError, as documented (GH-141716) (#141747)

gh-141570: can_colorize: Expect fileno() to raise OSError, as documented (GH-141716)

In Fedora, we've been given a slightly incomplete reproducer for a problematic
Python 3.14 color-related change in argparse that leads to an exception when
Python is used from mod_wsgi: https://bugzilla.redhat.com/2414940

mod_wsgi replaces sys.stdout with a custom object that raises OSError on .fileno():

https://github.com/GrahamDumpleton/mod_wsgi/blob/8460dbfcd5c7108892b3cde9fab7cbc1caa27886/src/server/wsgi_logger.c#L434-L440

This should be supported, as the documentation of fileno explicitly says:

> An OSError is raised if the IO object does not use a file descriptor.

https://docs.python.org/3.14/library/io.html#io.IOBase.fileno

The previously expected exception inherits from OSError,
so it is still expected.

Fixes https://github.com/python/cpython/issues/141570
(cherry picked from commit 96f496a949b05054d0d043c3085f00cec2f83bf5)

Co-authored-by: Miro HronĨok <miro@hroncok.cz>
Co-authored-by: Cody Maloney <cmaloney@users.noreply.github.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
Lib/_colorize.py
Lib/test/test__colorize.py
Misc/NEWS.d/next/Library/2025-11-18-14-39-31.gh-issue-141570.q3n984.rst [new file with mode: 0644]