Abort when unable to fix relative imports past module root (#3319)

This commit is contained in:
Charlie Marsh 2023-03-02 23:38:51 -05:00 committed by GitHub
parent 4de3882088
commit a03fa93c3a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 38 deletions

View file

@ -2,6 +2,7 @@ from typing import TYPE_CHECKING, Any, ClassVar
import attrs
from ....import unknown
from ..protocol import commands, definitions, responses
from ..server import example
from .. import server

View file

@ -94,6 +94,10 @@ fn fix_banned_relative_import(
) -> Option<Fix> {
// Only fix is the module path is known.
if let Some(mut parts) = module_path.cloned() {
if *level? >= parts.len() {
return None;
}
// Remove relative level from module path.
for _ in 0..*level? {
parts.pop();

View file

@ -10,50 +10,25 @@ expression: diagnostics
column: 0
end_location:
row: 5
column: 55
fix:
content: "from my_package.sublib.protocol import commands, definitions, responses"
location:
row: 5
column: 0
end_location:
row: 5
column: 55
column: 23
fix: ~
parent: ~
- kind:
RelativeImports:
strictness: parents
location:
row: 5
row: 6
column: 0
end_location:
row: 5
row: 6
column: 55
fix:
content: "from my_package.sublib.protocol import commands, definitions, responses"
location:
row: 5
row: 6
column: 0
end_location:
row: 5
column: 55
parent: ~
- kind:
RelativeImports:
strictness: parents
location:
row: 5
column: 0
end_location:
row: 5
column: 55
fix:
content: "from my_package.sublib.protocol import commands, definitions, responses"
location:
row: 5
column: 0
end_location:
row: 5
row: 6
column: 55
parent: ~
- kind:
@ -64,32 +39,68 @@ expression: diagnostics
column: 0
end_location:
row: 6
column: 55
fix:
content: "from my_package.sublib.protocol import commands, definitions, responses"
location:
row: 6
column: 0
end_location:
row: 6
column: 55
parent: ~
- kind:
RelativeImports:
strictness: parents
location:
row: 6
column: 0
end_location:
row: 6
column: 55
fix:
content: "from my_package.sublib.protocol import commands, definitions, responses"
location:
row: 6
column: 0
end_location:
row: 6
column: 55
parent: ~
- kind:
RelativeImports:
strictness: parents
location:
row: 7
column: 0
end_location:
row: 7
column: 28
fix:
content: from my_package.sublib.server import example
location:
row: 6
row: 7
column: 0
end_location:
row: 6
row: 7
column: 28
parent: ~
- kind:
RelativeImports:
strictness: parents
location:
row: 7
row: 8
column: 0
end_location:
row: 7
row: 8
column: 21
fix:
content: from my_package.sublib import server
location:
row: 7
row: 8
column: 0
end_location:
row: 7
row: 8
column: 21
parent: ~