On 18/07/2020 02:10, Guido van Rossum wrote:
[...] it was quickly pointed out by my co-authors that this doesn't fly, because when the parser sees `case other_3d_point:` it doesn't know whether you meant this as a capture pattern (binding the variable `other_3d_point`) or as a pattern object.
This could be solved. One option would be to make pattern objects callable, such that when you write: my_pattern = MatchCase("something") match stuff: case my_pattern(): ... my_pattern() is used as a pattern object, and a single identifier like my_pattern is interpreted, as expected by the current version of the PEP, as a capture. I believe this is not subtle enough to be confusing to anyone who learns the feature as a whole. We don't, after all, confuse function calls for references to a function, or vice-versa.
Also with your proposal the compiler would not be able to tell that x, y and z are local variables, because they are only mentioned inside string literals. I was hoping the implementation of MatchCase could take care of this. I suppose it would require MatchCase to have access to locals() everywhere it's called; would this be a problem?