-
-
Notifications
You must be signed in to change notification settings - Fork 33.4k
Description
Bug report
Bug description:
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. cc @GrahamDumpleton
Apparently the following code is enough to trigger it:
import argparse
parser = argparse.ArgumentParser(add_help=False, color=False)
arg = parser.add_argument('-v', '--verbose', help='verbose', action='store_true', default=False)Looking at GrahamDumpleton/mod_wsgi#890 it seems that mod_wsgi replaces sys.stdout with a custom object that raises OSError on .fileno():
The relevant code in _colorize.can_colorize() does not expect OSError -- it only expects a more specific io.UnsupportedOperation:
Lines 313 to 316 in a2442fd
| try: | |
| return os.isatty(file.fileno()) | |
| except io.UnsupportedOperation: | |
| return hasattr(file, "isatty") and file.isatty() |
I don't know if raising OSError from .fileno() in mod_wsgi is OK or not, yet perhaps _colorize.can_colorize() should be more robust and expect either OSError or outright Exception. WDYT?
CPython versions tested on:
3.14
Operating systems tested on:
Linux