15:00:41 #startmeeting Ansible Core Public IRC Meeting https://github.com/ansible/community/issues/495 15:00:41 Meeting started Thu Oct 3 15:00:41 2019 UTC. 15:00:41 This meeting is logged and archived in a public location. 15:00:41 The chair is sdoran. Information about MeetBot at http://wiki.debian.org/MeetBot. 15:00:41 Useful Commands: #action #agreed #halp #info #idea #link #topic. 15:00:41 The meeting name has been set to 'ansible_core_public_irc_meeting_https://github.com/ansible/community/issues/495' 15:01:04 #topic https://github.com/ansible/ansible/pull/53488 15:01:27 cyberpear: What would you like to discuss on this PR? 15:06:00 * cyberpear waves 15:06:27 wondering if we can resurrect it to enable using the dict() functionality as a filter 15:09:46 that way it can be used in a "pipeline" without having to wrap the whole thing in a function syntax 15:10:43 it was rejected since dict() function exists in jinja2 .. we did add backwards compat for versions of jinja2 that didn't have it 15:10:59 This is just an interface change, not adding functionality. 15:11:01 would make it possible to do `"{{ mykeys | zip(myvar) | dict }}"` instead of `"{{ dict(mykeys | zip(myvar)) }}"` 15:11:17 why is that better? 15:11:50 cyberpear: if you can convince those that voted against it, go ahead, idc either way, i do think its redundant so i wont vote for it 15:11:57 when the "pipeline" gets long, it gets confusing with lots of extra params. Left to right evaluation is easiest to read 15:12:16 s/params/parens// 15:14:15 would also allow use in a list comprehension, which doesn't work for me today 15:14:32 if I try to map('dict'), I get `no filter named 'dict'` 15:15:21 even if accepted, i would push for name change to_dict to distinguish from dict() function 15:15:21 `"{{ mykeyslists | map('zip', myvarslists) | map('dict') | list }}"` <- gives `no filter named 'dict'` 15:15:42 well, making a filter named the same as a python keyword seems fraught with peril ... it would need to be something like to_dict even if we did take it, imo 15:15:50 to_dict is fine 15:16:24 I can't see a way to make the above list comprehension example work with the existing built-in dict() function 15:16:51 I want a list of dict, not just a dict 15:18:27 `dict2items` doesn't work? 15:19:31 sdoran: no, that creates dicts with just 2 items 15:19:47 it kind of does but key and value are the keys of the dict 15:20:03 not what most expect from dict()/to_dict 15:20:21 map is a pita, i typically replace the whole expression with a custom filter 15:20:49 I've run into needs for this too- so long as to_dict filter stays an extremely thin wrapper over dict() without a lot of "value add" I could probably be convinced to +1 it 15:21:06 (map is built-in and doesn't require extra dependencies) 15:21:32 cyberpear: i think he jsut gets perl flashbacks with map() 15:22:17 feel free to use my closed PR (or not) if you want to implement to_dict 15:22:50 he .. or |map 15:22:51 when I try to use the dict() construct with map, I get `unhashable type: 'list'` 15:23:11 #chair jtanner nitzmahone bc 15:23:11 Current chairs: bc jtanner nitzmahone sdoran 15:23:14 to_map 15:23:15 cause map is looking for an attribute or key and then failing when it can find neither 15:23:17 #chair bcoca 15:23:17 Current chairs: bc bcoca jtanner nitzmahone sdoran 15:24:22 jtanner: no, it looks for a filter, for attributes you need to use attribute= option 15:24:33 tbh, i think if ansible needs a to_dict, jinja probably "needs" it too 15:24:35 `{{ dict(myvar | map('zip', mykeys) ) }}` does not work, even w/ `|list` added 15:24:38 list|map('filter', attribute=) 15:25:03 jtanner: i dont disagree 15:25:30 jtanner I actually agree with that, but even if Jinja gets one, we couldn't use it for years (see also the equalto test) 15:25:48 sigh ... to_json|from_json ... would get you what you want .. but its fugly 15:25:54 Yeah, I was just wondering why Jinja doesn't include a `dict` filter. 15:26:00 * nitzmahone shudders 15:26:03 they includ e adict function 15:26:06 yeah, i'm saying we could carry it until jinja gets it and it's eventually in the various distros 15:26:17 nitzmahone: im not going to write example .. since it would haunt me 15:26:25 Lol 15:26:39 |mapping 15:26:53 ^ to avoid dict confusion and use a jinja2 'normalized' term 15:27:30 Let the bikeshedding commence 😉 15:27:35 to_dict 15:27:46 no need to fight, you can make multiple aliases to same 15:27:50 see relpath/realpath 15:27:58 unfrackpath is all i know 15:29:42 did we make that into a filter? 15:30:00 * bcoca was tempted to rename that function, but ended up liking the name 15:30:00 no, but i love the name 15:30:08 GET OUT OF MY BRAIN 15:30:13 you first 15:30:21 calling it dict seems fine to me if it's just an alias for the built in 15:30:36 but to_dict is fine to 15:30:44 to_dict/mapping 15:31:08 caause people will ask for 'short version' .. but if mapping is there, to_dict is already 'the short version' 15:31:11 Yeah, colliding with an already defined function that's mapped on seems like a recipe for trouble down the line 15:31:18 * bcoca is a lazy typist and thinks like lazy typists 15:31:22 then we could have from_dict and unzip to undo the operation :P 15:32:13 dct 15:32:18 soon enough well make jinja a comple replication of python ... 15:32:30 we are well on our way 15:32:32 ... with much jankier syntax 15:32:56 could just rip out jinja completely and make direct call to `exec()` also =) 15:33:07 heh 15:33:21 Just write `(code) | python_eval` and be done with it 15:33:33 exec technically 15:33:38 Yeah 15:34:17 You can basically do that already if you know what you're doing... 15:34:34 <.< 15:34:40 >.> 15:34:56 to_exec 15:35:10 * nitzmahone quits 15:35:12 shhhhh ;) 15:35:21 * jtanner braces for many more months of cve discussion 15:37:02 s/months/lifetimes/ 15:37:58 nitzmahone: lookup('pipe' .... 15:38:28 So seems like we're ok adding a `to_dict` filter so long as it remains a pretty thin wrapper over Python's `dict()`. 15:38:32 That's the "easy" way ;) 15:38:34 * cyberpear tries to avoid that 15:39:03 I'll go ask in the Jinja chat why they don't offer a `dict` filter. I couldn't find anything in issues and PRs. 15:39:12 * bcoca writes unsafe_eval_no_really_dont_use this filter 15:39:38 sdoran++ 15:39:58 Probably because most people are using full templates, not just expressions, which makes it easier to do imperative stuff 15:40:11 cyberpear: You can submit a PR (with tests 😁) and we'll review it. 15:40:18 Anything else on this topic? 15:40:31 ok, thanks 15:40:37 * bcoca was hoping to bikeshed for another 30mins ... 15:40:56 Meeting's not over yet ;) 15:41:01 #topic open floor 15:42:09 If there are no more topics, I'll close in one minute. 15:45:39 Thanks everyone for participating! 15:45:41 #endmeeting