lib: let getAttrs ignore nonexistent keys#345535
Conversation
Like its cousin `lib.removeAttrs`, `getAttrs` should now ignore keys that does not exist in the attrset.
|
I recognize the problem, but I'm not happy about the solution.
Probably needs to sort the keys internally anyway. A log factor is a lot like a constant factor though, so if we really want to say something about performance, we'll have to measure it. |
|
Just to make sure I'm understanding you correctly, you're suggesting we change Changing the Would it be a bad idea to create a |
If you need it for other code, I recommend putting it locally in a let binding for the time being, with a comment pointing to this discussion. |
|
Check out #269586, which is essentially the same idea but has a lot of discussion already. |
This PR contains an alternative implementation of
lib.attrsets.getAttrswhich ignores keys which do not exist in the attrset. It now behaves more similarly tolib.removeAttrs, which I've considered to be it's opposite. I am not aware of any usage where we depend ongetAttrsthrowing in absence of expected attributes (at least not solely), but I've only looked at in-tree usage.I'm not really sure that this is the behavior we want for this function considering it's named
getAttrs, but it would be useful to have a function that mirrorsremoveAttrsmore accurately. I don't mind making this into a new function if we want to keep the old behavior for this one.I believe this increases the time complexity. As far as I can tell, the old implementation was
O(n)wherenis the size of the key list, while this isO(n) + O(x log y)wherenis the key list andxandydepends on which is large of the key list and the input attrs (according tobuiltins.intersectAttrs).Things done
nix.conf? (See Nix manual)sandbox = relaxedsandbox = truenix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/)Add a 👍 reaction to pull requests you find important.