ruff
0ed93d2a - `analyze graph`: resolve string imports that reference attributes, not just modules (#24058)

Commit
62 days ago
`analyze graph`: resolve string imports that reference attributes, not just modules (#24058) ## 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()`](https://github.com/python/cpython/blob/3.14/Lib/pydoc.py#L1719) for this resolution, so the proposal here is for `analyze graph` to also see these types of string "imports". ## Proposed Fix The change 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. The fallback respects `min-dots` so it never produces a candidate with fewer dots than the configured threshold. I could imagine some edge-cases I am not thinking about, so open to suggestions. For example, maybe just always only check `n-1` (so only support top-level attributes in a module) ## Test Plan Added relevant tests for this behaviour and verified this change does solve my problem in my repo! --------- Co-authored-by: Micha Reiser <micha@reiser.io>
Author
Parents
Loading