-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ConfigParser: stripping of comments should be documented #86129
Comments
While working on 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 and 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. |
This "while comments have a default value, inline comments do not" should read "while comment prefixes have a default value, inline comment prefixes do not" |
The Python wiki mentions that "writing to an INI file will wipe out all comments". https://wiki.python.org/moin/ConfigParserExamples So, when updating the docstrings, it may be a good idea to both add a note at the read methods, that comments get ignored and to the write method(s) that on writing, the possible previous existing comments get removed. Are there any thoughts on this or should I go forward and create a pull request? |
pymotw.com shows a big red warning about comments not being preserved: |
Closing as fixed in gh-26197. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: