[Python-Dev] Re: PEP 622 version 2 (Structural Pattern Matching)

2020年7月12日 13:15:34 -0700

On 7/11/2020 7:54 PM, Greg Ewing wrote:
I can see that being a reasonable choice if you're using 8-space
indents, but I don't see that done much in Python.
Also, directly translating this into Python leads to something that
looks like a mistake:
  match x:
  case 1:
    ...
  case 2:
    ...
and as has been pointed out, the alternative of putting x on the
next line is unprecedented in Python.
If the 2 levels of indenting are really offensive, surely we could teach editors, black, ourselves, etc. to indent the match statement as:
match pt:
 case (x, y):        # <-- indent by two spaces
return Point3d(x, y, 0) # <-- indent by 2 more spaces, for a total of 4
if x:
  return x # <-- normally indent by 4 spaces
I used to do something similar with C switch statements.
I guess you couldn't use this trick if you were using tabs. Another reason to not use them!
Eric
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/MZWH24XT5PDP3THWC6LL6Q4ITAASAKON/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to