Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replacing a call atom with a comprehension raises ParsingError #195

Open
graingert opened this issue Feb 10, 2020 · 0 comments
Open

replacing a call atom with a comprehension raises ParsingError #195

graingert opened this issue Feb 10, 2020 · 0 comments

Comments

@graingert
Copy link
Member

>>> red = redbaron.RedBaron("filter(fn, items).pop()")
>>> red[0]
filter(fn, items).pop()
>>> del red[0][1]
>>> red
0   filter.pop()

>>> red[0][0] = "[x for x in items if fn(x)]"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/redacted/.virtualenvs/redbaron/local/lib/python/site-packages/redbaron/base_nodes.py", line 736, in __setitem__
    self.value[key] = value
  File "/home/redacted/.virtualenvs/redbaron/local/lib/python/site-packages/redbaron/base_nodes.py", line 1469, in __setitem__
    on_attribute=self.on_attribute)
  File "/home/redacted/.virtualenvs/redbaron/local/lib/python/site-packages/redbaron/base_nodes.py", line 1672, in _convert_input_to_node_object
    return self.node_list.parent._convert_input_to_node_object_list(value, parent, on_attribute).filtered()[-1]
  File "/home/redacted/.virtualenvs/redbaron/local/lib/python/site-packages/redbaron/base_nodes.py", line 188, in _convert_input_to_node_object_list
    return self._string_to_node_list(value, parent=parent, on_attribute=on_attribute)
  File "/home/redacted/.virtualenvs/redbaron/local/lib/python/site-packages/redbaron/nodes.py", line 98, in _string_to_node_list
    return NodeList.from_fst(baron.parse("(%s)" % string)[0]["value"]["value"], parent=parent, on_attribute=on_attribute)
  File "/home/redacted/.virtualenvs/redbaron/local/lib/python/site-packages/baron/baron.py", line 57, in parse
    to_return = _parse(tokens, print_function)
  File "/home/redacted/.virtualenvs/redbaron/local/lib/python/site-packages/baron/baron.py", line 24, in _parse
    return parser(tokens)
  File "/home/redacted/.virtualenvs/redbaron/local/lib/python/site-packages/baron/grammator.py", line 828, in parse
    return parser.parse(iter(tokens))
  File "/home/redacted/.virtualenvs/redbaron/local/lib/python/site-packages/baron/parser.py", line 167, in parse
    raise ParsingError(debug_output)
baron.parser.ParsingError: Error, got an unexpected token FOR here:

   1 (a[x for <---- here

The token FOR should be one of those: COLON, COMMA, RIGHT_SQUARE_BRACKET

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 python 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant