Reputation: 1327
Given a python file, I want to find out all of the scopes and declarations for the identifiers in the file.
For example, given this file:
import a
from b import xyz
def my_func(g):
print "2"
my_func(0)
a.function_in_a(3)
xyz(4)
I want the output to be:
my_func
refers to my_func
defined in line 4 of this filea
refers to the module a. function_in_a
refers to the function defined in module axyz
refers to the function defined in module bIs there a library that does this for me? Basically I'm trying to use the in the context of IDE functionality / code autocomplete / understanding scopes of variables. Basically, I'm interested in understanding the location of an identifier's (variable, function, etc) definition, much like how an IDE like PyCharm determines it.
Upvotes: 3
Views: 290
Reputation: 16335
Strange that I haven't seen this issue before.
There's jedi.names
, which would do pretty much what you want!
https://jedi.readthedocs.io/en/latest/docs/api.html#jedi.names
Upvotes: 2