Support comments as part of multiline values in configparser
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
Feature or enhancement
Proposal:
Today's configparser module does not consider lines being properly indented and starting with a comment_prefixes to be part of a multiline value. This can lead to unintended data loss during reading an INI file as:
config.ini
# I am a comment
# I am also a comment
[dummy]
# I am a comment
key = I am a multiline
# I am a comment
# multiline part which is not considered but should be
being again part
# I am a comment
test.py
import configparser
config = configparser.ConfigParser(comment_prefixes='#', interpolation=None, inline_comment_prefixes=None)
config.read('config.ini')
print(config['dummy']['key'])
# output: 'I am a multiline\nbeing again part'
# expected output: 'I am a multiline\n# multiline part which is not considered but should be\nbeing again part''
Therefore, I would propose to add a new parameter allow_comment_in_value (default False) in the ConfigParser class to support such scenarios. Please note that in this scenario the comment_prefixes is set to '#' and any interpolation is disabled!
Thanks and best regards!
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the ConfigParser entry point and reproduce the behavior using the config.ini and test.py example in the issue. Trace how comment_prefixes and multiline values are handled, then add coverage for the proposed option. Done means the indented comment is preserved in the multiline value while existing behavior remains unchanged by default.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100