Skip to content

Commit d7c490e

Browse files
authored
Refactor: Make dataclasses frozen, slots and kw_only where possible (#119)
1 parent 22eb0c1 commit d7c490e

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

auto_typing_final/finder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def has_global_identifier_with_name(root: SgNode, name: str) -> bool:
172172
return name in {identifier.text() for identifier, _ in _find_identifiers_in_current_scope(root)}
173173

174174

175-
@dataclass
175+
@dataclass(slots=True, kw_only=True)
176176
class ImportsResult:
177177
module_aliases: set[str]
178178
has_from_import: bool

auto_typing_final/lsp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def make_text_edit(edit: Edit) -> lsp.TextEdit:
7575
)
7676

7777

78-
@dataclass
78+
@dataclass(frozen=True, slots=True, kw_only=True)
7979
class Service:
8080
ls_name: str
8181
ignored_paths: list[Path]

auto_typing_final/transform.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
)
1313

1414

15-
@dataclass
15+
@dataclass(frozen=True, slots=True, kw_only=True)
1616
class ImportConfig:
1717
value: str
1818
import_text: str
@@ -26,35 +26,35 @@ class ImportConfig:
2626
}
2727

2828

29-
@dataclass
29+
@dataclass(frozen=True, slots=True)
3030
class EditableAssignmentWithoutAnnotation:
3131
node: SgNode
3232
left: str
3333
right: str
3434

3535

36-
@dataclass
36+
@dataclass(frozen=True, slots=True)
3737
class EditableAssignmentWithAnnotation:
3838
node: SgNode
3939
left: str
4040
annotation: SgNode
4141
right: str
4242

4343

44-
@dataclass
44+
@dataclass(frozen=True, slots=True)
4545
class OtherDefinition:
4646
node: SgNode
4747

4848

4949
Definition = EditableAssignmentWithoutAnnotation | EditableAssignmentWithAnnotation | OtherDefinition
5050

5151

52-
@dataclass
52+
@dataclass(frozen=True, slots=True)
5353
class AddFinal:
5454
node: Definition
5555

5656

57-
@dataclass
57+
@dataclass(frozen=True, slots=True)
5858
class RemoveFinal:
5959
nodes: list[Definition]
6060

@@ -174,20 +174,19 @@ def _make_changed_text_from_operation(
174174
yield node, f"{left}: {new_annotation} = {right}"
175175

176176

177-
# TODO: make dataclasses frozen and all other stuff # noqa: FIX002, TD002, TD003
178-
@dataclass
177+
@dataclass(frozen=True, slots=True)
179178
class Edit:
180179
node: SgNode
181180
new_text: str
182181

183182

184-
@dataclass
183+
@dataclass(frozen=True, slots=True)
185184
class Replacement:
186185
operation_type: type[Operation]
187186
edits: list[Edit]
188187

189188

190-
@dataclass
189+
@dataclass(frozen=True, slots=True)
191190
class MakeReplacementsResult:
192191
replacements: list[Replacement]
193192
import_text: str | None

0 commit comments

Comments
 (0)