Le 14/08/2020 à 16:24, Mark Shannon a écrit :
reading through this made me think of 3 ideas which I think are new . 2 of them are about the Value Pattern question, the last one is a small nit about the Django example.
* the critique points the limitations to the use of pattern matching in __init__ methods, because Capture Patterns can't assign to dotted names.
Thus the currently proposed dot-based rule is a limitation not just for Value Patterns, as already heavily discussed, but also for Capture Patterns. Moreover, this limitation cannot be lifted after the fact if the __init__ method use-case proves important in the future.
* the critique points that Value Patterns with booleans would need identity-, not equality-based comparison. This leads to the idea that, if a special syntax if eventually used for Value Patterns, using the comparison operator in it might be useful. Thus we could have:
match int_or_boolean: # ok, dubious design!
... case is True: # same as "if int_or_boolean is True:" ... print("boolean true") ... case is False: ... print("boolean false") ... case == ONE: # same as "if int_or_boolean == ONE:" ... print("integer 1")
* the Django example could be written more idiomatically by relying more on destructuring instead of having a guard:
... case [first, *_, label := (Promise() | str())]: ... value = value[:-1] ... case _: ... label = key.replace('_', ' ').title()
 as in: I skimmed through most of the threads and believe they have not already been said (famous last words…)