On Mon, May 24, 2021 at 07:55:07PM -0000, Tyler F wrote:

> with the addition of PEP 634 and the new match/case syntax in python 
> 3.10, it seems fitting to be able to use these new match statements 
> inside of expressions as well,

Python 3.10 isn't even showing up on the Downloads page yet:

https://www.python.org/downloads/

It is still in beta, the first production-ready version is not due out 
until October.

https://www.python.org/dev/peps/pep-0619/#schedule

So how much real-world practical experience do you have now with the 
match/case syntax? Do you think that the community overall has as much 
experience with this syntax as you?

Normally we have years of practical experience with a feature before 
being able to judge its true worth and ability to extend it to new 
features. It was many years between if statements and the if operator; 
many years between for loops and comprehensions. We still don't have a 
try...except expression.

> However, this should be used sparingly (ideally for single 
> comparisons), similar to list comprehensions versus for loops.

o_O

In my experience, list comprehensions are used more than for loops now. 
But even if they aren't used literally more often than for loops, we can 
hardly say that comprehensions are used *sparingly*. They are an 
extremely popular and common feature.


So what does this matches operator return? You have this example:

    if variable matches ["example", *files]:
        print(files)


but we can extract the matches expression outside of the if statement.

(It's an expression, so we must be able to extract it out of the 
statement and use it alone, like any other expression.)


    variable matches ["example", *files]


I can't interpret what that should do or what it would return. Suppose I 
assigned it to a variable, or printed it:


    spam = variable matches ["example", *files]
    print(variable matches ["example", *files])


What's the value of `spam` (or what gets printed)?

If we can use it in an if statement, it has to return a value that can 
be either truthy or falsey, possibly even True or False itself.

How does that reconcile with the multi-branching match statement? A 
match statement can take an arbitrarily large number of cases, and each 
case is a block. How do you get the same effect in an expression?

Match statements also have binding side-effects. Binding in Python is 
*almost* entirely done with statements:

    spam = eggs # assignment
    import spam
    for spam in iterable: ...
    except Exception as err: ...

etc. The only expression that performs binding is the walrus operator, 
and that is still new and remains controversial. This would be a second 
one.


-- 
Steve
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/G6SIIWILJ2QWGURSXXEFTH4PQMGK7XSL/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to