https://github.com/python/cpython/commit/f4c9bc899b982b9742b45cff0643fa34de3dc84d
commit: f4c9bc899b982b9742b45cff0643fa34de3dc84d
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: savannahostrowski <[email protected]>
date: 2026-04-03T12:10:19-07:00
summary:

[3.14] gh-126676: Expand argparse docs for type=bool with warning and 
alternatives (GH-146435) (#148048)

gh-126676: Expand argparse docs for type=bool with warning and alternatives 
(GH-146435)
(cherry picked from commit 80d0a85d969d305c7436dc54f8939d7b6f441b5f)

Co-authored-by: Joshua Swanson <[email protected]>
Co-authored-by: joshuaswanson <[email protected]>
Co-authored-by: Savannah Ostrowski <[email protected]>

files:
A Misc/NEWS.d/next/Documentation/2026-03-25-00-00-00.gh-issue-126676.052336.rst
M Doc/library/argparse.rst

diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst
index 622f116bbee2ea..fe77a3a8b69f54 100644
--- a/Doc/library/argparse.rst
+++ b/Doc/library/argparse.rst
@@ -1111,7 +1111,15 @@ User defined functions can be used as well:
 
 The :func:`bool` function is not recommended as a type converter.  All it does
 is convert empty strings to ``False`` and non-empty strings to ``True``.
-This is usually not what is desired.
+This is usually not what is desired::
+
+   >>> parser = argparse.ArgumentParser()
+   >>> _ = parser.add_argument('--verbose', type=bool)
+   >>> parser.parse_args(['--verbose', 'False'])
+   Namespace(verbose=True)
+
+See :class:`BooleanOptionalAction` or ``action='store_true'`` for common
+alternatives.
 
 In general, the ``type`` keyword is a convenience that should only be used for
 simple conversions that can only raise one of the three supported exceptions.
diff --git 
a/Misc/NEWS.d/next/Documentation/2026-03-25-00-00-00.gh-issue-126676.052336.rst 
b/Misc/NEWS.d/next/Documentation/2026-03-25-00-00-00.gh-issue-126676.052336.rst
new file mode 100644
index 00000000000000..d2e275fdf08385
--- /dev/null
+++ 
b/Misc/NEWS.d/next/Documentation/2026-03-25-00-00-00.gh-issue-126676.052336.rst
@@ -0,0 +1,2 @@
+Expand :mod:`argparse` documentation for ``type=bool`` with a demonstration
+of the surprising behavior and pointers to common alternatives.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to