-
Notifications
You must be signed in to change notification settings - Fork 897
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid marking InitVar as typing-only
- Loading branch information
1 parent
4ccbacd
commit a52afe7
Showing
7 changed files
with
91 additions
and
3 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
crates/ruff_linter/resources/test/fixtures/flake8_type_checking/init_var.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"""Test: avoid marking an `InitVar` as typing-only.""" | ||
|
||
from __future__ import annotations | ||
|
||
from dataclasses import FrozenInstanceError, InitVar, dataclass | ||
|
||
|
||
@dataclass | ||
class C: | ||
i: int | ||
j: int = None | ||
database: InitVar[int] = None | ||
|
||
err: FrozenInstanceError = None | ||
|
||
def __post_init__(self, database): | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
..._flake8_type_checking__tests__strict_typing-only-standard-library-import_init_var.py.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/flake8_type_checking/mod.rs | ||
--- | ||
init_var.py:5:25: TCH003 [*] Move standard library import `dataclasses.FrozenInstanceError` into a type-checking block | ||
| | ||
3 | from __future__ import annotations | ||
4 | | ||
5 | from dataclasses import FrozenInstanceError, InitVar, dataclass | ||
| ^^^^^^^^^^^^^^^^^^^ TCH003 | ||
| | ||
= help: Move into type-checking block | ||
|
||
ℹ Unsafe fix | ||
2 2 | | ||
3 3 | from __future__ import annotations | ||
4 4 | | ||
5 |-from dataclasses import FrozenInstanceError, InitVar, dataclass | ||
5 |+from dataclasses import InitVar, dataclass | ||
6 |+from typing import TYPE_CHECKING | ||
7 |+ | ||
8 |+if TYPE_CHECKING: | ||
9 |+ from dataclasses import FrozenInstanceError | ||
6 10 | | ||
7 11 | | ||
8 12 | @dataclass | ||
|
||
|
File renamed without changes.
4 changes: 4 additions & 0 deletions
4
..._rules__flake8_type_checking__tests__typing-only-standard-library-import_init_var.py.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/flake8_type_checking/mod.rs | ||
--- | ||
|