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

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

View file

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

View file

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