tree-sitter-python icon indicating copy to clipboard operation
tree-sitter-python copied to clipboard

except_clause no except_item

Open gilosh opened this issue 5 years ago • 3 comments

For the following code:

try:
  pass
except Exception as e:
  pass
...   except_clause )
        identifier )
        identifier )
        block ) ...

It would be helpful to have an 'except_item' similarly to 'with_item', helping distinguish between the identifiers:

    with_item )
      value: identifier )
      alias: identifier )

.. # suggestion
    except_item )
      value: identifier )
      alias: identifier )

gilosh avatar Jun 18 '20 15:06 gilosh

Issue-Label Bot is automatically applying the label feature_request to this issue, with a confidence of 0.57. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

issue-label-bot[bot] avatar Jun 18 '20 15:06 issue-label-bot[bot]

I think except_item isn't needed as clearly as with_item, because unlike with_item, there can only be one item in each except_clause.

I'm still open to this change though. Alternatively, should we just put a value and alias fields in except_clause?

maxbrunsfeld avatar Jun 18 '20 17:06 maxbrunsfeld

Right! I was under the wrong assumption you could have multiple exceptions (I should have double checked with the interpreter).

  1. Would you say that this is a bug then?
try:
  pass
except RuntimeError, TypeError:
  pass
  try_statement [0, 0] - [3, 6])
...
    except_clause [2, 0] - [3, 6])
      identifier [2, 7] - [2, 19])
      identifier [2, 21] - [2, 30])
      block [3, 2] - [3, 6])
...

CPython

  File "<stdin>", line 3
    except RuntimeError, TypeError:
  1. Your solution for adding the fields sounds perfect

gilosh avatar Jun 18 '20 17:06 gilosh