Terry J. Reedy added the comment:

Discussion continues because my close message was, I now realize, incomplete 
and therefore unsatisfying.  Ditto for the doc.  So I complete my close message 
here and reopen issue to augment the doc.

The discussion has so far has glossed over the key question: "What is a legal 
section name?"  Pulling the answer from the doc was a challenge. It uses 'legal 
section name', once, as if one should already know. Reading further, I found 
the answer: there is no (fixed) answer!

The legal section name for a particular parser is determined by its .SECTCRE 
class attribute.
'''configparser.SECTCRE
    A compiled regular expression used to parse section headers. The default 
matches [section] to the name "section".'''  (This neglects to say whether the 
closing ']' is the first or last ']' on the line after the opening '['.) A 
non-verbose version of the default is
re.compile(r"\[(?P<header>[^]]+)\]").

I propose adding near the top of the doc:
"By default, a legal section name can be any string that does not contain '\n' 
or ']'.  To change this, see configparser.SECTCRE."

So my response to Miloš should have been to set SECTCRE to something like p 
below.

>>> p = re.compile(r"\[(?P<header>.*)\]")
>>> m = p.search("[Test[2]_foo]")
>>> m.group('header')
'Test[2]_foo'

Additional note: Postel's principle was formulated for internet protocols, 
which .ini files are not.  In any case, it is not a Python design principle.  
Neither is "always check user input", which amounts to 'look before you leap'.  
So I will not debate these. However, "Errors should never pass silently." is 
#10 on the Zen of Python ('import this') and that I do attend to.

----------
assignee:  -> docs@python
components: +Documentation
nosy: +docs@python
resolution: rejected -> 
stage: test needed -> needs patch
status: closed -> open
versions: +Python 2.7, Python 3.4, Python 3.6

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue20923>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to