Index: Doc/library/configparser.rst =================================================================== --- Doc/library/configparser.rst (revision 61890) +++ Doc/library/configparser.rst (working copy) @@ -34,7 +34,7 @@ to other values in the same section, or values in a special ``DEFAULT`` section. Additional defaults can be provided on initialization and retrieval. Lines beginning with ``'#'`` or ``';'`` are ignored and may be used to provide -comments. +comments. Whitespace is allowed before the comment delimiter. For example:: Index: Lib/ConfigParser.py =================================================================== --- Lib/ConfigParser.py (revision 61890) +++ Lib/ConfigParser.py (working copy) @@ -451,7 +451,7 @@ break lineno = lineno + 1 # comment or blank line? - if line.strip() == '' or line[0] in '#;': + if line.strip() == '' or line.strip()[0] in '#;': continue if line.split(None, 1)[0].lower() == 'rem' and line[0] in "rR": # no leading whitespace Index: Lib/test/test_cfgparser.py =================================================================== --- Lib/test/test_cfgparser.py (revision 61890) +++ Lib/test/test_cfgparser.py (working copy) @@ -46,6 +46,8 @@ "[Spacey Bar]\n" "foo = bar\n" "[Commented Bar]\n" + " # a comment: with leading spaces\n" + " ; another : one\n" "foo: bar ; comment\n" "[Long Line]\n" "foo: this line is much, much longer than my editor\n" @@ -100,6 +102,10 @@ eq(cf.get('Long Line', 'foo'), 'this line is much, much longer than my editor\nlikes it.') + # Issue 1524825 : allow leading spaces for comments + self.failIf(cf.has_option('Commented bar', ' # a comment')) + self.failIf(cf.has_option('Commented bar', ' ; another')) + def test_case_sensitivity(self): cf = self.newconfig() cf.add_section("A")