Technologicat / pyan

Static call graph generator. The official Python 3 version. Development repo.
GNU General Public License v2.0
324 stars 57 forks source link

Analyzing an __init__.py in cwd crashes Pyan #9

Closed Technologicat closed 5 years ago

Technologicat commented 5 years ago

The scope naming internals of objects at the top level of a module seem to have changed somewhere between Python 3.4 and 3.6.

This code used to work in Python 3.4 (pyan/analyzer.py, method analyze_scopes):

ns = "%s.%s" % (parent_ns, sc.name) if len(sc.name) else parent_ns

but in Python 3.6.8, I'm now getting names like ".some_top_level_object" (note silly leading dot).

Now parent_ns is empty, and the object name is returned in sc.name. It used to be the other way around.

Seems this needs code to handle both cases...

Technologicat commented 5 years ago

...or maybe it's the fact I'm now trying to analyze a nontrivial __init__.py? Debugging...

Technologicat commented 5 years ago

...which is in the cwd (see anutils.py, function get_module_name).

Technologicat commented 5 years ago

Yep, analyzing an __init__.py in cwd was the actual culprit.

Technologicat commented 5 years ago

Let's document also the fact that nontrivial here means that the __init__.py defines functions and/or classes, so something for Pyan to pick up.