diff --git a/docs/source/metadata.rst b/docs/source/metadata.rst index 1392dc2a..ee0a87ae 100644 --- a/docs/source/metadata.rst +++ b/docs/source/metadata.rst @@ -137,7 +137,7 @@ Parent Node Metadata -------------------- A :class:`~libcst.CSTNode` only has attributes link to its child nodes and thus only top-down tree traversal is doable. Sometimes user may want to access the parent :class:`~libcst.CSTNode` -for more information or traverse in buttom-up manner. +for more information or traverse in bottom-up manner. We provide :class:`~libcst.metadata.ParentNodeProvider` for those use cases. .. autoclass:: libcst.metadata.ParentNodeProvider diff --git a/libcst/metadata/tests/test_parent_node_provider.py b/libcst/metadata/tests/test_parent_node_provider.py index 4634da94..74ed764b 100644 --- a/libcst/metadata/tests/test_parent_node_provider.py +++ b/libcst/metadata/tests/test_parent_node_provider.py @@ -39,6 +39,26 @@ class ParentNodeProviderTest(UnitTest): fn3(foo) """, ), + ( + """ + global_var = None + @cls_attr + class Cls(cls_attr, kwarg=cls_attr): + cls_attr = 5 + def f(): + pass + """, + ), + ( + """ + iterator = None + condition = None + [elt for target in iterator if condition] + {elt for target in iterator if condition} + {elt: target for target in iterator if condition} + (elt for target in iterator if condition) + """, + ), ) ) def test_parent_node_provier(self, code: str) -> None: