ruff: `ruff analyze graph` does not understand submodule imports

ruff 0.6.8

i see something like this:

{
"src/view.py": [
    "src/models/User.py",
  ],
"src/code.py": [
    "src/models/user.py",
  ],
}

content of src/models/__init__.py:

from models.user import User

__all__ = ['User']

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 21 (17 by maintainers)

Most upvoted comments

@AlexWaygood Is my understanding correct that red knot’s inference for from import misses the automatic sub-module fallback?

Yeah, I think that’s a known limitation of the red-knot semantic model right now. There’s a test case with a TODO for it IIRC. I can look at doing the todo next week!

That’s correct, but I think that’s an issue in the analyze graph because it first tries to resolve models.User before testing for models

https://github.com/astral-sh/ruff/blob/3018303c8759b3e96d075c62eeb8b8ef24b4d0c3/crates/ruff_graph/src/resolver.rs#L27-L34

Red Knot does the resolution in the opposite order:

  1. First resolve models
  2. Then resolve models.user by looking up User in models

The repo don’t contains User.py, only user.py, so “src/ruff_analyze_tree/models/User.py” - is invalid.