On Tue, Dec 31, 2019 at 8:23 PM Andrew Barnert via Python-ideas <
python-ideas@python.org> wrote:

> > K = 42
> > x, K, z = vec
> Yes. I’m surveying the way other languages deal with this to try to figure
> out what might fit best for Python.
> Some languages use special syntax to mark either values or targets:
>
>     let x, K, let z = vec
>     x, @K, z = vec
>
> But the simplest solution is to nothing: you have to stick it in an
> expression that isn’t a valid target, or
> It’s a target. And I think that might actually work. If the pattern
> matching library includes this (or you write it yourself):
>

What is and isn't a valid target.  For example: 'map[key]', 'seq[pos]',
'obj.attr'.

Generally a dictionary with key should be a target.  Or likewise a sequence
with position.  But they might be invalid too at runtime.  So maybe it's
fine for parser to think they are a target, and just blow up with
IndexError or the like, as now.

But what about that attribute? Maybe it's an assignment target.  Or maybe
it's a read-only property that contains a desirable value to match.  Or
maybe it's not read only, but a plain attribute that already exists with a
desirable value to match.

The bigger problem in my mind is that what I'd like to match isn't
generally a specific value.  It's more like:

    type[int], type[int], type[float] = vec

Or:

    type[int], y, z = vec

... I don't like my "proposed" syntax, but it kinda-sort vaguely resembles
stuff in PEP 484 and typing module, so using that as placeholder.

Or I even want to match:

    type[int], y < 42, z = vec

So your syntax gets me maybe 20% of what I'd want to do if we had pattern
matching.  And it has edge cases that of course I could learn, but would
not be intuitive.
_______________________________________________
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/YAY5KQSTBBNSCLN5NB2IOYNTP7TZ2KTB/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to