Git Product home page Git Product logo

Comments (5)

jimmylai avatar jimmylai commented on June 15, 2024

@zhammer Retrieve the FunctionDef node given a Call is doable through our Scope metadata provider.
https://2589-200896124-gh.circle-artifacts.com/0/doc/metadata.html#libcst.metadata.Scope

You can add the dependency to use the provider in your visitor/transformer

class MyVisitor(libcst.CSTVisitor):
    METADATA_DEPENDENCIES = (libcst.metadata.ScopeProvider,)

    def visit_Call(self, node):
        scope = self. get_metadata(libcst.metadata.ScopeProvider, node)
        assignments = scope[node.func.value]  # you'll get a list of possible assignments

See the Assignment class for more detail.
https://2580-200896124-gh.circle-artifacts.com/0/doc/metadata.html#libcst.metadata.Assignment

I'm working on a couple more powerful metadata providers and plan to add tutorial to demonstrate some use cases.

Currently the metadata providers only analyze one single module and single module is the scope of LibCST. For collecting metadata across multiple files, we plan to work on it in the future by adding another layer on top of LibCST to support code repository scope analysis/refactoring.

from libcst.

zhammer avatar zhammer commented on June 15, 2024

hey @jimmylai ! any updates on the repository analysis/refactoring? just curious

from libcst.

jimmylai avatar jimmylai commented on June 15, 2024

@zhammer I'm currently working on it and hoping to deliver it by the end of this month.

from libcst.

jimmylai avatar jimmylai commented on June 15, 2024

Update: the TypeInferenceProvider PRs are in review and will be published in the next release.
#159
#179

from libcst.

jimmylai avatar jimmylai commented on June 15, 2024

TypeInferenceProvider is available in LibCST 0.2.6. Given a Call.func, it provides the type annotation of the node (Callable(name)[...]). The name is provided as a fully qualified name. So we can potentially use the name to read source code and parse as CST to get the FunctionDef node.

from libcst.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.