On Mon, 7 Feb 2022 at 00:10, layday--- via Python-ideas
<python-ideas@python.org> 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 
> want to describe your data e.g. by encoding it in a dataclass you'll no 
> longer be able to dictionary-unpack it which will prove very frustrating.
>

That's not entirely true, because there are a ton of places where you
can read something generically and then process it afterwards. For
instance, I can run "ffprobe -print_format json", then use json.loads
to parse the output, and I'll get back a completely generic dictionary
with all its information. Suppose I then want to iterate over the
video streams:

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.

A match/case block would kinda work here, but it's overkill, like
using a for/break block to fetch the first element from a list.

But I'm not convinced of the syntax, and there's only a small number
of places where I'd actually use this. Consider me +0.25.

(BTW Steven, you can consider this to be one real-world example; I
lifted this straight from an actual script of mine. But the whole
script is a dozen lines long, so this isn't exactly a strong demo
case!)

ChrisA
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/BJPE4B6GZ3TUENUTLQAKVZVJ3EOY7MNZ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to