Disallow guards when using an "open pattern"? #153
Description
Towards the end of #140 -- which is about changing walrus patterns (v := P
) to AS patterns (P as v
) -- there's a side discussion about introducing guards for subpatterns, e.g.
case C(a if a >= 0, b if b >= 0):
as a more efficient way to spell
case C(a, b) if a >= 0 and b >= 0:
I don't think we should add that to the current proposal, but if we want to keep that door open for a future PEP, we should probably disallow
case a, b if a >= 0 and b >= 0:
since with sub-guards we'd want the guard to apply only to the b
subpattern.
It is easy to syntactically prohibit this and force users to write
case (a, b) if a >= 0 and b >= 0:
Once the PEP is accepted and the code is merged into the 3.10 branch, we would have a much harder time to change the semantics of case a, b if ...
and if we ever wanted to introduce sub-guards we'd be stuck with an ugly inconsistency.
Thoughts? We can also just decide to close the door for sub-guards (even with code colorization, the examples here look rather busy).