Skip to content

ConfigParser parsing failures with default_section and ExtendedInterpolation options #71018

Closed

Description

@frispete
mannequin
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']

    Activity

    1. frispete commented on Apr 22, 2016

      frispetemannequin
      MannequinAuthor

      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.

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      on Apr 22, 2016
    3. SilentGhost commented on Apr 23, 2016

      SilentGhostmannequin
      Mannequin

      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())

    4. ambv commented on Feb 17, 2022

      @ambv
      Contributor

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

    5. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions