You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Change default parser mode to json_or_yaml and say which format failed in parse errors - #1004
Making json the default parser_mode (#997) turned out to be very disruptive, since YAML configs and values like --list=[a, b] stopped working. This PR replaces it with a less disruptive default:
New json_or_yaml parser mode, now the default. It parses as JSON and, only if that fails and pyyaml is installed, as YAML. Valid JSON parses the same whether or not pyyaml is installed, and anything that worked with the v4 yaml default keeps working when pyyaml is installed. Dumps, e.g. --print_config, are YAML when pyyaml is installed, otherwise JSON.
Parse errors now say which format failed, e.g. Failed to parse as JSON: .... In json mode, a value that parses as a YAML mapping or list gets a hint to use parser_mode='json_or_yaml'. Previously a YAML config given in json mode only showed a misleading Expecting value: line 1 column 1.
Removed the parser_mode setting of set_parsing_settings and the JSONARGPARSE_PARSER_MODE environment variable (both unreleased). They were added to undo the strict json default, and with json_or_yaml they are no longer needed.
The jsonnet parser mode accepts YAML again, as in v4, but only for Jsonnet syntax errors, so evaluation errors are no longer hidden by a YAML parse.
Fixed the docs of JSONARGPARSE_DEFAULT_ENV and JSONARGPARSE_ALLOW_ABBREV to say how they interact with parsers given default_env or allow_abbrev explicitly.
✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (5070670) to head (1ad358d). ⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.
The PR makes json_or_yaml the default parser mode, adds format-specific parse errors, restores YAML fallback in Jsonnet mode, and updates dump behavior and documentation.
JSON is tried before optional YAML parsing; default dumps use YAML when PyYAML is installed.
Three error-handling paths need correction: JSON provenance lookup, Jsonnet evaluation fallback, and malformed unvalidated typed values.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Config or argument value] --> B{Parser mode}
B -->|json_or_yaml| C[Try JSON]
C -->|fails; PyYAML installed| D[Try YAML]
B -->|jsonnet| E[Evaluate Jsonnet]
E -->|RuntimeError| D
C -->|succeeds| F[Validate value]
D -->|succeeds| F
F -->|validation error with config source| G[Look up source position]
G --> H[Compose file as YAML]
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
enhancementNew feature or requestrefactorImprovements to the quality of the code
2 participants
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.
What does this PR do?
Making
jsonthe defaultparser_mode(#997) turned out to be very disruptive, since YAML configs and values like--list=[a, b]stopped working. This PR replaces it with a less disruptive default:json_or_yamlparser mode, now the default. It parses as JSON and, only if that fails andpyyamlis installed, as YAML. Valid JSON parses the same whether or notpyyamlis installed, and anything that worked with the v4yamldefault keeps working whenpyyamlis installed. Dumps, e.g.--print_config, are YAML whenpyyamlis installed, otherwise JSON.Failed to parse as JSON: .... Injsonmode, a value that parses as a YAML mapping or list gets a hint to useparser_mode='json_or_yaml'. Previously a YAML config given injsonmode only showed a misleadingExpecting value: line 1 column 1.parser_modesetting ofset_parsing_settingsand theJSONARGPARSE_PARSER_MODEenvironment variable (both unreleased). They were added to undo the strictjsondefault, and withjson_or_yamlthey are no longer needed.jsonnetparser mode accepts YAML again, as in v4, but only for Jsonnet syntax errors, so evaluation errors are no longer hidden by a YAML parse.JSONARGPARSE_DEFAULT_ENVandJSONARGPARSE_ALLOW_ABBREVto say how they interact with parsers givendefault_envorallow_abbrevexplicitly.Before submitting