Opened 8 months ago

Closed 3 weeks ago

Last modified 3 weeks ago

#36376 closed Bug (fixed)

Respect --no-color for command help on python 3.14

Reported by: Adam Johnson Owned by: Sachi Jain
Component: Core (Management commands) Version: 5.2
Severity: Release blocker Keywords: 3.14, color
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Adam Johnson)

Python 3.14 introduces colorized help to argparse: https://docs.python.org/3.14/library/argparse.html#color

I propose that we enable this feature by setting color=True for all argument parsers in Django, notably for management commands.

Python supports common opt-out environment variables for the feature. I think we’ll need to extend that to also avoid setting the color attribute when DJANGO_COLORS is set to nocolor, as already documented.

We may also be able to set the option when `--force-color` is passed, although that may not make sense when --help is passed.

Related: #36321

Change History (16)

comment:1 by Adam Johnson, 8 months ago

Description: modified (diff)

comment:2 by Adam Johnson, 8 months ago

Summary: Use argparse color on Python 3.14+Use argparse colorized help on Python 3.14+

comment:3 by Sarah Boyce, 8 months ago

Triage Stage: UnreviewedSomeday/Maybe
Type: UncategorizedNew feature

Note that Python 3.14 is scheduled for October 1st (see #35844)

comment:4 by Adam Johnson, 4 months ago

Has patch: set
Patch needs improvement: set

comment:5 by wangxiaolei, 4 months ago

Owner: set to wangxiaolei
Status: newassigned

comment:6 by Jacob Walls, 3 months ago

Triage Stage: Someday/MaybeAccepted

comment:7 by Sachi Jain, 4 weeks ago

Owner: changed from wangxiaolei to Sachi Jain

comment:8 by Sachi Jain, 4 weeks ago

Patch needs improvement: unset

comment:9 by Jacob Walls, 4 weeks ago

Keywords: 6.1 removed
Patch needs improvement: set
Severity: NormalRelease blocker
Summary: Use argparse colorized help on Python 3.14+Respect --no-color for command help on python 3.14
Type: New featureBug
Version: dev5.2

Before 3.14 final, Python decided to colorize by default. So rather than opting into the future here, we're left with just the bugfix to make --no-color and DJANGO_COLORS=nocolor work correctly on Python 3.14.

I'd even backport this as a bug in the support for 3.14.

comment:10 by Jacob Walls, 4 weeks ago

Needs documentation: set
Version: 5.26.0

That said, I don't think we have to backport all the way to 5.2 necessarily. I'm open to advice.

comment:11 by Adam Johnson, 4 weeks ago

I think I would backport it as a bugfix. Disabling colourization is sometimes important for accessibility or CI scripts, and leaving users who upgrade to Python 3.14 with new colours they can't disable feels like a minor bug to me.

comment:12 by Jacob Walls, 3 weeks ago

Keywords: 3.14 color added
Version: 6.05.2

I agree, and the vector for regressions is pretty low.

comment:13 by Jacob Walls, 3 weeks ago

Needs documentation: unset
Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:14 by Jacob Walls <jacobtylerwalls@…>, 3 weeks ago

Resolution: fixed
Status: assignedclosed

In d0d85cd:

Fixed #36376 -- Fixed --no-color for command help in Python 3.14+.

https://github.com/python/cpython/pull/136809 made color default to
True in ArgumentParser.

comment:15 by Jacob Walls <jacobtylerwalls@…>, 3 weeks ago

In b0befe1:

[6.0.x] Fixed #36376 -- Fixed --no-color for command help in Python 3.14+.

https://github.com/python/cpython/pull/136809 made color default to
True in ArgumentParser.

Backport of d0d85cd165e54582cce98cf685252e771460a9d4 from main.

comment:16 by Jacob Walls <jacobtylerwalls@…>, 3 weeks ago

In 8346657a:

[5.2.x] Fixed #36376 -- Fixed --no-color for command help in Python 3.14+.

https://github.com/python/cpython/pull/136809 made color default to
True in ArgumentParser.

Backport of d0d85cd165e54582cce98cf685252e771460a9d4 from main.

Note: See TracTickets for help on using tickets.
Back to Top