Skip to content

Commit 4faa3b5

Browse files
committed
Use the built-in list instead of List, etc
1 parent d75eb81 commit 4faa3b5

File tree

9 files changed

+42
-45
lines changed

9 files changed

+42
-45
lines changed

python/selfie-lib/selfie_lib/ArrayMap.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from abc import ABC, abstractmethod
22
from collections.abc import ItemsView, Iterator, Mapping, Set
3-
from typing import Any, List, Tuple, TypeVar, Union
3+
from typing import Any, TypeVar, Union
44

55
T = TypeVar("T")
66
V = TypeVar("V")
@@ -44,7 +44,7 @@ class ListBackedSet(Set[T], ABC):
4444
def __len__(self) -> int: ...
4545

4646
@abstractmethod
47-
def __getitem__(self, index: Union[int, slice]) -> Union[T, List[T]]: ...
47+
def __getitem__(self, index: Union[int, slice]) -> Union[T, list[T]]: ...
4848

4949
@abstractmethod
5050
def __iter__(self) -> Iterator[T]: ...
@@ -57,13 +57,13 @@ def _binary_search(self, item: Any) -> int:
5757

5858

5959
class ArraySet(ListBackedSet[K]):
60-
__data: List[K]
60+
__data: list[K]
6161

6262
def __init__(self):
6363
raise NotImplementedError("Use ArraySet.empty() or other class methods instead")
6464

6565
@classmethod
66-
def __create(cls, data: List[K]) -> "ArraySet[K]":
66+
def __create(cls, data: list[K]) -> "ArraySet[K]":
6767
instance = super().__new__(cls)
6868
instance.__data = data # noqa: SLF001
6969
return instance
@@ -80,7 +80,7 @@ def empty(cls) -> "ArraySet[K]":
8080
def __len__(self) -> int:
8181
return len(self.__data)
8282

83-
def __getitem__(self, index: Union[int, slice]) -> Union[K, List[K]]:
83+
def __getitem__(self, index: Union[int, slice]) -> Union[K, list[K]]:
8484
return self.__data[index]
8585

8686
def plusOrThis(self, element: K) -> "ArraySet[K]":
@@ -95,7 +95,7 @@ def plusOrThis(self, element: K) -> "ArraySet[K]":
9595

9696

9797
class _ArrayMapKeys(ListBackedSet[K]):
98-
def __init__(self, data: List[Union[K, V]]):
98+
def __init__(self, data: list[Union[K, V]]):
9999
self.__data = data
100100

101101
def __len__(self) -> int:
@@ -118,8 +118,8 @@ def __iter__(self) -> Iterator[K]:
118118
return (self.__data[i] for i in range(0, len(self.__data), 2)) # type: ignore
119119

120120

121-
class _ArrayMapEntries(ListBackedSet[Tuple[K, V]], ItemsView[K, V]):
122-
def __init__(self, data: List[Union[K, V]]):
121+
class _ArrayMapEntries(ListBackedSet[tuple[K, V]], ItemsView[K, V]):
122+
def __init__(self, data: list[Union[K, V]]):
123123
self.__data = data
124124

125125
def __len__(self) -> int:
@@ -138,21 +138,21 @@ def __getitem__(self, index: Union[int, slice]): # type: ignore
138138
else:
139139
return (self.__data[2 * index], self.__data[2 * index + 1])
140140

141-
def __iter__(self) -> Iterator[Tuple[K, V]]:
141+
def __iter__(self) -> Iterator[tuple[K, V]]:
142142
return (
143143
(self.__data[i], self.__data[i + 1]) for i in range(0, len(self.__data), 2)
144144
) # type: ignore
145145

146146

147147
class ArrayMap(Mapping[K, V]):
148-
__data: List[Union[K, V]]
148+
__data: list[Union[K, V]]
149149
__keys: ListBackedSet[K]
150150

151151
def __init__(self):
152152
raise NotImplementedError("Use ArrayMap.empty() or other class methods instead")
153153

