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

ConfigParser parsing failures with default_section and ExtendedInterpolation options #71018

Closed
frispete mannequin opened this issue Apr 22, 2016 · 3 comments
Closed

ConfigParser parsing failures with default_section and ExtendedInterpolation options #71018

frispete mannequin opened this issue Apr 22, 2016 · 3 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@frispete
Copy link
Mannequin

frispete mannequin commented Apr 22, 2016

BPO 26831
Nosy @ambv
Files
  • configparser-test.py: show parsing failures
  • 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 = <Date 2016-04-23.08:53:44.069>
    created_at = <Date 2016-04-22.22:37:37.961>
    labels = ['invalid', 'type-bug', 'library']
    title = 'ConfigParser parsing failures with default_section and ExtendedInterpolation options'
    updated_at = <Date 2022-02-17.12:22:23.632>
    user = 'https://bugs.python.org/frispete'

    bugs.python.org fields:

    activity = <Date 2022-02-17.12:22:23.632>
    actor = 'lukasz.langa'
    assignee = 'none'
    closed = True
    closed_date = <Date 2016-04-23.08:53:44.069>
    closer = 'SilentGhost'
    components = ['Library (Lib)']
    creation = <Date 2016-04-22.22:37:37.961>
    creator = 'frispete'
    dependencies = []
    files = ['42573']
    hgrepos = []
    issue_num = 26831
    keywords = []
    message_count = 3.0
    messages = ['264031', '264059', '413399']
    nosy_count = 3.0
    nosy_names = ['frispete', 'SilentGhost', 'lukasz.langa']
    pr_nums = []
    priority = 'normal'
    resolution = 'not a bug'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue26831'
    versions = ['Python 3.4']

    @frispete
    Copy link
    Mannequin Author

    frispete mannequin commented Apr 22, 2016

    ConfigParser fails in interesting ways, when using default_section and ExtendedInterpolation options. Running the attached script results in:

    ConfigParser() with expected result:
    global: [('loglevel', 'WARNING'), ('logfile', '-')]
    section1: [('key_a', 'value'), ('key_b', 'morevalue')]
    section2: [('key_c', 'othervalue'), ('key_d', 'differentvalue')]

    ConfigParser(default_section='global') mangles section separation:
    section1: [('loglevel', 'WARNING'), ('logfile', '-'), ('key_a', 'value'), ('key_b', 'morevalue')]
    section2: [('loglevel', 'WARNING'), ('logfile', '-'), ('key_c', 'othervalue'), ('key_d', 'differentvalue')]

    ConfigParser(interpolation=ExtendedInterpolation) fails with strange error:
    Traceback (most recent call last):
      File "configparser-test.py", line 36, in <module>
        print_sections(cp)
      File "configparser-test.py", line 21, in print_sections
        cp.read_string(__doc__)
      File "/usr/lib64/python3.4/configparser.py", line 696, in read_string
        self.read_file(sfile, source)
      File "/usr/lib64/python3.4/configparser.py", line 691, in read_file
        self._read(f, source)
      File "/usr/lib64/python3.4/configparser.py", line 1089, in _read
        self._join_multiline_values()
      File "/usr/lib64/python3.4/configparser.py", line 1101, in _join_multiline_values
        name, val)
    TypeError: before_read() missing 1 required positional argument: 'value'

    while it is expected to behave identical.

    @frispete frispete mannequin added the stdlib Python modules in the Lib dir label Apr 22, 2016
    @SilentGhost
    Copy link
    Mannequin

    SilentGhost mannequin commented Apr 23, 2016

    I think there is some misunderstanding of what default_section is supposed to do, in fact in provides default values for *other* section, as the documentation says, it doesn't mangle section separation.

    In case of ExtendedInterpolation, the interpolation argument needs to be instantiated, i.e. the call should be:
    ConfigParser(interpolation=ExtendedInterpolation())

    @SilentGhost SilentGhost mannequin closed this as completed Apr 23, 2016
    @SilentGhost SilentGhost mannequin added invalid type-bug An unexpected behavior, bug, or error labels Apr 23, 2016
    @ambv
    Copy link
    Contributor

    ambv commented Feb 17, 2022

    Note: the problem here was due to passing ExtendedInterpolation (the class) instead of ExtendedInterpolation() (the object). This is now fixed through BPO-41086.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant