Message378146
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. |
|
Date |
User |
Action |
Args |
2020-10-07 07:21:09 | jugmac00 | set | recipients:
+ jugmac00 |
2020-10-07 07:21:09 | jugmac00 | set | messageid: <1602055269.91.0.0897084304522.issue41963@roundup.psfhosted.org> |
2020-10-07 07:21:09 | jugmac00 | link | issue41963 messages |
2020-10-07 07:21:09 | jugmac00 | create | |
|