2 ms·
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
by IshKebab 1y ago
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.
- 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/
- porridgeraisin 1y agoSure, but destructuring makes sense for both. Just assign the variables without corresponding keys a value of None.