-
I'm trying to figure out how to use the import libcst as cst
from libcst.metadata import FullyQualifiedNameProvider, MetadataWrapper
class FullyQualifiedNameCollector(cst.CSTVisitor):
METADATA_DEPENDENCIES = (FullyQualifiedNameProvider,)
def visit_Name(self, node: cst.Name) -> None:
fqns = self.get_metadata(FullyQualifiedNameProvider, node, None)
if fqns:
for fqn in fqns:
print(f"Identifier: {node.value}, Fully Qualified Name: {fqn.name}")
code = """
import os
def my_function():
print(os.path.join("a", "b"))
"""
module = cst.parse_module(code)
wrapper = MetadataWrapper(module)
collector = FullyQualifiedNameCollector()
wrapper.visit(collector) gives
Any hints? |
Beta Was this translation helpful? Give feedback.
Answered by
obiwac
Jun 2, 2025
Replies: 1 comment
-
You need to use |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
zsol
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need to use
FullRepoManager
. Look at the example forFullyQualifiedNameProvider
here.FullyQualifiedNameProvider
needs the context of your codebase to be able to provide you with fully qualfiied names.