[Python-ideas] Re: Mapping unpacking assignment

2022-02-06 Thread layday--- via Python-ideas
This feature is far more useful in JS because JS objects double up as mappings - Python dataclasses/attrs models/Pydantic models/named tuples/who knows what are all represented by (typed) objects in JS/TS. As soon as you want to describe your data e.g. by encoding it in a dataclass you'll no lo

[Python-ideas] Re: Mapping unpacking assignment

2022-02-06 Thread Chris Angelico
On Mon, 7 Feb 2022 at 00:10, layday--- via Python-ideas wrote: > > This feature is far more useful in JS because JS objects double up as > mappings - Python dataclasses/attrs models/Pydantic models/named tuples/who > knows what are all represented by (typed) objects in JS/TS. As soon as you >

[Python-ideas] Re: Mapping unpacking assignment

2022-02-06 Thread layday--- via Python-ideas
I don't think we're saying anything different, I agree. The point I was making was that _after_ loading the data onto a dataclass (or equivalent), you wouldn't be able to unpack it. In JS, you can use destructuring assignment when working with "classes" (and therefore well-defined APIs), which

[Python-ideas] Re: Mapping unpacking assignment

2022-02-06 Thread Chris Angelico
On Mon, 7 Feb 2022 at 06:03, layday--- via Python-ideas wrote: > > I don't think we're saying anything different, I agree. The point I was > making was that _after_ loading the data onto a dataclass (or equivalent), > you wouldn't be able to unpack it. In JS, you can use destructuring > assig

[Python-ideas] Re: Mapping unpacking assignment

2022-02-06 Thread layday--- via Python-ideas
> Please can you quote some text to show who and what you're responding to? I *think* you're responding to my post, but it's hard to be sure. Sorry, I'm using the web UI which nests replies - I forgot this is a mailing list! I was responding to your message. _

[Python-ideas] Re: Mapping unpacking assignment

2022-02-06 Thread Christopher Barker
TL;DR I think Python's distinction between code (e.g. classes) and data (e.g. dicts) is a good distinction to keep -- if you want code, define code, and datcalasses make that very easy these days. And now the detailed version: On Sun, Feb 6, 2022 at 6:05 AM Chris Angelico wrote: > > This featu

[Python-ideas] Re: Mapping unpacking assignment

2022-02-06 Thread Bruce Leban
On Thu, Feb 3, 2022 at 11:53 AM Yurii Karabas <1998uri...@gmail.com> wrote: > > Proposed syntax: > > m = {"a": 1, "b": 2, "c": 3, "d": 4} > > {a, b} = m # a: 1, b: 2 > {a, b, **rest} = m # a: 1, b: 2, rest: {c: 3, d: 4} > > as equivalent to this from PEP 634: > match m: > case {"a": a, "b":

[Python-ideas] Re: Mapping unpacking assignment

2022-02-06 Thread Chris Angelico
On Mon, 7 Feb 2022 at 15:17, Christopher Barker wrote: > Using Chris's example: > >> for {codec_type, width, height} in info["streams"]: >> if codec_type == "video": >> ... >> This would be extremely convenient, and it doesn't really work with >> dataclasses. > > > First, how does thi

[Python-ideas] Re: Mapping unpacking assignment

2022-02-06 Thread Christopher Barker
On Sun, Feb 6, 2022 at 9:42 PM Chris Angelico wrote: > > As for dataclasses, this is what i mean by "code" vs "data" -- if you > know when you are writing the code exactly what key (fields, etc) you > expect , and you want to be able to work with that data model as code (e.g. > attribute access,

[Python-ideas] Re: Mapping unpacking assignment

2022-02-06 Thread Chris Angelico
On Mon, 7 Feb 2022 at 17:35, Christopher Barker wrote: > After I posted, I realized that dataclasses are probably not the simplest > solution -- but SimpleNamespace could be: > > In [9]: stream_info = {'codec_type': 'video', >...:'width': 1024, >...:'height