Fix boolean value parsing to return Python booleans #102
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.
Summary
This PR fixes #15 by implementing proper boolean parsing in the LKML parser. Boolean values like
yes
,no
,true
, andfalse
are now correctly converted to Pythonbool
objects instead of remaining as strings.Changes
Core Implementation
Modified
DictVisitor.visit_token()
inlkml/simple.py
to:QuotedSyntaxToken
) - if so, preserve as stringyes
/no
/true
/false
) to Pythonbool
objectsUpdated
DictParser.parse_any()
to handle boolean type during serialization:bool
to accepted typesyes
/no
for LKML outputTest Coverage
Added comprehensive tests in
tests/test_simple.py
:test_boolean_parsing_yes_no
- Basic yes/no conversiontest_boolean_parsing_true_false
- Basic true/false conversiontest_boolean_parsing_case_insensitive
- Case insensitive handlingtest_boolean_parsing_non_boolean_strings
- Non-boolean strings remain unchangedtest_boolean_round_trip
- Round-trip serialization works correctlytest_quoted_boolean_strings_remain_strings
- Quoted values remain as stringstest_mixed_quoted_unquoted_booleans
- Mixed quoted/unquoted in same structuretest_filter_with_quoted_boolean_values
- Filter blocks with quoted booleanstest_case_sensitivity_with_quoted_values
- Case preservation for quoted valuestest_edge_cases_quoted_vs_unquoted
- Edge cases and empty stringsExamples
Before (incorrect):
After (correct):
Behavior Summary
hidden: yes
→True
(bool)primary_key: no
→False
(bool)suggestions: true
→True
(bool)can_filter: false
→False
(bool)label: "yes"
→"yes"
(str)value: "true"
→"true"
(str)Fixes #15