Comments (5)
@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.
hey @jimmylai ! any updates on the repository analysis/refactoring? just curious
from libcst.
@zhammer I'm currently working on it and hoping to deliver it by the end of this month.
from libcst.
Update: the TypeInferenceProvider PRs are in review and will be published in the next release.
#159
#179
from libcst.
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)
- RemoveImportsVisitor crashes when parsing Literal["r+"] HOT 1
- Real-world code snippets which `libcst` fails to parse HOT 8
- A way to silence "Failed to determine module name"? HOT 2
- Support LSP for `TypeInferenceProvider` HOT 8
- Parse error when no space between keyword and float
- Parse error when non-standard indentation is encountered HOT 2
- Parse error when keyword adjacent to parenthesis
- ApplyTypeAnnotationVisitor should only annotate the first assignment to a name in a given scope HOT 1
- pip install -e gets the wrong version number HOT 2
- `QualifiedNameProvider` returns inner func name for higher-order anonymous func calls
- Publishing wheels for musl (alpine 3.17) HOT 1
- CSTNode.with_deep_changes type annotation is incomplete HOT 2
- Would be great if matchers somehow do automatic `ensure_type` HOT 1
- Incorrect expected type for second arg of `deep_replace`
- Sort functions by their usage? HOT 1
- Publishing the parser to crates.io HOT 8
- `CodeRange` provided by `PositionProvider` doesn't include decorators HOT 2
- Native parser crashes on pydoc_data.topics
- Codemod idea: change annotation strings to not strings
- Incorrect syntax error parsing contextmanagers HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libcst.