154154
@classmethod
155-
def __create(cls, data: List[Union[K, V]]) -> "ArrayMap[K, V]":
155+
def __create(cls, data: list[Union[K, V]]) -> "ArrayMap[K, V]":
156156
instance = cls.__new__(cls)
157157
instance.__data = data # noqa: SLF001
158158
instance.__keys = _ArrayMapKeys(data) # noqa: SLF001
@@ -195,7 +195,7 @@ def plus(self, key: K, value: V) -> "ArrayMap[K, V]":
195195
new_data.insert(insert_at * 2 + 1, value)
196196
return ArrayMap.__create(new_data)
197197

198-
def minus_sorted_indices(self, indices: List[int]) -> "ArrayMap[K, V]":
198+
def minus_sorted_indices(self, indices: list[int]) -> "ArrayMap[K, V]":
199199
new_data = self.__data[:]
200200
adjusted_indices = [i * 2 for i in indices] + [i * 2 + 1 for i in indices]
201201
adjusted_indices.sort(reverse=True)

python/selfie-lib/selfie_lib/CommentTracker.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import threading
22
from collections.abc import Iterable
33
from enum import Enum, auto
4-
from typing import Dict, Tuple
54

65
from .Slice import Slice
76
from .TypedPath import TypedPath
@@ -20,7 +19,7 @@ def writable(self) -> bool:
2019

2120
class CommentTracker:
2221
def __init__(self):
23-
self.cache: Dict[TypedPath, WritableComment] = {}
22+
self.cache: dict[TypedPath, WritableComment] = {}
2423
self.lock = threading.Lock()
2524

2625
def paths_with_once(self) -> Iterable[TypedPath]:
@@ -42,7 +41,7 @@ def hasWritableComment(self, call: CallStack, layout: SnapshotFileLayout) -> boo
4241
return new_comment.writable
4342

4443
@staticmethod
45-
def commentString(typedPath: TypedPath) -> Tuple[str, int]:
44+
def commentString(typedPath: TypedPath) -> tuple[str, int]:
4645
comment, line = CommentTracker.__commentAndLine(typedPath)
4746
if comment == WritableComment.NO_COMMENT:
4847
raise ValueError("No writable comment found")
@@ -54,7 +53,7 @@ def commentString(typedPath: TypedPath) -> Tuple[str, int]:
5453
raise ValueError("Invalid comment type")
5554

