You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note that a OneOf matcher can be used anywhere you are defining a matcher attribute. So, an alternate form to the first example looks like:
m.Name(m.OneOf("True", "False"))
However, I'm not able to use that matcher, as I get the following error:
Traceback (most recent call last):
File "cst/matcher_bug2.py", line 8, in <module>
print(m.findall(node, matcher_oneof))
File "/Users/user/.virtualenvs/cst/lib/python3.6/site-packages/libcst/matchers/_matcher_base.py", line 1574, in findall
nodes, _ = _find_or_extract_all(tree, matcher, metadata_resolver=metadata_resolver)
File "/Users/user/.virtualenvs/cst/lib/python3.6/site-packages/libcst/matchers/_matcher_base.py", line 1539, in _find_or_extract_all
tree.visit(finder)
File "/Users/user/.virtualenvs/cst/lib/python3.6/site-packages/libcst/_nodes/base.py", line 225, in visit
_CSTNodeSelfT, self._visit_and_replace_children(visitor)
File "/Users/user/.virtualenvs/cst/lib/python3.6/site-packages/libcst/_nodes/statement.py", line 591, in _visit_and_replace_children
test=visit_required(self, "test", self.test, visitor),
File "/Users/user/.virtualenvs/cst/lib/python3.6/site-packages/libcst/_nodes/internal.py", line 81, in visit_required
result = node.visit(visitor)
File "/Users/user/.virtualenvs/cst/lib/python3.6/site-packages/libcst/_nodes/base.py", line 216, in visit
should_visit_children = visitor.on_visit(self)
File "/Users/user/.virtualenvs/cst/lib/python3.6/site-packages/libcst/matchers/_matcher_base.py", line 1483, in on_visit
match = _matches(node, self.matcher, self.metadata_lookup)
File "/Users/user/.virtualenvs/cst/lib/python3.6/site-packages/libcst/matchers/_matcher_base.py", line 1352, in _matches
return _node_matches(node, matcher, metadata_lookup)
File "/Users/user/.virtualenvs/cst/lib/python3.6/site-packages/libcst/matchers/_matcher_base.py", line 1299, in _node_matches
attribute_capture = _attribute_matches(actual, desired, metadata_lookup)
File "/Users/user/.virtualenvs/cst/lib/python3.6/site-packages/libcst/matchers/_matcher_base.py", line 1113, in _attribute_matches
sequence_capture = _sequence_matches(node, m, metadata_lookup)
File "/Users/user/.virtualenvs/cst/lib/python3.6/site-packages/libcst/matchers/_matcher_base.py", line 1044, in _sequence_matches
match_capture = _matches(node, matcher, metadata_lookup)
File "/Users/user/.virtualenvs/cst/lib/python3.6/site-packages/libcst/matchers/_matcher_base.py", line 1352, in _matches
return _node_matches(node, matcher, metadata_lookup)
File "/Users/user/.virtualenvs/cst/lib/python3.6/site-packages/libcst/matchers/_matcher_base.py", line 1282, in _node_matches
for field in fields(matcher):
File "/Users/user/.virtualenvs/cst/lib/python3.6/site-packages/dataclasses.py", line 972, in fields
raise TypeError('must be called with a dataclass type or instance')
TypeError: must be called with a dataclass type or instance
The documentation is wrong. The options of OneOf need to be matchers (either concrete matcher node or some matcher helper node like OneOf/AllOf) instead of arbitrary type (like the str in the example).
We should fix the document.
Zac-HD
added a commit
to Zac-HD/LibCST
that referenced
this issue
Oct 10, 2021
In the
OneOf
docs it says:However, I'm not able to use that matcher, as I get the following error:
This is the code I'm using to test it:
Note that the
matcher_matchiftrue
and thematcher_oneof
matchers work fine in the example above.The text was updated successfully, but these errors were encountered: