mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-19 01:50:38 +00:00
[red-knot] Fix relative imports in src.root
(#15990)
## Summary Fixes https://github.com/astral-sh/ruff/issues/15989 Red Knot failed to resolve relative imports if the importing module is located at a search path root. The issue was that the module resolver returned an `Err(TooManyDots)` as soon as the parent of the current module is `None` (which is the case for a module at the search path root). However, this is incorrect if a `tail` (a module name) exists.
This commit is contained in:
parent
9d2105b863
commit
5588c75d65
2 changed files with 50 additions and 6 deletions
|
@ -218,3 +218,33 @@ import package
|
|||
# error: [unresolved-attribute] "Type `<module 'package'>` has no attribute `foo`"
|
||||
reveal_type(package.foo.X) # revealed: Unknown
|
||||
```
|
||||
|
||||
## In the src-root
|
||||
|
||||
`parser.py`:
|
||||
|
||||
```py
|
||||
X: int = 42
|
||||
```
|
||||
|
||||
`__main__.py`:
|
||||
|
||||
```py
|
||||
from .parser import X
|
||||
|
||||
reveal_type(X) # revealed: int
|
||||
```
|
||||
|
||||
## Beyond the src-root
|
||||
|
||||
`parser.py`:
|
||||
|
||||
```py
|
||||
X: int = 42
|
||||
```
|
||||
|
||||
`__main__.py`:
|
||||
|
||||
```py
|
||||
from ..parser import X # error: [unresolved-import]
|
||||
```
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue