From 58ffc517d76e77aad40195ca0fae76ab60267ecd Mon Sep 17 00:00:00 2001 From: litlighilit Date: Mon, 14 Oct 2024 16:23:32 +0800 Subject: [PATCH 1/5] gh-125436: add missing allow_unnamed_section doc --- Doc/library/configparser.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/configparser.rst b/Doc/library/configparser.rst index 3aad6f7b5d2d20..0925912daac3db 100644 --- a/Doc/library/configparser.rst +++ b/Doc/library/configparser.rst @@ -942,7 +942,7 @@ interpolation if an option used is not defined elsewhere. :: ConfigParser Objects -------------------- -.. class:: ConfigParser(defaults=None, dict_type=dict, allow_no_value=False, delimiters=('=', ':'), comment_prefixes=('#', ';'), inline_comment_prefixes=None, strict=True, empty_lines_in_values=True, default_section=configparser.DEFAULTSECT, interpolation=BasicInterpolation(), converters={}) +.. class:: ConfigParser(defaults=None, dict_type=dict, allow_no_value=False, delimiters=('=', ':'), comment_prefixes=('#', ';'), inline_comment_prefixes=None, strict=True, empty_lines_in_values=True, default_section=configparser.DEFAULTSECT, interpolation=BasicInterpolation(), converters={}, allow_unnamed_section=False) The main configuration parser. When *defaults* is given, it is initialized into the dictionary of intrinsic defaults. When *dict_type* is given, it From 4f84f437c558445588ed1aa00022b2c2b5cf079d Mon Sep 17 00:00:00 2001 From: litlighilit Date: Mon, 14 Oct 2024 16:24:26 +0800 Subject: [PATCH 2/5] gh-125436: split too long line of ConfigParser doc --- Doc/library/configparser.rst | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Doc/library/configparser.rst b/Doc/library/configparser.rst index 0925912daac3db..c3c6f1dad8405b 100644 --- a/Doc/library/configparser.rst +++ b/Doc/library/configparser.rst @@ -942,7 +942,13 @@ interpolation if an option used is not defined elsewhere. :: ConfigParser Objects -------------------- -.. class:: ConfigParser(defaults=None, dict_type=dict, allow_no_value=False, delimiters=('=', ':'), comment_prefixes=('#', ';'), inline_comment_prefixes=None, strict=True, empty_lines_in_values=True, default_section=configparser.DEFAULTSECT, interpolation=BasicInterpolation(), converters={}, allow_unnamed_section=False) +.. class:: ConfigParser(defaults=None, dict_type=dict, allow_no_value=False, \ + delimiters=('=', ':'), comment_prefixes=('#', ';'), \ + inline_comment_prefixes=None, strict=True, \ + empty_lines_in_values=True, \ + default_section=configparser.DEFAULTSECT, \ + interpolation=BasicInterpolation(), converters={}, \ + allow_unnamed_section=False) The main configuration parser. When *defaults* is given, it is initialized into the dictionary of intrinsic defaults. When *dict_type* is given, it From b8db50b4586a9b6868590ea8f577ecf30e0a4823 Mon Sep 17 00:00:00 2001 From: litlighilit Date: Mon, 14 Oct 2024 17:44:47 +0800 Subject: [PATCH 3/5] gh-125436: fixup missing desc and verionchanged --- Doc/library/configparser.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Doc/library/configparser.rst b/Doc/library/configparser.rst index c3c6f1dad8405b..f761d57a60fffb 100644 --- a/Doc/library/configparser.rst +++ b/Doc/library/configparser.rst @@ -996,6 +996,13 @@ ConfigParser Objects converter gets its own corresponding :meth:`!get*` method on the parser object and section proxies. + When *allow_unnamed_section* is ``True`` (default: ``False``), + the first section name can be omitted, options with no section name + specified ahead (often called ``"Global Options"`` or + ``options in "Default Section"``) are allowed. See + `"Supported INI File Structure" section<#supported-ini-file-structure>`_ + for details. + It is possible to read several configurations into a single :class:`ConfigParser`, where the most recently added configuration has the highest priority. Any conflicting keys are taken from the more recent @@ -1045,6 +1052,9 @@ ConfigParser Objects Raise a :exc:`MultilineContinuationError` when *allow_no_value* is ``True``, and a key without a value is continued with an indented line. + .. versionchanged:: 3.13 + The *allow_unnamed_section* argument was added. + .. method:: defaults() Return a dictionary containing the instance-wide defaults. From 5dea0655ee955adab25cfa3c57f60fc6cb162220 Mon Sep 17 00:00:00 2001 From: litlighilit Date: Tue, 15 Oct 2024 08:41:08 +0800 Subject: [PATCH 4/5] gh-125436: add `*`; apply suggestion from @picnixz - add space in ref before `<` char of URL to fix compile error; - add `*` to mark keywords (fixup) of ConfigParser; - simpify desc for `allow_unnamed_section` param; --- Doc/library/configparser.rst | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Doc/library/configparser.rst b/Doc/library/configparser.rst index f761d57a60fffb..da7fc6693fa1f9 100644 --- a/Doc/library/configparser.rst +++ b/Doc/library/configparser.rst @@ -942,7 +942,7 @@ interpolation if an option used is not defined elsewhere. :: ConfigParser Objects -------------------- -.. class:: ConfigParser(defaults=None, dict_type=dict, allow_no_value=False, \ +.. class:: ConfigParser(defaults=None, dict_type=dict, allow_no_value=False, *, \ delimiters=('=', ':'), comment_prefixes=('#', ';'), \ inline_comment_prefixes=None, strict=True, \ empty_lines_in_values=True, \ @@ -997,11 +997,8 @@ ConfigParser Objects object and section proxies. When *allow_unnamed_section* is ``True`` (default: ``False``), - the first section name can be omitted, options with no section name - specified ahead (often called ``"Global Options"`` or - ``options in "Default Section"``) are allowed. See - `"Supported INI File Structure" section<#supported-ini-file-structure>`_ - for details. + the first section name can be omitted. See the + `"Unnamed Sections" section <#unnamed-sections>`_. It is possible to read several configurations into a single :class:`ConfigParser`, where the most recently added configuration has the From 673a26c71a0c39290cbe49c4774aa36741b7cdd3 Mon Sep 17 00:00:00 2001 From: lit Date: Fri, 18 Oct 2024 01:38:12 +0800 Subject: [PATCH 5/5] gh-125436: update signature of RawConfigParser... - apply suggestion from https://github.com/python/cpython/pull/125437#pullrequestreview-2375551319 - also update for `versionchanged` for params of RawConfigParser --- Doc/library/configparser.rst | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Doc/library/configparser.rst b/Doc/library/configparser.rst index da7fc6693fa1f9..ac0f3fca3d72fd 100644 --- a/Doc/library/configparser.rst +++ b/Doc/library/configparser.rst @@ -1308,18 +1308,30 @@ RawConfigParser Objects comment_prefixes=('#', ';'), \ inline_comment_prefixes=None, strict=True, \ empty_lines_in_values=True, \ - default_section=configparser.DEFAULTSECT[, \ - interpolation]) + default_section=configparser.DEFAULTSECT, \ + interpolation=BasicInterpolation(), converters={}, \ + allow_unnamed_section=False) Legacy variant of the :class:`ConfigParser`. It has interpolation disabled by default and allows for non-string section names, option names, and values via its unsafe ``add_section`` and ``set`` methods, as well as the legacy ``defaults=`` keyword argument handling. + .. versionchanged:: 3.2 + *allow_no_value*, *delimiters*, *comment_prefixes*, *strict*, + *empty_lines_in_values*, *default_section* and *interpolation* were + added. + + .. versionchanged:: 3.5 + The *converters* argument was added. + .. versionchanged:: 3.8 The default *dict_type* is :class:`dict`, since it now preserves insertion order. + .. versionchanged:: 3.13 + The *allow_unnamed_section* argument was added. + .. note:: Consider using :class:`ConfigParser` instead which checks types of the values to be stored internally. If you don't want interpolation, you