oxuser
oxuser

Reputation: 1327

Is there a scope analyzer for Python?

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:

Is 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

Answers (1)

Dave Halter
Dave Halter

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

Related Questions