Skip to content
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

[doc] configparser: modifying default_section at runtime #71770

Closed
rk mannequin opened this issue Jul 21, 2016 · 6 comments
Closed

[doc] configparser: modifying default_section at runtime #71770

rk mannequin opened this issue Jul 21, 2016 · 6 comments
Labels
3.9 only security fixes 3.10 only security fixes 3.11 only security fixes docs Documentation in the Doc dir easy stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@rk
Copy link
Mannequin

rk mannequin commented Jul 21, 2016

BPO 27583
Nosy @bitdancer, @ambv, @wm75, @slateny
PRs
  • gh-71770: Add more details on behavior of configparser's default_section #31562
  • Files
  • bug_configparser_default_section.py: testcase (for Py3)
  • 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:

    assignee = None
    closed_at = None
    created_at = <Date 2016-07-21.12:54:13.554>
    labels = ['easy', 'type-bug', '3.9', '3.10', '3.11', 'library', 'docs']
    title = '[doc ] configparser: modifying default_section at runtime'
    updated_at = <Date 2022-02-25.04:50:50.798>
    user = 'https://bugs.python.org/rk'

    bugs.python.org fields:

    activity = <Date 2022-02-25.04:50:50.798>
    actor = 'slateny'
    assignee = 'docs@python'
    closed = False
    closed_date = None
    closer = None
    components = ['Documentation', 'Library (Lib)']
    creation = <Date 2016-07-21.12:54:13.554>
    creator = 'rk'
    dependencies = []
    files = ['43808']
    hgrepos = []
    issue_num = 27583
    keywords = ['patch', 'easy']
    message_count = 5.0
    messages = ['270918', '270930', '270931', '270932', '281232']
    nosy_count = 6.0
    nosy_names = ['r.david.murray', 'docs@python', 'lukasz.langa', 'wolma', 'rk', 'slateny']
    pr_nums = ['31562']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue27583'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    Linked PRs

    @rk
    Copy link
    Mannequin Author

    rk mannequin commented Jul 21, 2016

    Modifying "default_section" in the configparser at runtime does not behave as described.

    The documentation says about default_section:

    When default_section is given, it specifies the name for the special section holding default values for other sections and interpolation purposes (normally named "DEFAULT"). This value can be retrieved and changed on runtime using the default_section instance attribute.
    [https://docs.python.org/3/library/configparser.html]

    So, if I modify default_section at runtime, the default values for other sections should then come from the new default_section. But this is not the case. Instead, the default-values still come from self._default, which was set by self._read.

    So, this is either a bug in the library or a bug in the documentation.

    I've attached a testcase.

    @rk rk mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Jul 21, 2016
    @rk
    Copy link
    Mannequin Author

    rk mannequin commented Jul 21, 2016

    Verified/tested with Python 2.7.9, 3.2.6, 3.3.6, 3.4.2, 3.5.1.
    The bug exists in all versions, so I've added 3.2, 3.3, 3.4 again.

    I've also attached an updated testcase, which now works in both Python 2 and Python 3.

    @rk
    Copy link
    Mannequin Author

    rk mannequin commented Jul 21, 2016

    (removed Python 2.7, since default_section was not supported there)

    @bitdancer
    Copy link
    Member

    We use the versions field to indicate which versions it might get fixed in. Since this is not a security issue, that would be 3.5 and 3.6, if it doesn't affect 2.7. If we decide to make the code match the docs, it will probably only get fixed in 3.6, since it is a behavior change.

    @wm75
    Copy link
    Mannequin

    wm75 mannequin commented Nov 19, 2016

    Well, you *can* change the value at runtime as you are demonstrating in your script, but you are misunderstanding the effect this will have. It *won't* cause a reevaluation of an already parsed config file. Instead it will affect the writing of the parsed settings to a new config file.
    This is explained a bit further up in the documentation of the module:
    https://docs.python.org/3/library/configparser.html#customizing-parser-behaviour
    where it says: "Its current value can be retrieved using the parser_instance.default_section attribute and may be modified at runtime (i.e. to convert files from one format to another)."

    So maybe this hint could be repeated in the actual parameter description of https://docs.python.org/3/library/configparser.html#configparser-objects to avoid confusion, but I don't think there is a bug here.

    @bitdancer bitdancer added docs Documentation in the Doc dir 3.7 (EOL) end of life labels Nov 19, 2016
    @iritkatriel iritkatriel added easy 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes and removed 3.7 (EOL) end of life labels Dec 9, 2021
    @iritkatriel iritkatriel changed the title configparser: modifying default_section at runtime [doc ] configparser: modifying default_section at runtime Dec 9, 2021
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    hugovk added a commit that referenced this issue Sep 7, 2023
    miss-islington pushed a commit to miss-islington/cpython that referenced this issue Sep 7, 2023
    …t_section (pythonGH-31562)
    
    (cherry picked from commit 891236f)
    
    Co-authored-by: Stanley <[email protected]>
    Co-authored-by: Hugo van Kemenade <[email protected]>
    miss-islington pushed a commit to miss-islington/cpython that referenced this issue Sep 7, 2023
    …t_section (pythonGH-31562)
    
    (cherry picked from commit 891236f)
    
    Co-authored-by: Stanley <[email protected]>
    Co-authored-by: Hugo van Kemenade <[email protected]>
    @hugovk hugovk changed the title [doc ] configparser: modifying default_section at runtime [doc] configparser: modifying default_section at runtime Sep 7, 2023
    @hugovk
    Copy link
    Member

    hugovk commented Sep 7, 2023

    Thanks, fixed via #31562 and backports to 3.11.

    @hugovk hugovk closed this as completed Sep 7, 2023
    hugovk added a commit that referenced this issue Sep 7, 2023
    …lt_section (GH-31562) (#109089)
    
    Co-authored-by: Stanley <[email protected]>
    Co-authored-by: Hugo van Kemenade <[email protected]>
    Yhg1s pushed a commit that referenced this issue Sep 8, 2023
    …lt_section (GH-31562) (#109088)
    
    gh-71770: Add more details on behavior of configparser's default_section (GH-31562)
    (cherry picked from commit 891236f)
    
    Co-authored-by: Stanley <[email protected]>
    Co-authored-by: Hugo van Kemenade <[email protected]>
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes 3.10 only security fixes 3.11 only security fixes docs Documentation in the Doc dir easy stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants