Skip to content

Commit a6b78d9

Browse files
committed
make annotations a subclass of UserList
1 parent 0b5cae1 commit a6b78d9

File tree

7 files changed

+21
-36
lines changed

7 files changed

+21
-36
lines changed

tests/tendencies/periodic/test_periodic_base.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def test_bounds(
6464
user_max=max,
6565
)
6666
if has_error:
67-
assert tendency.annotations.get()
67+
assert tendency.annotations
6868
else:
6969
assert tendency.base == approx(expected_base)
7070
assert tendency.amplitude == approx(expected_amplitude)
@@ -111,7 +111,7 @@ def test_bounds_prev(
111111
user_max=max,
112112
)
113113
if has_error:
114-
assert tendency.annotations.get()
114+
assert tendency.annotations
115115
else:
116116
tendency.set_previous_tendency(prev_tendency)
117117
assert tendency.base == approx(expected_base)
@@ -176,13 +176,13 @@ def test_frequency_and_period():
176176
assert tendency.frequency == 0.5
177177

178178
tendency = PeriodicBaseTendency(user_duration=1, user_period=2, user_frequency=2)
179-
assert tendency.annotations.get()
179+
assert tendency.annotations
180180

181181
tendency = PeriodicBaseTendency(user_duration=1, user_period=0)
182-
assert tendency.annotations.get()
182+
assert tendency.annotations
183183

184184
tendency = PeriodicBaseTendency(user_duration=1, user_frequency=0)
185-
assert tendency.annotations.get()
185+
assert tendency.annotations
186186

187187

188188
def test_phase():

tests/tendencies/test_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_first_base_tendency(
3333
base_tendency = BaseTendency(**kwargs)
3434

3535
if has_error:
36-
assert base_tendency.annotations.get()
36+
assert base_tendency.annotations
3737
else:
3838
assert base_tendency.start == approx(expected_start)
3939
assert base_tendency.duration == approx(expected_duration)
@@ -70,7 +70,7 @@ def test_second_base_tendency(
7070
base_tendency = BaseTendency(**kwargs)
7171

7272
if has_error:
73-
assert base_tendency.annotations.get()
73+
assert base_tendency.annotations
7474
else:
7575
base_tendency.set_previous_tendency(prev_tendency)
7676
assert base_tendency.start == approx(expected_start)

tests/tendencies/test_linear.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_linear_tendency(
4444
user_duration=duration, user_from=from_, user_to=to, user_rate=rate
4545
)
4646
if has_error:
47-
assert tendency.annotations.get()
47+
assert tendency.annotations
4848
else:
4949
assert tendency.duration == duration
5050
assert tendency.from_ == approx(expected_from)
@@ -80,7 +80,7 @@ def test_linear_tendency_with_prev(
8080
user_duration=duration, user_from=from_, user_to=to, user_rate=rate
8181
)
8282
if has_error:
83-
assert tendency.annotations.get()
83+
assert tendency.annotations
8484
else:
8585
tendency.set_previous_tendency(prev_tendency)
8686
assert tendency.duration == duration
@@ -119,7 +119,7 @@ def test_linear_tendency_with_next(
119119
user_duration=duration, user_from=from_, user_to=to, user_rate=rate
120120
)
121121
if has_error:
122-
assert tendency.annotations.get()
122+
assert tendency.annotations
123123
else:
124124
tendency.set_next_tendency(next_tendency)
125125
assert tendency.duration == duration

tests/tendencies/test_repeat.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,23 @@ def test_zero_start(repeat_waveform):
9191
"""Test if zero start does not raise an error."""
9292
repeat_waveform["user_waveform"][0]["start"] = 0
9393
repeat_tendency = RepeatTendency(**repeat_waveform)
94-
assert not repeat_tendency.annotations.get()
94+
assert not repeat_tendency.annotations
9595

9696

9797
def test_one_start(repeat_waveform):
9898
"""Test if non-zero start raises an error."""
9999
repeat_waveform["user_waveform"][0]["start"] = 1
100100
repeat_tendency = RepeatTendency(**repeat_waveform)
101-
assert repeat_tendency.annotations.get()
101+
assert repeat_tendency.annotations
102102

103103

104104
def test_empty():
105105
"""Test if ill-defined tendency raises an error."""
106106
repeat_tendency = RepeatTendency()
107-
assert repeat_tendency.annotations.get()
107+
assert repeat_tendency.annotations
108108

109109
repeat_tendency = RepeatTendency(user_duration=8)
110-
assert repeat_tendency.annotations.get()
110+
assert repeat_tendency.annotations
111111

112112

113113
def check_values_at_times(target_times, times, values, expected_value):
@@ -136,7 +136,7 @@ def test_filled(repeat_waveform):
136136
"""Test if tendencies in repeated waveform are filled correctly."""
137137

138138
repeat_tendency = RepeatTendency(**repeat_waveform)
139-
assert not repeat_tendency.annotations.get()
139+
assert not repeat_tendency.annotations
140140
tendencies = repeat_tendency.waveform.tendencies
141141
assert isinstance(tendencies[0], LinearTendency)
142142
assert tendencies[0].start == 0

waveform_editor/annotations.py

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,16 @@
11
import difflib
2+
from collections import UserList
23

34

4-
class Annotations:
5-
def __init__(self):
6-
self.annotations = []
7-
8-
def get(self):
9-
"""
10-
Retrieve the list of annotations stored in this instance.
11-
12-
Returns:
13-
list: A list containing all annotations.
14-
"""
15-
return self.annotations
16-
5+
class Annotations(UserList):
176
def add_annotations(self, annotations):
187
"""Merge another Annotations instance into this instance by appending its
198
annotations.
209
2110
Args:
2211
annotations: The Annotations object to append.
2312
"""
24-
return self.annotations.extend(annotations.get())
13+
return self.extend(annotations)
2514

2615
def add(self, line_number, error_msg, is_warning=False):
2716
"""Adds the error message to the list of annotations.
@@ -34,7 +23,7 @@ def add(self, line_number, error_msg, is_warning=False):
3423
treated as an error.
3524
"""
3625
error_type = "warning" if is_warning else "error"
37-
self.annotations.append(
26+
self.append(
3827
{
3928
"row": line_number,
4029
"column": 0,
@@ -73,7 +62,3 @@ def suggest(self, word_to_match, possible_matches):
7362
suggestion = f"Did you mean {close_matches[0]!r}?\n"
7463

7564
return suggestion
76-
77-
def clear(self):
78-
"""Clear all stored annotations."""
79-
self.annotations.clear()

waveform_editor/waveform.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def _process_waveform(self, waveform):
124124
self.tendencies[i].set_previous_tendency(self.tendencies[i - 1])
125125

126126
for tendency in self.tendencies:
127-
if tendency.annotations.get():
127+
if tendency.annotations:
128128
self.annotations.add_annotations(tendency.annotations)
129129

130130
def _handle_tendency(self, entry):

waveform_editor/waveform_editor_gui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def update_plot(value):
4242
yaml_alert.visible = error_alert.visible = False
4343
yaml_parser.parse_waveforms_from_string(value)
4444

45-
code_editor.annotations = yaml_parser.waveform.annotations.get()
45+
code_editor.annotations = list(yaml_parser.waveform.annotations)
4646
code_editor.param.trigger("annotations")
4747

4848
# Show alert when there is a yaml parsing error

0 commit comments

Comments
 (0)