Issue 33333: ConfigParser.items returns items present in DEFAULTSECT when section argument given. (original) (raw)

Created on 2018-04-22 11:20 by chrBrd, last changed 2022-04-11 14:58 by admin.

Pull Requests
URL Status Linked Edit
PR 6446 chrBrd,2018-04-22 11:27
PR 6567 closed chrBrd,2018-04-22 21:13
Messages (4)
msg315608 - (view) Author: Chris Bradbury (chrBrd) Date: 2018-04-22 11:20
According to `ConfigParser.items` docs: > When section is not given, return a list of section_name, section_proxy pairs, including DEFAULTSECT. > Otherwise, return a list of name, value pairs for the options in the given section. Optional arguments have the same meaning as for the get() method. https://docs.python.org/3/library/configparser.html#configparser.ConfigParser.items However due to `d = self._defaults.copy()` on line 843 of configparser.py the default section is always included, even when a section argument is specified.
msg315625 - (view) Author: Chris Bradbury (chrBrd) Date: 2018-04-22 18:03
The fix for the actual issue is quite trivial (and should fix bpo-33251 at the same time). However `ExtendedInterpolation::_interpolate_some` relies on the options from the default section always being returned. Not only does this make the fix more complicated, it also makes me worry that aligning behaviour to match the documentation (which I personally feel makes more sense) will breake backwards compatibility.
msg315629 - (view) Author: Ɓukasz Langa (lukasz.langa) * (Python committer) Date: 2018-04-22 21:38
See line 379 in configparser.py. BasicInterpolation is also assumed to work for values from the default section. This is why the default section exists in the first place. More importantly, as you're pointing out, even though this is an omission of the documentation, existing code in the wild probably assumes that `items()` include pairs from the default section. This is how ConfigParser worked in Python 2. If you don't want this behavior, use cfgparser[section].items() instead which does what you want. If you think this is helpful, go ahead and extend the documentation of ConfigParser.items() to point out this weirdness. But we won't be going forward with PR 6567.
msg315630 - (view) Author: Chris Bradbury (chrBrd) Date: 2018-04-22 21:48
I'll make the documentation changes instead, not overly surprised to hear this is intentional.
History
Date User Action Args
2022-04-11 14:58:59 admin set github: 77514
2018-04-22 22:05:28 chrBrd set status: closed -> opennosy: + docs@pythonassignee: docs@pythoncomponents: + Documentation, - Library (Lib)resolution: not a bug ->
2018-04-22 21:53:20 chrBrd set resolution: not a bug
2018-04-22 21:48:56 chrBrd set status: open -> closedmessages: + stage: patch review -> resolved
2018-04-22 21:38:17 lukasz.langa set messages: +
2018-04-22 21:13:47 chrBrd set pull_requests: + <pull%5Frequest6263>
2018-04-22 18:03:14 chrBrd set messages: +
2018-04-22 11:31:36 serhiy.storchaka set nosy: + lukasz.langacomponents: + Library (Lib)
2018-04-22 11:27:55 chrBrd set keywords: + patchstage: patch reviewpull_requests: + <pull%5Frequest6261>
2018-04-22 11:20:36 chrBrd create