-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid treating
dataclasses.KW_ONLY
as typing-only (#12863)
## Summary Closes #12859.
- Loading branch information
1 parent
d0ac38f
commit e05953a
Showing
5 changed files
with
54 additions
and
3 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
crates/ruff_linter/resources/test/fixtures/flake8_type_checking/kw_only.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,18 @@ | ||
"""Test: avoid marking a `KW_ONLY` annotation as typing-only.""" | ||
|
||
from __future__ import annotations | ||
|
||
from dataclasses import KW_ONLY, dataclass, Field | ||
|
||
|
||
@dataclass | ||
class Test1: | ||
a: int | ||
_: KW_ONLY | ||
b: str | ||
|
||
|
||
@dataclass | ||
class Test2: | ||
a: int | ||
b: Field |
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
25 changes: 25 additions & 0 deletions
25
...__flake8_type_checking__tests__strict_typing-only-standard-library-import_kw_only.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,25 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/flake8_type_checking/mod.rs | ||
--- | ||
kw_only.py:5:45: TCH003 [*] Move standard library import `dataclasses.Field` into a type-checking block | ||
| | ||
3 | from __future__ import annotations | ||
4 | | ||
5 | from dataclasses import KW_ONLY, dataclass, Field | ||
| ^^^^^ TCH003 | ||
| | ||
= help: Move into type-checking block | ||
|
||
ℹ Unsafe fix | ||
2 2 | | ||
3 3 | from __future__ import annotations | ||
4 4 | | ||
5 |-from dataclasses import KW_ONLY, dataclass, Field | ||
5 |+from dataclasses import KW_ONLY, dataclass | ||
6 |+from typing import TYPE_CHECKING | ||
7 |+ | ||
8 |+if TYPE_CHECKING: | ||
9 |+ from dataclasses import Field | ||
6 10 | | ||
7 11 | | ||
8 12 | @dataclass |
4 changes: 4 additions & 0 deletions
4
...__rules__flake8_type_checking__tests__typing-only-standard-library-import_kw_only.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 | ||
--- | ||
|