mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-29 03:02:14 +00:00
[ty] Fix duplicate diagnostics for unresolved module when an import from statement imports multiple members (#17886)
This commit is contained in:
parent
457ec4dddd
commit
2f9992b6ef
17 changed files with 95 additions and 60 deletions
|
|
@ -0,0 +1,30 @@
|
|||
---
|
||||
source: crates/ty_test/src/lib.rs
|
||||
expression: snapshot
|
||||
---
|
||||
---
|
||||
mdtest name: basic.md - Structures - Multiple objects imported from an unresolved module
|
||||
mdtest path: crates/ty_python_semantic/resources/mdtest/import/basic.md
|
||||
---
|
||||
|
||||
# Python source files
|
||||
|
||||
## mdtest_snippet.py
|
||||
|
||||
```
|
||||
1 | # error: [unresolved-import]
|
||||
2 | from does_not_exist import foo, bar, baz
|
||||
```
|
||||
|
||||
# Diagnostics
|
||||
|
||||
```
|
||||
error: lint:unresolved-import: Cannot resolve imported module `does_not_exist`
|
||||
--> src/mdtest_snippet.py:2:6
|
||||
|
|
||||
1 | # error: [unresolved-import]
|
||||
2 | from does_not_exist import foo, bar, baz
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
|
||||
```
|
||||
|
|
@ -12,16 +12,16 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/import/basic.md
|
|||
## mdtest_snippet.py
|
||||
|
||||
```
|
||||
1 | import zqzqzqzqzqzqzq # error: [unresolved-import] "Cannot resolve import `zqzqzqzqzqzqzq`"
|
||||
1 | import zqzqzqzqzqzqzq # error: [unresolved-import] "Cannot resolve imported module `zqzqzqzqzqzqzq`"
|
||||
```
|
||||
|
||||
# Diagnostics
|
||||
|
||||
```
|
||||
error: lint:unresolved-import: Cannot resolve import `zqzqzqzqzqzqzq`
|
||||
error: lint:unresolved-import: Cannot resolve imported module `zqzqzqzqzqzqzq`
|
||||
--> src/mdtest_snippet.py:1:8
|
||||
|
|
||||
1 | import zqzqzqzqzqzqzq # error: [unresolved-import] "Cannot resolve import `zqzqzqzqzqzqzq`"
|
||||
1 | import zqzqzqzqzqzqzq # error: [unresolved-import] "Cannot resolve imported module `zqzqzqzqzqzqzq`"
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
|
||||
|
|
|
|||
|
|
@ -13,10 +13,10 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/import/basic.md
|
|||
|
||||
```
|
||||
1 | # Topmost component resolvable, submodule not resolvable:
|
||||
2 | import a.foo # error: [unresolved-import] "Cannot resolve import `a.foo`"
|
||||
2 | import a.foo # error: [unresolved-import] "Cannot resolve imported module `a.foo`"
|
||||
3 |
|
||||
4 | # Topmost component unresolvable:
|
||||
5 | import b.foo # error: [unresolved-import] "Cannot resolve import `b.foo`"
|
||||
5 | import b.foo # error: [unresolved-import] "Cannot resolve imported module `b.foo`"
|
||||
```
|
||||
|
||||
## a/__init__.py
|
||||
|
|
@ -27,11 +27,11 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/import/basic.md
|
|||
# Diagnostics
|
||||
|
||||
```
|
||||
error: lint:unresolved-import: Cannot resolve import `a.foo`
|
||||
error: lint:unresolved-import: Cannot resolve imported module `a.foo`
|
||||
--> src/mdtest_snippet.py:2:8
|
||||
|
|
||||
1 | # Topmost component resolvable, submodule not resolvable:
|
||||
2 | import a.foo # error: [unresolved-import] "Cannot resolve import `a.foo`"
|
||||
2 | import a.foo # error: [unresolved-import] "Cannot resolve imported module `a.foo`"
|
||||
| ^^^^^
|
||||
3 |
|
||||
4 | # Topmost component unresolvable:
|
||||
|
|
@ -40,11 +40,11 @@ error: lint:unresolved-import: Cannot resolve import `a.foo`
|
|||
```
|
||||
|
||||
```
|
||||
error: lint:unresolved-import: Cannot resolve import `b.foo`
|
||||
error: lint:unresolved-import: Cannot resolve imported module `b.foo`
|
||||
--> src/mdtest_snippet.py:5:8
|
||||
|
|
||||
4 | # Topmost component unresolvable:
|
||||
5 | import b.foo # error: [unresolved-import] "Cannot resolve import `b.foo`"
|
||||
5 | import b.foo # error: [unresolved-import] "Cannot resolve imported module `b.foo`"
|
||||
| ^^^^^
|
||||
|
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/diagnostics/unresolved_i
|
|||
# Diagnostics
|
||||
|
||||
```
|
||||
error: lint:unresolved-import: Cannot resolve import `does_not_exist`
|
||||
error: lint:unresolved-import: Cannot resolve imported module `does_not_exist`
|
||||
--> src/mdtest_snippet.py:1:8
|
||||
|
|
||||
1 | import does_not_exist # error: [unresolved-import]
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/diagnostics/unresolved_i
|
|||
# Diagnostics
|
||||
|
||||
```
|
||||
error: lint:unresolved-import: Cannot resolve import `.does_not_exist`
|
||||
error: lint:unresolved-import: Cannot resolve imported module `.does_not_exist`
|
||||
--> src/mdtest_snippet.py:1:7
|
||||
|
|
||||
1 | from .does_not_exist import add # error: [unresolved-import]
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/diagnostics/unresolved_i
|
|||
# Diagnostics
|
||||
|
||||
```
|
||||
error: lint:unresolved-import: Cannot resolve import `.does_not_exist.foo.bar`
|
||||
error: lint:unresolved-import: Cannot resolve imported module `.does_not_exist.foo.bar`
|
||||
--> src/mdtest_snippet.py:1:7
|
||||
|
|
||||
1 | from .does_not_exist.foo.bar import add # error: [unresolved-import]
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/diagnostics/unresolved_i
|
|||
# Diagnostics
|
||||
|
||||
```
|
||||
error: lint:unresolved-import: Cannot resolve import `does_not_exist`
|
||||
error: lint:unresolved-import: Cannot resolve imported module `does_not_exist`
|
||||
--> src/mdtest_snippet.py:1:6
|
||||
|
|
||||
1 | from does_not_exist import add # error: [unresolved-import]
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/diagnostics/unresolved_i
|
|||
# Diagnostics
|
||||
|
||||
```
|
||||
error: lint:unresolved-import: Cannot resolve import `....foo`
|
||||
error: lint:unresolved-import: Cannot resolve imported module `....foo`
|
||||
--> src/package/subpackage/subsubpackage/__init__.py:1:10
|
||||
|
|
||||
1 | from ....foo import add # error: [unresolved-import]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue