-
Notifications
You must be signed in to change notification settings - Fork 2k
Description
Hi again -
Congrats on the big OpenAI news - very exciting!
To business π - below is a proposal I have to make analyze graph a little more effective for additional cases:
Problem Statement
When detect-string-imports is enabled, strings like "a.b.c.MyClass" are dropped because a/b/c/MyClass.py doesn't exist.
One common pattern (for better or worse) we have in our codebase is a fully-specified import-like string to an attribute in a module. We specifically use pydoc.locate() for this resolution, so the proposal here is for analyze graph to also see these types of string "imports".
Proposed Fix
The proposed fix is pretty simple - just allow the resolver to try progressively shorter prefixes only for string imports
eg. a.b.c, then a.b, etc. β until one resolves to an actual module file.
I have implemented this in #24058 if this is of interest to upstream!
Thanks for reading!