On Mon, 7 Feb 2022 at 16:43, Chris Angelico <ros...@gmail.com> wrote:
>
> There have been thoughts thrown around in the past of having a "match
> assignment" concept. The OP is far from the first to notice the
> parallel. Maybe that's what we should be looking at - but the biggest
> question is syntax. What should it look like?
>
> # A different type of assignment operator?
> {codec_type, width, height} $= info["streams"]
> # A special assignment target?
> match {codec_type, width, height} = info["streams"]
> # A special assignment source?
> {codec_type, width, height = match info["streams"]
> # Something else?

A question and two thoughts...

(1) Has there been any way to use the operator "=" in which the right
hand side was not just an expression specifying an object?

(2) For the form of the assignment target, I think an analogy with the
reception of function arguments could also be considered.  Note the
intended assignment could be done by

locals().update(
    (lambda codec_type, width, height, **rest: locals())(
        **info["streams"]
    )
)

if none of the variables were not local.

(3) If some keys in the mapping object may not appear on the left hand
side, then demanding **rest part would be consistent with the case of
iterable unpacking, structural pattern matching, as well as the case
for function arguments.  For an assignment without **rest, the
assignment source can just be sliced beforehand.

Best regards,
Takuo Matsuoka
_______________________________________________
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/JORGO6KH22A5YGFVEZK4Z74MGK2GADYS/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to