Skip to content

Proposal for extension of ruff analyze graph --detect-string-importsΒ #24059

@markjm

Description

@markjm

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    analyzeRelated to Ruff analyze functionalityneeds-decisionAwaiting a decision from a maintainer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions