Description
Description
This issue originally sprouted from here: #15976 (comment)
Consider this Python program:
from ...zqzqzqzq import hi
Running red-knot at present gives you this:
$ run-red-knot -q pr1 -- check
error: lint:unresolved-import
--> /home/andrew/astral/ruff/play/diags/play/test.py:1:9
|
1 | from ...zqzqzqzq import hi
| ^^^^^^^^ Cannot resolve import `...zqzqzqzq`
|
The range here is a little inconsistent with the actual message. The range is only on the module name, but the message includes the preceding ...
. Indeed, if we futz with the Python program a bit more, we can somewhat observe what's going wrong:
from . . . zqzqzqzq import hi
Gives this:
$ run-red-knot -q pr1 -- check
error: lint:unresolved-import
--> /home/andrew/astral/ruff/play/diags/play/test.py:1:12
|
1 | from . . . zqzqzqzq import hi
| ^^^^^^^^ Cannot resolve import `...zqzqzqzq`
|
Here, the diagnostic message is showing something that does not match the actual source code.
I believe the underlying problem is the AST definition of a from import
:
ruff/crates/ruff_python_ast/src/nodes.rs
Lines 291 to 298 in a84b27e
Namely, it normalizes the level based on the preceding dots. But in doing so, this drops the range associated with the dots.