-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Internal, New Feature, No Breaking] Rewrite constructor part 1 #173
Open
Paalon
wants to merge
16
commits into
JuliaData:master
Choose a base branch
from
Paalon:schema-constructor
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains 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
Define constructors for each schema. However, it is not completed. So this is the part 1. Because the two tags: `!!merge` and `!!value` remain in the construction of mapping. I added a bit modification in the constructor of `ConstructorError` to increase the readability. And also I added some TODO comments and my thoughts.
Paalon
changed the title
Rewrite constructor part 1
[Internal, New Feature, No Breaking] Rewrite constructor part 1
Jun 16, 2024
Is this still live? |
function add_multi_constructor!(func::Function, constructor::Constructor, tag::Union{String, Nothing}) | ||
constructor.yaml_multi_constructors[tag] = func | ||
constructor | ||
end | ||
|
||
Constructor(::Nothing) = Constructor(Dict{String,Function}()) | ||
SafeConstructor(constructors::Dict = Dict(), multi_constructors::Dict = Dict()) = Constructor(merge(copy(default_yaml_constructors), constructors), multi_constructors) | ||
# Paalon: I don't know what is safe. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe unsafe refers to things like this that you can do in pyyaml:
$ python
Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import yaml
>>> yaml.load("""!!python/object/apply:subprocess.Popen\n- [echo, hello]\n""", Loader=yaml.Loader)
<Popen: returncode: None args: ['echo', 'hello']>
>>> hello
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.
Abstract
Detail
Rewrite construct functions in
src/constructor.jl
. Add constructor functions for the three essential YAML schemata. However this is not completed because processing for tag!!merge
and!!value
are still tightly connected toconstruct_mapping
etc.ConstructorError
.flatten_mapping
to always returnnothing
.src/constructor.jl
tosrc/constructor_yaml_jl_0_4_10.jl
for the YAML.jl 0.4.10 schema:construct_yaml_null
→construct_yaml_jl_0_4_10_schema_null
bool_values
→yaml_jl_0_4_10_schema_bool_values
construct_yaml_bool
→construct_yaml_jl_0_4_10_schema_bool
construct_yaml_int
→construct_yaml_jl_0_4_10_schema_int
construct_yaml_float
→construct_yaml_jl_0_4_10_schema_float
timestamp_pat
→yaml_jl_0_4_10_schema_timestamp_regex
construct_yaml_timestamp
→construct_yaml_jl_0_4_10_schema_timestamp
construct_yaml_omap
→construct_yaml_jl_0_4_10_schema_timestamp
construct_yaml_pairs
→construct_yaml_jl_0_4_10_schema_timestamp
construct_yaml_set
→construct_yaml_jl_0_4_10_schema_set
construct_yaml_str
→construct_yaml_jl_0_4_10_schema_str
construct_yaml_seq
→construct_yaml_jl_0_4_10_schema_seq
construct_yaml_map
→construct_yaml_jl_0_4_10_schema_map
construct_yaml_object
→construct_yaml_jl_0_4_10_schema_object
construct_yaml_binary
→construct_yaml_jl_0_4_10_schema_binary
construct_undefined
→construct_undefined_yaml_jl_0_4_10_schema
: this requires test's modification.default_yaml_constructors
→yaml_jl_0_4_10_schema_constructors
: this requires test's modification.src/constructor_failsafe.jl
,src/constructor_json.jl
andsrc/constructor_core.jl
.This PR does not change any commonly used API (
load
,load_all
,write
, etc.).