Skip to content
This repository was archived by the owner on Apr 4, 2024. It is now read-only.

Commit 4d6d4c4

Browse files
committed
Update WriteTracker and CommentTracker
1 parent 5b4bd9e commit 4d6d4c4

File tree

2 files changed

+37
-43
lines changed

2 files changed

+37
-43
lines changed

python/selfie-lib/selfie_lib/CommentTracker.py

+3-41
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,8 @@
44
import threading
55

66
from selfie_lib.Slice import Slice
7-
87
from selfie_lib.TypedPath import TypedPath
9-
10-
T = TypeVar("T")
11-
12-
13-
class FS(ABC):
14-
@abstractmethod
15-
def file_walk(self, typed_path, walk: Callable[[Sequence["TypedPath"]], T]) -> T:
16-
pass
17-
18-
@abstractmethod
19-
def file_read(self, typed_path) -> str:
20-
return self.file_read_binary(typed_path).decode()
21-
22-
@abstractmethod
23-
def file_write(self, typed_path, content: str):
24-
self.file_write_binary(typed_path, content.encode())
25-
26-
@abstractmethod
27-
def file_read_binary(self, typed_path) -> bytes:
28-
pass
29-
30-
@abstractmethod
31-
def file_write_binary(self, typed_path, content: bytes):
32-
pass
33-
34-
@abstractmethod
35-
def assert_failed(self, message: str, expected=None, actual=None) -> Exception:
36-
pass
37-
38-
39-
class SnapshotFileLayout:
40-
def __init__(self, fs: FS):
41-
self.fs = fs
42-
43-
def sourcePathForCall(self, location) -> "TypedPath":
44-
raise NotImplementedError("sourcePathForCall is not implemented")
8+
from selfie_lib.WriteTracker import CallStack, SnapshotFileLayout
459

4610

4711
class WritableComment(Enum):
@@ -67,10 +31,8 @@ def pathsWithOnce(self) -> Iterable[TypedPath]:
6731
if comment == WritableComment.ONCE
6832
]
6933

70-
def hasWritableComment(self, call, layout):
71-
from selfie_lib.WriteTracker import CallStack
72-
73-
path = layout.sourcePathForCall(call.location)
34+
def hasWritableComment(self, call: CallStack, layout: SnapshotFileLayout) -> bool:
35+
path = layout.sourcePathForCall(call)
7436
with self.lock:
7537
if path in self.cache:
7638
comment = self.cache[path]

python/selfie-lib/selfie_lib/WriteTracker.py

+34-2
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,49 @@
1-
from typing import List, Optional, Generic, TypeVar, Dict, cast
1+
from typing import List, Optional, Generic, TypeVar, Dict, cast, Callable, Sequence
22
from abc import ABC, abstractmethod
33
import inspect, threading
44
from functools import total_ordering
55

6-
from selfie_lib.CommentTracker import SnapshotFileLayout
76
from selfie_lib.SourceFile import SourceFile
87
from selfie_lib.Literals import LiteralValue
8+
from selfie_lib.TypedPath import TypedPath
99

1010

1111
T = TypeVar("T")
1212
U = TypeVar("U")
1313

1414

15+
class FS(ABC):
16+
@abstractmethod
17+
def file_walk(self, typed_path, walk: Callable[[Sequence["TypedPath"]], T]) -> T:
18+
pass
19+
20+
def file_read(self, typed_path) -> str:
21+
return self.file_read_binary(typed_path).decode()
22+
23+
def file_write(self, typed_path, content: str):
24+
self.file_write_binary(typed_path, content.encode())
25+
26+
@abstractmethod
27+
def file_read_binary(self, typed_path) -> bytes:
28+
pass
29+
30+
@abstractmethod
31+
def file_write_binary(self, typed_path, content: bytes):
32+
pass
33+
34+
@abstractmethod
35+
def assert_failed(self, message: str, expected=None, actual=None) -> Exception:
36+
pass
37+
38+
39+
class SnapshotFileLayout:
40+
def __init__(self, fs: FS):
41+
self.fs = fs
42+
43+
def sourcePathForCall(self, location) -> "TypedPath":
44+
raise NotImplementedError("sourcePathForCall is not implemented")
45+
46+
1547
@total_ordering
1648
class CallLocation:
1749
def __init__(self, file_name: Optional[str], line: int):

0 commit comments

Comments
 (0)