]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.10] bpo-41963: document that ConfigParser strips off comments (GH-26197) (GH-26214)
authorŁukasz Langa <lukasz@langa.pl>
Tue, 18 May 2021 17:03:09 +0000 (19:03 +0200)
committerGitHub <noreply@github.com>
Tue, 18 May 2021 17:03:09 +0000 (19:03 +0200)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Laura Gutierrez Funderburk <58710704+lgfunderburk@users.noreply.github.com>
Co-authored-by: Jürgen Gmach <juergen.gmach@googlemail.com>
(cherry picked from commit 02ee8191263848f8c8999f72286148946b83e5c9)

Doc/library/configparser.rst
Lib/configparser.py
Misc/NEWS.d/next/Documentation/2021-05-17-20-03-47.bpo-41963.eUz9_o.rst [new file with mode: 0644]

index 646e8a317f52c3e314de7677b26656ee5cc29fef..b0c2a2cfb06a47886ed293042f871cc4efc0a845 100644 (file)
@@ -1153,6 +1153,13 @@ ConfigParser Objects
       *space_around_delimiters* is true, delimiters between
       keys and values are surrounded by spaces.
 
+   .. note::
+
+      Comments in the original configuration file are not preserved when
+      writing the configuration back.
+      What is considered a comment, depends on the given values for
+      *comment_prefix* and *inline_comment_prefix*.
+
 
    .. method:: remove_option(section, option)
 
index 3b4cb5e6b2407f7b10989444caf64b1bdc8914de..2f45e242b49426d0c55b104bd48a41230e93a01e 100644 (file)
@@ -908,6 +908,9 @@ class RawConfigParser(MutableMapping):
 
         If `space_around_delimiters' is True (the default), delimiters
         between keys and values are surrounded by spaces.
+
+        Please note that comments in the original configuration file are not
+        preserved when writing the configuration back.
         """
         if space_around_delimiters:
             d = " {} ".format(self._delimiters[0])
@@ -1006,7 +1009,7 @@ class RawConfigParser(MutableMapping):
         Configuration files may include comments, prefixed by specific
         characters (`#' and `;' by default). Comments may appear on their own
         in an otherwise empty line or may be entered in lines holding values or
-        section names.
+        section names. Please note that comments get stripped off when reading configuration files.
         """
         elements_added = set()
         cursect = None                        # None, or a dictionary
diff --git a/Misc/NEWS.d/next/Documentation/2021-05-17-20-03-47.bpo-41963.eUz9_o.rst b/Misc/NEWS.d/next/Documentation/2021-05-17-20-03-47.bpo-41963.eUz9_o.rst
new file mode 100644 (file)
index 0000000..b9fe722
--- /dev/null
@@ -0,0 +1 @@
+Document that ``ConfigParser`` strips off comments when reading configuration files.
\ No newline at end of file