Skip to content

Commit c1f4338

Browse files
committed
Rename "Same" to "Flush"
Proper type hack for sentinel object for mypy
1 parent bddbd41 commit c1f4338

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

core/commands/log_graph.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,19 @@ def augment_color_scheme(view):
243243

244244

245245
MAX_LOOK_AHEAD = 10000
246-
Same = object()
246+
if MYPY:
247+
from enum import Enum
248+
249+
class FlushT(Enum):
250+
token = 0
251+
Flush = FlushT.token
252+
253+
else:
254+
Flush = object()
247255

248256

249257
def diff(a, b):
250-
# type: (Sequence[str], Iterable[str]) -> Iterator[Union[Ins, Del]]
258+
# type: (Sequence[str], Iterable[str]) -> Iterator[Union[Ins, Del, FlushT]]
251259
a_index = 0
252260
b_index = -1 # init in case b is empty
253261
len_a = len(a)
@@ -268,7 +276,7 @@ def diff(a, b):
268276
else:
269277
if i == 0:
270278
a_index += 1
271-
yield Same
279+
yield Flush
272280
else:
273281
len_a -= i
274282
a_index += i + 1
@@ -279,10 +287,10 @@ def diff(a, b):
279287

280288

281289
def simplify(diff, max_size):
282-
# type: (Iterable[Union[Ins, Del]], int) -> Iterator[Union[Ins, Del, Replace]]
290+
# type: (Iterable[Union[Ins, Del, FlushT]], int) -> Iterator[Union[Ins, Del, Replace]]
283291
previous = None # type: Union[Ins, Del, Replace, None]
284292
for token in diff:
285-
if token is Same:
293+
if token is Flush:
286294
if previous is not None:
287295
yield previous
288296
previous = None

tests/test_graph_diff.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
from GitSavvy.core.commands.log_graph import (
7-
diff, simplify, normalize_tokens, apply_diff, Ins, Del, Replace, Same
7+
diff, simplify, normalize_tokens, apply_diff, Ins, Del, Replace, Flush
88
)
99

1010

@@ -26,7 +26,7 @@ def tx(tokens):
2626

2727

2828
def filter_same(it):
29-
return filter(lambda t: t is not Same, it)
29+
return filter(lambda t: t is not Flush, it)
3030

3131

3232
class TestGraphDiff(DeferrableTestCase):

0 commit comments

Comments
 (0)