5 ms·
I would donate $500 to the PSF tomorrow if they added this, the lack of it is daily pain
by nikisweeting 1y ago
I would donate $500 to the PSF tomorrow if they added this, the lack of it is daily pain
- almostgotcaught 1y agoyou can't do this consistently across all cases without compiler assistance (see https://doc.rust-lang.org/book/ch19-03-pattern-syntax.html https://doc.rust-lang.org/book/ch19-03-pattern-syntax.html or https://peps.python.org/pep-0636/#matching-builtin-classes https://peps.python.org/pep-0636/#matching-builtin-classes linked below).
- nikisweeting 1y agoperfect is enemy of good imo, dict destructuring is so valuable that I'm willing to bend some rules / add some rules to make it possible. can't we just copy whatever JS does?
- skeledrew 1y agoIf it's that valuable to you personally you can use that project to remove your "daily pain". No need to inflict the pain caused by such a thing being present in official Python. Some of us like for the language to remain highly readable.
- notpushkin 1y ago> you can use that project It’s not meant for production use. Quite clearly so: https://github.com/asottile/dict-unpacking-at-home#please-dont-use-this https://github.com/asottile/dict-unpacking-at-home#please-do...
- almostgotcaught 1y ago> perfect is enemy of good imo You can't land a language feature that only sometimes works - that's absolutely horrid UX. > can't we just copy whatever JS does? I wasn't aware that js does this and I don't know it's implemented. So maybe I should retract my claim about compiler assistance.
- nikisweeting 1y agoIt's been one of the headline features keeping me happy in JS for 9+ years.
- IshKebab 1y agoYou shouldn't be using dicts for data that you know the name of anyway - use dataclasses or named tuples. Dicts are best for things with keys that are not known at compile time.
- IgorPartola 1y agoSince when can you use data classes for kwargs? There are plenty of times when you should use a dict even if you know the keys.
- IshKebab 1y agoYou shouldn't be using kwargs! That is also well known to be bad practice (or it should be anyway). https://medium.com/codex/stop-using-kwargs-as-method-arguments-for-goodness-sake-4de2faf78986 https://medium.com/codex/stop-using-kwargs-as-method-argumen... http://ivory.idyll.org/blog/on-kwargs.html http://ivory.idyll.org/blog/on-kwargs.html Give me another one.
- almostgotcaught 1y agolol i think you didn't read/understand this - the article is about **kwargs (which is sometimes sloppy) while the person you're responding to is talking about "exploding" a dict when calling a function (this does not require **kwargs at all).
- IshKebab 1y agoSo when they said "kwargs" they didn't actually mean **kwargs they meant something else which doesn't even require kwargs? How did you magically infer that?
- ahupp 1y agoI’d agree with this, unless the kwargs is typed with the new-ish PEP-692: https://peps.python.org/pep-0692/ https://peps.python.org/pep-0692/
- 1y ago
- crabbone 1y agoNow come on... for code golf? Why on Earth would anyone want extra syntax in a language with already tons of bloat in the syntax that contribute nothing to language's capabilities? It's, in Bill Gates words, like paying to make airplanes heavier... This package is a funny gimmick, to illustrate, probably, unintended consequences of some of the aspects of Python's parser. Using this for anything other than another joke is harmful...
- porridgeraisin 1y agoDestructuring/unpacking and packing add more to the language than whatever crap they stuff into every new python release these days. Let's never forget they _removed_ in its entirety a standard library package, that is the level we are dealing with here... Not saying it needs to be done with the decoder hack, it should have proper compiler support, but it's basically necessary. It's the best feature in JS hands down. >> a, b = 2, 3 # say >> d = dict_of(a, b) >> d {"a": 2, "b": 3} >> # somewhere else... >> { a, b } = d >> a + b 5 The dict_of() function is already possible at runtime with python `ast` magic, see [1]. That package also has unpack_keys() again made possible with `ast`, but we'd of course want proper language support. [1] https://github.com/alexmojaki/sorcery https://github.com/alexmojaki/sorcery