Skip to content

Commit

Permalink
convert to safe fix, change fix title, and use real imports
Browse files Browse the repository at this point in the history
  • Loading branch information
diceroll123 committed Aug 5, 2024
1 parent ad41fab commit bdf4c2d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Bad import.
from __future__ import annotations # PYI044.
from __future__ import annotations, OtherThing # PYI044.
from __future__ import annotations, with_statement # PYI044.

# Good imports.
from __future__ import Something
from __future__ import with_statement
import sys
from socket import AF_INET
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl Violation for FutureAnnotationsInStub {
}

fn fix_title(&self) -> Option<String> {
Some("Remove `annotations` import from `__future__`".to_string())
Some("Remove `from __future__ import annotations`".to_string())
}
}

Expand Down Expand Up @@ -58,7 +58,7 @@ pub(crate) fn from_future_import(checker: &mut Checker, target: &StmtImportFrom)
checker.indexer(),
)?;

Ok(Fix::unsafe_edit(edit))
Ok(Fix::safe_edit(edit))
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ PYI044.pyi:2:1: PYI044 `from __future__ import annotations` has no effect in stu
1 | # Bad import.
2 | from __future__ import annotations # PYI044.
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI044
3 | from __future__ import annotations, OtherThing # PYI044.
3 | from __future__ import annotations, with_statement # PYI044.
|
= help: Remove `annotations` import from `__future__`
= help: Remove `from __future__ import annotations`

PYI044.pyi:3:1: PYI044 `from __future__ import annotations` has no effect in stub files, since type checkers automatically treat stubs as having those semantics
|
1 | # Bad import.
2 | from __future__ import annotations # PYI044.
3 | from __future__ import annotations, OtherThing # PYI044.
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI044
3 | from __future__ import annotations, with_statement # PYI044.
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI044
4 |
5 | # Good imports.
|
= help: Remove `annotations` import from `__future__`
= help: Remove `from __future__ import annotations`
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,33 @@ PYI044.pyi:2:1: PYI044 [*] `from __future__ import annotations` has no effect in
1 | # Bad import.
2 | from __future__ import annotations # PYI044.
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI044
3 | from __future__ import annotations, OtherThing # PYI044.
3 | from __future__ import annotations, with_statement # PYI044.
|
= help: Remove `annotations` import from `__future__`
= help: Remove `from __future__ import annotations`

Unsafe fix
Safe fix
1 1 | # Bad import.
2 |-from __future__ import annotations # PYI044.
3 2 | from __future__ import annotations, OtherThing # PYI044.
3 2 | from __future__ import annotations, with_statement # PYI044.
4 3 |
5 4 | # Good imports.

PYI044.pyi:3:1: PYI044 [*] `from __future__ import annotations` has no effect in stub files, since type checkers automatically treat stubs as having those semantics
|
1 | # Bad import.
2 | from __future__ import annotations # PYI044.
3 | from __future__ import annotations, OtherThing # PYI044.
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI044
3 | from __future__ import annotations, with_statement # PYI044.
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI044
4 |
5 | # Good imports.
|
= help: Remove `annotations` import from `__future__`
= help: Remove `from __future__ import annotations`

Unsafe fix
Safe fix
1 1 | # Bad import.
2 2 | from __future__ import annotations # PYI044.
3 |-from __future__ import annotations, OtherThing # PYI044.
3 |+from __future__ import OtherThing # PYI044.
3 |-from __future__ import annotations, with_statement # PYI044.
3 |+from __future__ import with_statement # PYI044.
4 4 |
5 5 | # Good imports.
6 6 | from __future__ import Something
6 6 | from __future__ import with_statement

0 comments on commit bdf4c2d

Please sign in to comment.