←back to thread

101 points _ZeD_ | 9 comments | | HN request time: 1.215s | source | bottom
1. nikisweeting ◴[] No.44539220[source]
I would donate $500 to the PSF tomorrow if they added this, the lack of it is daily pain
replies(3): >>44539245 #>>44540127 #>>44540364 #
2. almostgotcaught ◴[] No.44539245[source]
you can't do this consistently across all cases without compiler assistance (see https://doc.rust-lang.org/book/ch19-03-pattern-syntax.html or https://peps.python.org/pep-0636/#matching-builtin-classes linked below).
replies(1): >>44539403 #
3. nikisweeting ◴[] No.44539403[source]
perfect 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?
replies(2): >>44539489 #>>44539635 #
4. skeledrew ◴[] No.44539489{3}[source]
If 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.
replies(1): >>44541852 #
5. almostgotcaught ◴[] No.44539635{3}[source]
> 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.

6. IshKebab ◴[] No.44540127[source]
You 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.
replies(1): >>44541834 #
7. crabbone ◴[] No.44540364[source]
Now 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...

8. IgorPartola ◴[] No.44541834[source]
Since 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.
9. notpushkin ◴[] No.44541852{4}[source]
> you can use that project

It’s not meant for production use. Quite clearly so: https://github.com/asottile/dict-unpacking-at-home#please-do...