News for hackers. Stuff that matters.
Re:Python: Acceptance of Pattern Matching – PEP 634 by pansa2 on Tuesday February 09, 2021 @03:45AM (#26075231)
Is it still the case that these two pieces of code have different behaviour?

    match status:
        case 404:
            return "Not found"

    not_found = 404
    match status:
        case not_found:
            return "Not found"
IIRC in an earlier proposal, the former would check for equality (`status == 404`) and the latter would perform an assignment (`not_found = status`).
Re:Python: Acceptance of Pattern Matching – PEP 634 by bilboa on Tuesday February 09, 2021 @08:01AM (#26076964)
Yes, the variable names in the case patterns are treated like variables on the left hand side of an assignment statement. Whatever value they may have had before is irrelevant. A pattern which consists solely of a variable name is a wildcard pattern that matches anything, just as it would be on the left side of an assignment.

Edit: It is possible to use constants or variables in a case pattern, but they have to be dotted names to not be treated like a capture pattern. So this would work for your example:

  class HttpStatus(Enum):
      NOT_FOUND = 404

  match status:
     case HttpStatus.NOT_FOUND:
         return "Not found"
Re:Python: Acceptance of Pattern Matching – PEP 634 by wodenokoto on Tuesday February 09, 2021 @02:53PM (#26081744)
Do you know what would happen with:

    def _id(x): return x

    not_found = 404
    match status:
        case _id(not_found):
            return "Not found"
Re:Python: Acceptance of Pattern Matching – PEP 634 by airstrike on Tuesday February 09, 2021 @03:21PM (#26081990)
Yes, and this is incredibly disappointing.

Couldn't we achieve the same functionality with a little less ambiguity using the following syntax?:

    not_found = 404
    match status:
        case not_found:
            return "Not found"
            
        case _ as foo:
            do_something(foo)
            return "Match anything"
it even works for the example in PEP 365

    match json_pet:
        case {"type": "cat", "name": _ as name, "pattern": _ as pattern}:
            return Cat(name, pattern)
        case {"type": "dog", "name": _ as name, "breed": _ as breed}:
            return Dog(name, breed)
        case _:
            raise ValueError("Not a suitable pet")
Re:Python: Acceptance of Pattern Matching – PEP 634 by pfalcon on Wednesday February 10, 2021 @04:44AM (#26087244)
I'm with everyone on "incredibly disappointing" valuation. But being pragmatic, I had to accept the idea "it can be addressed later" vs continuing this mess. And there was truly mess, e.g. PEP642, which initially tried to addressed just this issue, turned in a hairy monster trying to random-patch pattern matching considerably in rather weird ways.
Re:Python: Acceptance of Pattern Matching – PEP 634 by reagle on Friday February 12, 2021 @09:04AM (#26113728)
I don’t understand this. How are we supposed to read the case word? Is there an online interpreter for this so we can play with it?