|
|
Subscribe / Log in / New account

"Structural pattern matching" for Python, part 2

"Structural pattern matching" for Python, part 2

Posted Sep 4, 2020 16:04 UTC (Fri) by mathstuf (subscriber, #69389)
In reply to: "Structural pattern matching" for Python, part 2 by hartb
Parent article: "Structural pattern matching" for Python, part 2

I was worried about the same thing too, but the walrus operator saves you in this related case as well:

match t := some_expr():
    case ...:
    case _:
        # use t
Though I don't like the locality mismatch here. For a large (probably considered un-Pythonic) match, your variable assignment is far away when it could be right next to it. You also have to consider that `t` is now always assigned to rather than just in the catch-all case.


to post comments


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds