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

TypeError on parsing some valid expressions #1061

Open
DRMacIver opened this issue Dec 11, 2023 · 0 comments
Open

TypeError on parsing some valid expressions #1061

DRMacIver opened this issue Dec 11, 2023 · 0 comments
Labels
bug Something isn't working parsing Converting source code into CST nodes

Comments

@DRMacIver
Copy link

DRMacIver commented Dec 11, 2023

The following code:

import libcst

libcst.parse_module('() if 0 else(lambda:())')

Raises the following error:

Traceback (most recent call last):
  File "/root/cstbreaker.py", line 5, in <module>
    libcst.parse_module('() if 0 else(lambda:())')
  File "/root/.pyenv/versions/3.11.6/lib/python3.11/site-packages/libcst/_parser/entrypoints.py", line 109, in parse_module
    result = _parse(
             ^^^^^^^
  File "/root/.pyenv/versions/3.11.6/lib/python3.11/site-packages/libcst/_parser/entrypoints.py", line 55, in _parse
    return parse(source_str)
           ^^^^^^^^^^^^^^^^^
  File "<string>", line 12, in __init__
  File "/root/.pyenv/versions/3.11.6/lib/python3.11/site-packages/libcst/_nodes/base.py", line 117, in __post_init__
    self._validate()
  File "/root/.pyenv/versions/3.11.6/lib/python3.11/site-packages/libcst/_nodes/expression.py", line 2553, in _validate
    and not self.orelse._safe_to_use_with_word_operator(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.pyenv/versions/3.11.6/lib/python3.11/site-packages/libcst/_nodes/expression.py", line 2115, in _safe_to_use_with_word_operator
    return super()._safe_to_use_with_word_operator(position)

This example is sensitive to whitespace. For example, inserting a space between the else and the opening bracket causes it to start working (or at least not crash, I've not checked if the parse is correct).

This is running with libcst 1.1.0 on Python 3.11.6

@zsol zsol added bug Something isn't working parsing Converting source code into CST nodes labels Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working parsing Converting source code into CST nodes
Projects
None yet
Development

No branches or pull requests

2 participants