-
Notifications
You must be signed in to change notification settings - Fork 9
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
RFC: define a single otk.op.join
#8
Conversation
This was a question I've been asking and was going to put it down, but it seems you have beaten me to asking it :) |
My reasoning for this was that having separate operations per type allows us to have separate arguments per type. For a map erroring on duplicates (or overwriting them) makes sense. For a sequence less so. |
Thanks! I'm not sure I follow - if |
Wanting to define the behavior, for example (don't pin me on this one ;)).
The |
Thank you! That is interesting (and the context I was looking for!). We could start with what popular languages like python are doing:
I like the idea of the users having a say here though, so once the above is not good enough anymore, we could add rules like
and then we could decide to error if "overwrite" is used on sequences. Or we could also "bend" the definition and "de-duplicate/replace/overwrite" keys in a seqence if later sequences also define it (not sure I like it or not but it's an option :) |
bf8327d
to
1e25c66
Compare
I fixed the conflicts, sorry that this took me a bit |
1e25c66
to
b2e0ed6
Compare
b2e0ed6
to
37115c7
Compare
37115c7
to
dd9c6e3
Compare
dd9c6e3
to
6349403
Compare
This does still need the implementation change at: https://github.com/osbuild/otk/blob/main/src/otk/directive.py#L107-L154 and https://github.com/osbuild/otk/blob/main/src/otk/transform.py#L51-L52 :) |
6349403
to
73775a9
Compare
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.
Duplicate keys in maps are considered an error.
It might be nice to have a test for this (unless there is one already and I missed it)
I wonder if we can simply avoid having the user care about the type when doing a join operation. It seems mostly a burden to the user and we need to check during compilation of the otk file anyway so maybe we can just leave it out? P.S. Having an example use-case for both would be really good, I'm wonder if we only should add things to the spec once we actually use it in the example/* tree ?
73775a9
to
9ead440
Compare
@tree.must_pass(tree.has_keys(["values"])) | ||
def op_map_merge(ctx: Context, tree: dict[str, Any]) -> Any: | ||
"""Merge two dictionaries. Keys from the second dictionary overwrite keys | ||
def _op_map_join(ctx: Context, values: List[dict]) -> Any: |
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.
List
wasn't imported from typing
.
There's no test for it (yet) and the code doesn't actually check this: Line 148 in 9ead440
It should straightforward to add, or reconsider if it should be an error. |
Yeah doesn't have to be for this PR :) |
9ead440
to
befed85
Compare
@mvo5 you imported |
Following the recent spec update the code is now updated as well to have a single `otk.op.join` instead of the previous: - otk.op.map.merge - otk.op.seq.merge
befed85
to
1bc69c5
Compare
Silly me, sorry for that! Fwiw, |
I wonder if we can simply avoid having the user care about the type when doing a join operation. It seems mostly a burden to the user and we need to check during compilation of the otk file anyway so maybe we can just leave it out?
P.S. Having an example use-case for both would be really good, I'm wonder if we only should add things to the spec once we actually use it in the example/* tree ?