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

[BUG] matched node in a sequence is returned as an array #338

Closed
sk- opened this issue Jul 11, 2020 · 0 comments · Fixed by #355
Closed

[BUG] matched node in a sequence is returned as an array #338

sk- opened this issue Jul 11, 2020 · 0 comments · Fixed by #355

Comments

@sk-
Copy link
Contributor

sk- commented Jul 11, 2020

Nodes matched in a sequence are for some reason returned as a list. See the code below where element is matched as a list, whereas int is not. Somewhat related to #337 .

libcst version: 0.3.7 (installed with pip)

import libcst.matchers as m
import libcst

node = libcst.parse_expression("[3]")
matcher = m.List(
    elements=[
        m.SaveMatchedNode(
            m.Element(value=m.SaveMatchedNode(m.Integer(value="3"), "int")),
            "element"
        ),
    ]
)
print(m.extract(node, matcher))
{'element': [Element(
    value=Integer(
        value='3',
        lpar=[],
        rpar=[],
    ),
    comma=MaybeSentinel.DEFAULT,
)], 'int': Integer(
    value='3',
    lpar=[],
    rpar=[],
)}
sk- added a commit to sk-/LibCST that referenced this issue Aug 2, 2020
jimmylai pushed a commit that referenced this issue Aug 14, 2020
* fix: correctly extract wildcard matchers

Fixes #337 and #338

* refactor: use data classes instead of bare tuples
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

Successfully merging a pull request may close this issue.

1 participant