On Sun, 1 Nov 2020 at 11:29, Nick Coghlan <ncogh...@gmail.com> wrote: > On Sat., 31 Oct. 2020, 9:29 pm Steven D'Aprano, <st...@pearwood.info> wrote: >> (4) Patterns which could conceivably be interpreted as assignment >> targets default to capture patterns, because that's what is normally >> wanted in pattern matching: >> >> >> case [1, spam, eggs]: >> # captures spam and eggs >> >> >> If you don't want to capture a named value, but just match on it, >> override it with an explicit `==` or `is`: >> >> >> case [1, ==spam, eggs]: >> # matches `spam` by equality, captures on eggs > > > As noted above, the current PEP 634 spec doesn't allow this, but if it did, > then I agree it would adress most of the concerns that prompted me to write > PEP 642. > > If the 634 PEP authors are amenable, I'd be happy to prepare a PR against the > PEP that made this change so you could see what it would look like at the > grammar level.
Since Guido has indicated he's still dubious about the value of offering an explicit prefix marker syntax at all, I'm instead going to agree with most of Steven's counter proposal and adopt it as the next iteration of PEP 642 (conceding the point on "_", using "==" and "is" as the prefix markers, and keeping the syntactic sugar that lets you omit the "==" prefix for comparison against literals and attributes). For the literal comparisons where equality isn't the right default, I'm still proposing leaving out the special casing, but I'm switching to proposing that we just not consider them valid literals for pattern matching purposes in the initial iteration of the design (so `is None` would be allowed as an identity constraint, but a bare ``None`` would be rejected as ambiguous, at least for now. I'd be more prepared to concede the "But is it *really* ambiguous?" case for `None` and `...` than I would for `True` and `False`, though). Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/OAIWD6UFYMKIUB7O5LLVLAZJO2R2QX5G/ Code of Conduct: http://python.org/psf/codeofconduct/