You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Lack of control over behavior of Duplicate Sections and Options while reading with ConfigParser. #107428
I am confident this is a bug in CPython,
not a bug in a third-party project
I have searched the CPython issue tracker,
and am confident this bug has not been reported before
A clear and concise description of the bug
Currently, we do not have much control over the behavior of ConfigParser when it encounters a duplicate section header or a duplicate option inside a section. It will directly raise an exception in strict mode and the read will fail. In case of non-strict mode, it will parse the config but there's no way to add custom behavior to it.
For example, I had a business requirement where we had to log a warning incase a duplicate section/option is encountered. But to do this I had to subclass the ConfigParser and override the entire _read method with a lot of code duplication just to add two log lines.
Another use case would be having different duplicate handling for Sections and Options.
When I do ConfigParser().read("config.ini"), this will raise a DuplicateOptionError and the code will stop executing. If I pass strict=False, it will parse as expected but there is no way to intimate to the end user that the config contains duplicates.
Activity
serv-inc commentedon Aug 5, 2026
another use case are systemd config files, e.g. Environment can have several values