Repository navigation
Make multi-line values opt-in, add merged, define repeated keys - #41
Merged
Merged
Conversation
multiline_values is a new Inifile option, false by default. When it is
off, every line stands on its own and leading whitespace is ignored, as
in IniFile 0.5, so indentation no longer changes the meaning of a file
by default. write throws an ArgumentError naming the key and section for
a value that contains a newline, since it could not be read back. The
check runs before anything is written, so write(filename, ini) does not
empty an existing file. Display does not throw.
merged(ini) returns an OrderedDict{String,String} with the defaults and
then each section's keys, in section order, where a later section
overrides an earlier one. Sections are ordered by their first header,
and a repeated header adds to the earlier section, as in Python 2's
ConfigParser.
Repeated keys and sections are now documented and tested: within a
section the last value wins and the key keeps its first position, and a
repeated section header adds to the earlier section. They are never an
error, with or without strict.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #41 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 1 1
Lines 146 172 +26
=========================================
+ Hits 146 172 +26 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
- print, string and interpolation give the file contents without the multi-line check, so logging an Inifile never throws. Only write checks. - write(filename, ini) delegates to write(io, ini) after its check. - Say what a multi-line value loses in a round trip: surrounding whitespace on each line, trailing blank lines, and lines starting with # or ;. Add a test that pins this down. - List write's new ArgumentError in the 0.6 upgrade guide. - Drop the claim that merged matches Python's ConfigParser, which also lowercases keys and strips inline comments. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Settles three things before 0.6.0 is registered, since changing them afterwards would be breaking.
Multi-line values are opt-in
multiline_values,falseby default. When it is off, every line stands on its own and leading whitespace is ignored, as in 0.5. An indented line is a separate entry, or malformed if it has no=or:.multiline_values=true, a line indented more than the line that started an entry continues its value, as before.writethrows anArgumentErrornaming the key and section for a value that contains a newline, because it could not be read back. The check runs before anything is written, sowrite(filename, ini)leaves an existing file alone. REPL display,print,stringand interpolation never throw. Onlywritechecks.multiline_values=true, a round trip keeps the lines of a value but not the whitespace around each line, trailing blank lines, or lines that start with#or;. The docs now say so, and a test pins it down.merged(ini)OrderedDict{String,String}: the defaults, then each section's keys in section order, with a later section overriding an earlier one. Each key keeps the position where it first appeared.mergedrather thanflatten, which would clash withBase.Iterators.flatten.mergedis not defined in Base, Core or the standard libraries checked.ConfigParser. I checked the repeated-section case against Python 3'sconfigparserwithstrict=False. Python also lowercases keys, and Python 2 strips;comments, so for Python files uselowercase_keys=trueandinline_comment_prefixes=(";",)to get the same keys.Repeated keys and sections
mergeda later section wins even over a line further down the file in a repeated, earlier section.strict.strictonly concerns malformed lines, so Circuitscape can usestrict=trueand still override a key by appending a line. There is no option to reject duplicates; if one is added later, it should be separate fromstrict.Docstrings (module,
Inifile,read,write,set,merged) and the README are updated. The 0.6 upgrade guide listswrite's newArgumentError. The test suite grows from 247 to 292 tests, covering every combination ofstrictandmultiline_valuesfor repeated keys.Review
An independent review found that
printandstringthrew for multi-line values, that the docs overstated the multi-line round trip, and that themergeddocstring overstated equivalence with Python. Those are fixed in ad7119f. Two suggestions are left out of this PR:=or:are still written out broken, as in 0.5. That could be a follow-up.writethrow for things like trailing spaces, which INI files normally drop.🤖 Generated with Claude Code