redbaron icon indicating copy to clipboard operation
redbaron copied to clipboard

support for context manager tuple

Open elijahr opened this issue 3 years ago • 0 comments

with (context1 as c1, context2 as c2) does not work.

>>> import redbaron
>>> redbaron.RedBaron('''
... with (open("a.txt", "w") as a, open("b.txt", "w") as b):
...     print(1)
... ''')
Traceback (most recent call last):
  File "~/.asdf/installs/python/3.10.7/lib/python3.10/site-packages/baron/baron.py", line 20, in _parse
    return parser(tokens)
  File "~/.asdf/installs/python/3.10.7/lib/python3.10/site-packages/baron/grammator.py", line 836, in parse
    return parser.parse(iter(tokens))
  File "~/.asdf/installs/python/3.10.7/lib/python3.10/site-packages/baron/parser.py", line 165, in parse
    raise ParsingError(debug_output)
baron.parser.ParsingError: Error, got an unexpected token AS here:

   1
   2 with (open("a.txt", "w") as <---- here

The token AS should be one of those: COMMA, FOR, RIGHT_PARENTHESIS

Baron has failed to parse this input. If this is valid python code (and by that I mean that the python binary successfully parse this code without any syntax error) (also consider that baron does not yet parse python 3 code integrally) it would be kind if you can extract a snippet of your code that make Baron fails and open a bug here: https://github.com/PyCQA/baron/issues

Sorry for the inconvenience.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "~/.asdf/installs/python/3.10.7/lib/python3.10/site-packages/redbaron/redbaron.py", line 36, in __init__
    self.node_list = base_nodes.NodeList.from_fst(baron.parse(source_code), parent=self, on_attribute="root")
  File "~/.asdf/installs/python/3.10.7/lib/python3.10/site-packages/baron/baron.py", line 66, in parse
    return _parse(tokens, print_function)
  File "~/.asdf/installs/python/3.10.7/lib/python3.10/site-packages/baron/baron.py", line 24, in _parse
    return parser(tokens)
  File "~/.asdf/installs/python/3.10.7/lib/python3.10/site-packages/baron/grammator.py", line 836, in parse
    return parser.parse(iter(tokens))
  File "~/.asdf/installs/python/3.10.7/lib/python3.10/site-packages/baron/parser.py", line 165, in parse
    raise ParsingError(debug_output)
baron.parser.ParsingError: Error, got an unexpected token AS here:

   1
   2 with (open("a.txt", "w") as <---- here

The token AS should be one of those: COMMA, FOR, RIGHT_PARENTHESIS

Baron has failed to parse this input. If this is valid python code (and by that I mean that the python binary successfully parse this code without any syntax error) (also consider that baron does not yet parse python 3 code integrally) it would be kind if you can extract a snippet of your code that make Baron fails and open a bug here: https://github.com/PyCQA/baron/issues

Sorry for the inconvenience.

elijahr avatar Oct 04 '22 07:10 elijahr