Skip to content

utils: make tidy() also clean up the first section - #48

Open
prownd wants to merge 1 commit into
candlepin:mainfrom
prownd:utils-make-tidy-also-clean-up-the-first-section-s01
Open

utils: make tidy() also clean up the first section#48
prownd wants to merge 1 commit into
candlepin:mainfrom
prownd:utils-make-tidy-also-clean-up-the-first-section-s01

Conversation

@prownd

@prownd prownd commented Sep 14, 2026

Copy link
Copy Markdown

tidy() started iterating over the top-level lines at index 1, so when a file starts directly with a section header (the common case), that first section was never passed to tidy_section() and its consecutive empty lines were kept:

>>> cfg = INIConfig(StringIO('[a]\nx = 1\n\n\n\ny = 2\n'))
>>> tidy(cfg); str(cfg)
'[a]\nx = 1\n\n\n\ny = 2\n'

Start at index 0 and only compare with the previous line when there is one.

tidy() started iterating over the top-level lines at index 1, so when
a file starts directly with a section header (the common case), that
first section was never passed to tidy_section() and its consecutive
empty lines were kept:

    >>> cfg = INIConfig(StringIO('[a]\nx = 1\n\n\n\ny = 2\n'))
    >>> tidy(cfg); str(cfg)
    '[a]\nx = 1\n\n\n\ny = 2\n'

Start at index 0 and only compare with the previous line when there
is one.
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