5655
@staticmethod
57-
def __commentAndLine(typedPath: TypedPath) -> Tuple[WritableComment, int]:
56+
def __commentAndLine(typedPath: TypedPath) -> tuple[WritableComment, int]:
5857
with open(typedPath.absolute_path, encoding="utf-8") as file:
5958
content = Slice(file.read())
6059
for comment_str in [

python/selfie-lib/selfie_lib/Lens.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import re
22
from abc import ABC, abstractmethod
33
from collections.abc import Iterator
4-
from typing import Callable, Generic, List, Optional, Protocol, TypeVar, Union
4+
from typing import Callable, Generic, Optional, Protocol, TypeVar, Union
55

66
from .Snapshot import Snapshot, SnapshotValue
77

@@ -15,7 +15,7 @@ def __call__(self, snapshot: Snapshot) -> Snapshot:
1515

1616
class CompoundLens(Lens):
1717
def __init__(self):
18-
self.lenses: List[Lens] = []
18+
self.lenses: list[Lens] = []
1919

2020
def __call__(self, snapshot: Snapshot) -> Snapshot:
2121
current = snapshot

python/selfie-lib/selfie_lib/PerCharacterEscaper.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
from typing import List
21

32

43
class PerCharacterEscaper:
54
def __init__(
65
self,
76
escape_code_point: int,
8-
escaped_code_points: List[int],
9-
escaped_by_code_points: List[int],
7+
escaped_code_points: list[int],
8+
escaped_by_code_points: list[int],
109
):
1110
self.__escape_code_point: int = escape_code_point
12-
self.__escaped_code_points: List[int] = escaped_code_points
13-
self.__escaped_by_code_points: List[int] = escaped_by_code_points
11+
self.__escaped_code_points: list[int] = escaped_code_points
12+
self.__escaped_by_code_points: list[int] = escaped_by_code_points
1413

1514
def __first_offset_needing_escape(self, input_string: str) -> int:
1615
length: int = len(input_string)
@@ -28,7 +27,7 @@ def escape(self, input_string: str) -> str:
2827
if no_escapes == -1:
2928
return input_string
3029
else:
31-
result: List[str] = []
30+
result: list[str] = []
3231
result.append(input_string[:no_escapes])
3332
for char in input_string[no_escapes:]:
3433
codepoint: int = ord(char)
@@ -52,7 +51,7 @@ def unescape(self, input_string: str) -> str:
5251
if no_escapes == -1:
5352
return input_string
5453
else:
55-
result: List[str] = [input_string[:no_escapes]]
54+
result: list[str] = [input_string[:no_escapes]]
5655
skip_next: bool = False
5756
for i in range(no_escapes, len(input_string)):
5857
if skip_next:
@@ -76,18 +75,18 @@ def unescape(self, input_string: str) -> str:
7675

7776
@classmethod
7877
def self_escape(cls, escape_policy: str) -> "PerCharacterEscaper":
79-
code_points: List[int] = [ord(c) for c in escape_policy]
78+
code_points: list[int] = [ord(c) for c in escape_policy]
8079
escape_code_point: int = code_points[0]
8180
return cls(escape_code_point, code_points, code_points)
8281

8382
@classmethod
8483
def specified_escape(cls, escape_policy: str) -> "PerCharacterEscaper":
85-
code_points: List[int] = [ord(c) for c in escape_policy]
84+
code_points: list[int] = [ord(c) for c in escape_policy]
8685
if len(code_points) % 2 != 0:
8786
raise ValueError(
8887
"Escape policy string must have an even number of characters."
8988
)
9089
escape_code_point: int = code_points[0]
91-
escaped_code_points: List[int] = code_points[0::2]
92-
escaped_by_code_points: List[int] = code_points[1::2]
90+
escaped_code_points: list[int] = code_points[0::2]
91+
escaped_by_code_points: list[int] = code_points[1::2]
9392
return cls(escape_code_point, escaped_code_points, escaped_by_code_points)

python/selfie-lib/selfie_lib/SelfieImplementations.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import base64
22
from abc import ABC, abstractmethod
33
from itertools import chain
4-
from typing import Any, Generic, List, Optional, TypeVar
4+
from typing import Any, Generic, Optional, TypeVar
55

66
from .Literals import (
77
LiteralFormat,
@@ -114,7 +114,7 @@ def __init__(
114114
self,
115115
actual: Snapshot,
116116
disk: DiskStorage,
117-
only_facets: Optional[List[str]] = None,
117+
only_facets: Optional[list[str]] = None,
118118
):
119119
super().__init__("<IT IS AN ERROR FOR THIS TO BE VISIBLE>", actual, disk)
120120
self.only_facets = only_facets
@@ -247,7 +247,7 @@ def _assertEqual(
247247
)
248248

249249

250-
def _serializeOnlyFacets(snapshot: Snapshot, keys: List[str]) -> str:
250+
def _serializeOnlyFacets(snapshot: Snapshot, keys: list[str]) -> str:
251251
writer = []
252252
for key in keys:
253253
if not key:

python/selfie-lib/selfie_lib/SnapshotFile.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import base64
22
from threading import Lock
3-
from typing import List, Optional, Tuple
3+
from typing import Optional
44

55
from .ArrayMap import ArrayMap
66
from .Snapshot import Snapshot, SnapshotValue
@@ -14,12 +14,12 @@ class SnapshotFile:
1414

1515
def __init__(self):
1616
self.unix_newlines: bool = True
17-
self.metadata: Optional[Tuple[str, str]] = None
17+
self.metadata: Optional[tuple[str, str]] = None
1818
self.snapshots: ArrayMap[str, Snapshot] = ArrayMap.empty()
1919
self._lock: Lock = Lock()
2020
self.was_set_at_test_time: bool = False
2121

22-
def serialize(self, valueWriter: List[str]):
22+
def serialize(self, valueWriter: list[str]):
2323
if self.metadata is not None:
2424
self.writeEntry(
2525
valueWriter,
@@ -37,7 +37,7 @@ def serialize(self, valueWriter: List[str]):
3737

3838
@staticmethod
3939
def writeEntry(
40-
valueWriter: List[str], key: str, facet: Optional[str], value: SnapshotValue
40+
valueWriter: list[str], key: str, facet: Optional[str], value: SnapshotValue
4141
):
4242
valueWriter.append("╔═ ")
4343
valueWriter.append(SnapshotValueReader.name_esc.escape(key))
@@ -70,7 +70,7 @@ def set_at_test_time(self, key: str, snapshot: Snapshot) -> None:
7070
self.snapshots = self.snapshots.plus_or_noop_or_replace(key, snapshot)
7171
self.was_set_at_test_time = True
7272

73-
def remove_all_indices(self, indices: List[int]) -> None:
73+
def remove_all_indices(self, indices: list[int]) -> None:
7474
with self._lock:
7575
if not indices:
7676
return

python/selfie-lib/selfie_lib/SnapshotValueReader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import base64
2-
from typing import Callable, List, Optional
2+
from typing import Callable, Optional
33

44
from .LineReader import LineReader
55
from .ParseException import ParseException
@@ -33,7 +33,7 @@ def next_value(self) -> SnapshotValue:
3333
self.__reset_line()
3434

3535
# Read value
36-
buffer: List[str] = []
36+
buffer: list[str] = []
3737

3838
def consumer(line: str) -> None:
3939
# Check for special condition and append to buffer accordingly

python/selfie-lib/selfie_lib/WithinTestGC.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from collections.abc import Iterable
22
from threading import Lock
3-
from typing import List, Tuple
43

54
from .ArrayMap import ArrayMap, ArraySet
65
from .Snapshot import Snapshot
@@ -42,7 +41,7 @@ def find_stale_snapshots_within(
4241
snapshots: ArrayMap[str, Snapshot],
4342
tests_that_ran: ArrayMap[str, "WithinTestGC"],
4443
tests_that_didnt_run: Iterable[str],
45-
) -> List[int]:
44+
) -> list[int]:
4645
stale_indices = []
4746

4847
# combine what we know about methods that did run with what we know about the tests that didn't
@@ -57,7 +56,7 @@ def find_stale_snapshots_within(
5756
key_idx = 0
5857
while key_idx < len(keys) and gc_idx < len(gc_roots):
5958
key: str = keys[key_idx] # type: ignore
60-
gc: Tuple[str, WithinTestGC] = gc_roots[gc_idx] # type: ignore
59+
gc: tuple[str, WithinTestGC] = gc_roots[gc_idx] # type: ignore
6160
if key.startswith(gc[0]):
6261
if len(key) == len(gc[0]):
6362
# startWith + same length = exact match, no suffix

python/selfie-lib/selfie_lib/WriteTracker.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from abc import ABC
55
from functools import total_ordering
66
from pathlib import Path
7-
from typing import Dict, Generic, List, Optional, TypeVar, cast
7+
from typing import Generic, Optional, TypeVar, cast
88

99
from .FS import FS
1010
from .Literals import LiteralString, LiteralTodoStub, LiteralValue, TodoStub
@@ -60,7 +60,7 @@ def __hash__(self):
6060

6161

6262
class CallStack:
63-
def __init__(self, location: CallLocation, rest_of_stack: List[CallLocation]):
63+
def __init__(self, location: CallLocation, rest_of_stack: list[CallLocation]):
6464
self.location = location
6565
self.rest_of_stack = rest_of_stack
6666

@@ -131,7 +131,7 @@ def __init__(self, snapshot: U, call_stack: CallStack):
131131
class WriteTracker(ABC, Generic[T, U]):
132132
def __init__(self):
133133
self.lock = threading.Lock()
134-
self.writes: Dict[T, FirstWrite[U]] = {}
134+
self.writes: dict[T, FirstWrite[U]] = {}
135135

136136
def recordInternal(
137137
self,

0 commit comments

Comments
 (0)