Skip to content

Make _compat_skip_empty_lines a per-instance attribute - #47

Open
prownd wants to merge 1 commit into
candlepin:mainfrom
prownd:make-compat_skip_empty_lines-a-per-instance-attribute-s01
Open

Make _compat_skip_empty_lines a per-instance attribute#47
prownd wants to merge 1 commit into
candlepin:mainfrom
prownd:make-compat_skip_empty_lines-a-per-instance-attribute-s01

Conversation

@prownd

@prownd prownd commented Sep 14, 2026

Copy link
Copy Markdown

INISection._compat_skip_empty_lines was a mutable set defined at class level and never re-assigned in init(), so every section of every INIConfig/RawConfigParser in the process shared the same set.

As a consequence, operations on one parser changed the values returned by another one:

>>> a = RawConfigParser()
>>> a.readfp(StringIO('[a]\nfoo = line1\n\n  line2\n'))
>>> a.get('a', 'foo')
'line1\nline2'
>>> b = RawConfigParser(); b.add_section('b'); b.set('b', 'foo', 'x')
>>> a.get('a', 'foo')
'line1\n\nline2'

Create the set in INISection.init() and keep only an immutable placeholder on the class.

INISection._compat_skip_empty_lines was a mutable set defined at class
level and never re-assigned in __init__(), so every section of every
INIConfig/RawConfigParser in the process shared the same set.

As a consequence, operations on one parser changed the values returned
by another one:

    >>> a = RawConfigParser()
    >>> a.readfp(StringIO('[a]\nfoo = line1\n\n  line2\n'))
    >>> a.get('a', 'foo')
    'line1\nline2'
    >>> b = RawConfigParser(); b.add_section('b'); b.set('b', 'foo', 'x')
    >>> a.get('a', 'foo')
    'line1\n\nline2'

Create the set in INISection.__init__() and keep only an immutable
placeholder on the class.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant