LibCST icon indicating copy to clipboard operation
LibCST copied to clipboard

`OneOf` causes match to fail in some cases

Open MapleCCC opened this issue 3 years ago • 0 comments

The version of libcst I am using is 0.3.21. Following is the code snippet to reproduce the bug:

import libcst as cst
import libcst.matchers as m

s = """
def f():
    pass
"""

module = cst.parse_module(s)

pattern_1 = (m.FunctionDef | m.Lambda)(m.Name("f"))
pattern_2 = m.FunctionDef(m.Name("g"))
pattern_3 = m.OneOf(pattern_1, pattern_2)

print(len(m.findall(module, pattern_1)))   # 1
print(len(m.findall(module, pattern_2)))   # 0
print(len(m.findall(module, pattern_3)))   # 0

As the result shows, pattern_1 has match, and pattern_2 has no match. pattern_3 is supposed to have match when it combines pattern_1 and pattern_2 with OneOf.

MapleCCC avatar Oct 06 '21 20:10 MapleCCC