[New-bugs-announce] [issue41963] ConfigParser: stripping of comments should be documented

Jürgen Gmach report at bugs.python.org
Wed Oct 7 03:21:09 EDT 2020


New submission from Jürgen Gmach <juergen.gmach at googlemail.com>:

While working on `tox-ini-fmt`, a formatter for - you guessed it - `tox.ini` files, I noticed ConfigParser strips comments when reading a config file.

( https://github.com/tox-dev/tox-ini-fmt/issues/34 )

While reasonable, this behaviour is surprising, as it is neither documented at https://docs.python.org/3/library/configparser.html nor in the docstrings (read and _read) which I read at first.

The stripping of comments is only documented with inline comments

https://github.com/jugmac00/cpython/blob/610a60c601fb4380eee30e15be1cd4dcbdaeec4c/Lib/configparser.py#L1019

and

https://github.com/jugmac00/cpython/blob/610a60c601fb4380eee30e15be1cd4dcbdaeec4c/Lib/configparser.py#L1031

Once I found these comments, I was surprised once again, as in my code the inline comments were not stripped. After some more pdb-ing and reading the source of ConfigParser, I noticed that - while comments have a default value, inline comments do not - and that is why when you read a config file, some comments get removed and others not.

I'd like to work on a pull request to document this behaviour, both in the official documentation and in the docstrings of the read and the _read methods.

----------
messages: 378146
nosy: jugmac00
priority: normal
severity: normal
status: open
title: ConfigParser: stripping of comments should be documented

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41963>
_______________________________________


More information about the New-bugs-announce mailing list