This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jugmac00
Recipients jugmac00
Date 2020-10-07.07:21:09
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1602055269.91.0.0897084304522.issue41963@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2020-10-07 07:21:09jugmac00setrecipients: + jugmac00
2020-10-07 07:21:09jugmac00setmessageid: <1602055269.91.0.0897084304522.issue41963@roundup.psfhosted.org>
2020-10-07 07:21:09jugmac00linkissue41963 messages
2020-10-07 07:21:09jugmac00create