Skip to content

Conversation

@chillakalyan
Copy link
Contributor

@chillakalyan chillakalyan commented Nov 15, 2025

Fixes: #141571

The color initialization logic in argparse currently calls _set_color()
twice when creating a formatter:

  1. HelpFormatter.init() calls _set_color(color) immediately,
    with color=True by default.

  2. Later, _get_formatter() calls _set_color(self.color) again.

This results in unnecessary repeated environment lookups and duplicate
calls to _colorize.can_colorize(), especially when color=False.

This patch removes the early _set_color(color) call inside
HelpFormatter.init and replaces it with a simple attribute assignment:

self._color = color

The actual color initialization continues to happen once in
_get_formatter(), maintaining all existing behavior while avoiding
redundant work.


📚 Documentation preview 📚: https://cpython-previews--141588.org.readthedocs.build/

miss-islington and others added 30 commits October 14, 2025 14:27
…) (python#140113)

Co-authored-by: Adorilson Bezerra <adorilson@gmail.com>
pythongh-139340) (pythongh-140110)

pythongh-101828: Fix `jisx0213` codecs removing null characters (pythongh-139340)
(cherry picked from commit 87eadce)

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
…odules (pythonGH-139755) (pythonGH-140117)

Revert pythonGH-131993.

Fix swallowing some syntax warnings in different modules if they accidentally
have the same message and are emitted from the same line.

Fix duplicated warnings in the "finally" block.

(cherry picked from commit 279db6b)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>

* Update 2025-10-06-10-03-37.gh-issue-139640.gY5oTb.rst

