[Python-Dev] Why not make frames? [was: Alternative forms [was: PEP 463: Exception-catching expressions]]

Ethan Furman ethan at stoneleaf.us
Wed Mar 12 01:58:23 CET 2014


On 03/09/2014 07:16 PM, Jim J. Jewett wrote:
>
> because I cannot imagine reading an embedded version of either of those
> without having to mentally re-parse at the colon.  An example assuming
> a precedence level that may not be what the PEP proposes:
>
>      if myfunc(5, expr1 except expr2: expr3, "label"):
>          for i in range(3, 3*max(data) except TypeError: 9, 3):
>             ...
>
>      if myfunc(5, (expr1 except expr2: expr3), "label"):
>          for i in range(3, (3*max(data) except TypeError: 9), 3):
>             ...
>
>      if myfunc(5, expr1 except (expr2: expr3), "label"):
>          for i in range(3, 3*max(data) except (TypeError: 9), 3):
>             ...
>
>      if myfunc(5, expr1 except (expr2: expr3), "label"):
>          for i in range(3, 3*max(data) (except TypeError: 9), 3):
>             ...
>
>      if myfunc(5, expr1 except (expr3 if expr3), "label"):
>          for i in range(3, 3*max(data) (except 9 if TypeError), 3):
>             ...
>
>      if myfunc(5, expr1 except (expr3 if expr3), "label"):
>          for i in range(3, 3*max(data) except (9 if TypeError), 3):
>
>      myarg = expr1 except (expr3 if expr2)
>      if myfunc(5, myarg, "label"):
>          limit = 3*max(data) except (9 if TypeError)
>          for i in range(3, limit, 3):
>
> Yes, I would prefer to create a variable naming those expressions,
> but these are all still simple enough that I would expect to have
> to read them.  (I like constructions that get ugly just a bit faster
> than they get hard to understand.)  If I have to parse any of them,
> the ones at the bottom are less difficult than the ones at the top.

I totally disagree.  I found the second one the easiest to read, and outside a function call (or other complexity, the 
parens wouldn't be needed.

--
~Ethan~


More information about the Python-Dev mailing list