multilang-depends / depends

Depends is a fast, comprehensive code dependency analysis tool
MIT License
195 stars 54 forks source link

Incorrect reverse dependency in Python #41

Closed jlefever closed 1 year ago

jlefever commented 2 years ago

Say you have a file example/b.py that contains

Foo = str

and another file example/a.py that contains

from example import b

Foo = b.Foo

then Depends will report dependencies going both ways (a.py depends on b.py AND b.py depends on a.py).

Technically, this might not be a valid Python import (I'm not sure) but you can find real code that does this. See this project praxis from Google. If you run depends on this project, you will find a circular dependency between praxis/pytypes.py and praxis/base_model.py. However, if you manually inspect these files, you will notice that the dependency should just be one-way (from base_model.py to pytypes.py). I tried to reduce this bug to its essentials with my initial example.

I tried to debug this myself and I suspect that both a.Foo and b.Foo are being mapped to the same entity. If you change line 3 of a.py to

Foo2 = b.Foo

then the wrong dependency is no longer reported by depends.

gangz commented 1 year ago

The processing of import before is incorrect. Fixed now. Thanks!