---------

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
…on#140088)

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
…onGH-140134) (python#140143)

Co-authored-by: Cody Maloney <cmaloney@users.noreply.github.com>
…ck if objects are uniquely referenced (pythongh-140062) (pythongh-140157)

The previous `Py_REFCNT(x) == 1` checks can have data races in the free
threaded build. `_PyObject_IsUniquelyReferenced(x)` is a more conservative
check that is safe in the free threaded build and is identical to
`Py_REFCNT(x) == 1` in the default GIL-enabled build.
(cherry picked from commit 32c2649)

Co-authored-by: Sergey Miryanov <sergey.miryanov@gmail.com>
….11-3.13 (pythonGH-140158) (python#140164)

pythongh-140153: Fix Py_REFCNT() definition on limited C API 3.11-3.13 (pythonGH-140158)
(cherry picked from commit 728d239)

Co-authored-by: Victor Stinner <vstinner@python.org>
…when ABI flags are present (pythonGH-140178) (python#140180)

Use sysconfig to determine the full name of libpython, rather than hardcoding
a library name that doesn't have ABI flags.
(cherry picked from commit 7f371ed)

Co-authored-by: Malcolm Smith <smith@chaquo.com>
…zeros in floating point numbers (pythonGH-140066) (pythonGH-140167)

(cherry picked from commit 1624c64)

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
…ython#140198)

pythongh-140170: Fix test_site with -s flag (pythonGH-140179)

Commit
(cherry picked from commit 7ac94fc)

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
…ython#140217)

pythongh-140078: fix typo in tkinter docs (pythonGH-140081)

Remove extraneous word.
(cherry picked from commit 5f357f3)

Co-authored-by: wangxiaolei <fatelei@gmail.com>
… lists … (pythonGH-138868) (python#140207)

pythongh-138859: Account for `ParamSpec` defaults that are not lists … (pythonGH-138868)
(cherry picked from commit 379fd02)

Co-authored-by: bzoracler <50305397+bzoracler@users.noreply.github.com>
…honGH-140188) (python#140192)

pythongh-140120: Refresh HACL* to fix an hmac memory leak (pythonGH-140188)

This pulls an updated version of HACL* that fixes the memory leak reported in pythonGH-140120, via an upstream fix.
(cherry picked from commit 3a81313)

Co-authored-by: Jonathan Protzenko <jonathan.protzenko+github@gmail.com>
…GH-131787) (python#137737)

pythongh-131788: make resource_tracker re-entrant safe (pythonGH-131787)

* make resource_tracker re-entrant safe
* Update Lib/multiprocessing/resource_tracker.py
* trim trailing whitespace
* use f-string and args = [x, *y, z]
* raise self._reentrant_call_error

---------
(cherry picked from commit f24a012)

Co-authored-by: Thomas Grainger <tagrain@gmail.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
…ythonGH-140240) (pythonGH-140246)

(cherry picked from commit fbf0843)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
…ading (pythonGH-140068) (python#140229)

pythongh-116738: test `uuid` module thread safety in free-threading (pythonGH-140068)
(cherry picked from commit 9a87ce8)

Co-authored-by: Alper <alperyoney@fb.com>
…Python 3.13 (pythonGH-133831) (python#140276)

pythonGH-133789: Fix unpickling of pathlib objects pickled in Python 3.13 (pythonGH-133831)

In Python 3.13 (but not 3.12 or 3.14), pathlib classes are defined in
`pathlib._local` rather than `pathlib`. In hindsight this was a mistake,
but it was difficult to predict how the abstract/local split would pan out.

In this patch we re-introduce `pathlib._local` as a stub module that
re-exports the classes from `pathlib`. This allows path objects pickled in
3.13 to be unpicked in 3.14+
(cherry picked from commit f4e51f2)

Co-authored-by: Barney Gale <barney.gale@gmail.com>
…GH-140274) (pythonGH-140285)

(cherry picked from commit f937468)

Co-authored-by: Shamil <ashm.tech@proton.me>
…ythonGH-140290) (pythonGH-140291)

(cherry picked from commit 936de25)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
…of warnings.warn_explicit() (pythonGH-140242) (pythonGH-140292)

(cherry picked from commit 78e1d65)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
…tion (pythonGH-140265) (python#140294)

pythongh-140257: fix data race on eval_breaker during finalization (pythonGH-140265)
(cherry picked from commit c8729c9)

Co-authored-by: Shamil <ashm.tech@proton.me>
…ythonGH-140111) (python#140118)

* [3.14] pythongh-140067: Fix memory leak in sub-interpreter creation  (pythonGH-140111)

Fix memory leak in sub-interpreter creation caused by overwriting of the previously used `_malloced` field. Now the pointer is stored in the first word of the memory block to avoid it being overwritten accidentally.
(cherry picked from commit 59547a2)

Co-authored-by: Shamil <ashm.tech@proton.me>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
…H-139974) (python#140309)

Closes pythonGH-128571
(cherry picked from commit 920de7c)

Co-authored-by: Parham MohammadAlizadeh <prhmma@gmail.com>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
…er docs (pythonGH-139023) (python#140319)

pythongh-138997: Remove false justify `fill` option from Tkinter docs (pythonGH-139023)
(cherry picked from commit 115a04b)

Co-authored-by: Marat Khagazheev <marathagazeev@gmail.com>
Co-authored-by: marat <khagazheev@artlebedev.ru>
…icate code (pythonGH-140259) (python#140322)

`Lib/idlelib/idle_test/__init__.py`: remove commented out duplicate code (pythonGH-140259)
(cherry picked from commit 790cdae)

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
…H-139898)

* Support non-UTF-8 shebang and comments if non-UTF-8 encoding is specified.
* Detect decoding error in comments for UTF-8 encoding.
* Include the decoding error position for default encoding in SyntaxError.
(cherry picked from commit 5c942f1)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
…ndling (pythonGH-140307) (pythonGH-140338)

(cherry picked from commit f932321)

Co-authored-by: Shamil <ashm.tech@proton.me>
…ython#140275)

Standardize translation of `Doc/bugs.rst` (pythonGH-137449)
(cherry picked from commit 869bb69)

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
@picnixz
Copy link
Member

picnixz commented Nov 15, 2025

Please create a new branch with a correct history

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

argparse color=False calls _set_color(True) first, then _set_color(False) -- leading to needless envirnment lookups