Skip to content

Commit 4b18744

Browse files
committed
Use protowhat Feedback
1 parent 3ebed23 commit 4b18744

File tree

8 files changed

+28
-76
lines changed

8 files changed

+28
-76
lines changed

pythonwhat/Feedback.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

pythonwhat/State.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from protowhat.State import State as ProtoState
99
from protowhat.selectors import DispatcherInterface
1010
from protowhat.Feedback import InstructorError
11-
from pythonwhat.Feedback import Feedback
1211
from pythonwhat import signatures
1312
from pythonwhat.converters import get_manual_converters
1413
from collections.abc import Mapping
@@ -203,26 +202,22 @@ def parse_external(self, code):
203202
e.filename = "script.py"
204203
# no line info for now
205204
self.report(
206-
Feedback(
207-
"Your code could not be parsed due to an error in the indentation:<br>`%s.`"
208-
% str(e)
209-
)
205+
"Your code could not be parsed due to an error in the indentation:<br>`%s.`"
206+
% str(e)
210207
)
211208

212209
except SyntaxError as e:
213210
e.filename = "script.py"
214211
# no line info for now
215212
self.report(
216-
Feedback(
217-
"Your code can not be executed due to a syntax error:<br>`%s.`"
218-
% str(e)
219-
)
213+
"Your code can not be executed due to a syntax error:<br>`%s.`"
214+
% str(e)
220215
)
221216

222217
# Can happen, can't catch this earlier because we can't differentiate between
223218
# TypeError in parsing or TypeError within code (at runtime).
224219
except:
225-
self.report(Feedback("Something went wrong while parsing your code."))
220+
self.report("Something went wrong while parsing your code.")
226221

227222
return res
228223

pythonwhat/checks/check_funcs.py

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
from pythonwhat.checks.check_logic import multi
22
from pythonwhat.checks.has_funcs import has_part
3-
from protowhat.Test import Test
43
from protowhat.Feedback import InstructorError
5-
from pythonwhat.Feedback import Feedback
64
from pythonwhat.tasks import setUpNewEnvInProcess, breakDownNewEnvInProcess
75
from pythonwhat.utils import get_ord
86
from pythonwhat.utils_ast import assert_ast
@@ -14,12 +12,6 @@ def render(template, kwargs):
1412
return Template(template).render(**kwargs)
1513

1614

17-
class StubState:
18-
def __init__(self, highlight, highlighting_disabled):
19-
self.highlight = highlight
20-
self.highlighting_disabled = highlighting_disabled
21-
22-
2315
def part_to_child(stu_part, sol_part, append_message, state, node_name=None):
2416
# stu_part and sol_part will be accessible on all templates
2517
append_message["kwargs"].update({"stu_part": stu_part, "sol_part": sol_part})
@@ -139,7 +131,7 @@ def check_node(
139131
stu_out[index]
140132
except (KeyError, IndexError): # TODO comment errors
141133
_msg = state.build_message(missing_msg, fmt_kwargs)
142-
state.report(Feedback(_msg, state))
134+
state.report(_msg)
143135

144136
# get node at index
145137
stu_part = stu_out[index]
@@ -167,20 +159,14 @@ def with_context(state, *args, child=None):
167159
process=state.student_process, context=state.student_parts["with_items"]
168160
)
169161
if isinstance(student_res, AttributeError):
170-
state.report(
171-
Feedback(
172-
"In your `with` statement, you're not using a correct context manager.",
173-
child.highlight, # TODO
174-
)
162+
child.report(
163+
"In your `with` statement, you're not using a correct context manager."
175164
)
176165

177166
if isinstance(student_res, (AssertionError, ValueError, TypeError)):
178-
state.report(
179-
Feedback(
180-
"In your `with` statement, the number of values in your context manager "
181-
"doesn't correspond to the number of variables you're trying to assign it to.",
182-
child.highlight,
183-
)
167+
child.report(
168+
"In your `with` statement, the number of values in your context manager "
169+
"doesn't correspond to the number of variables you're trying to assign it to."
184170
)
185171

186172
# run subtests
@@ -200,11 +186,8 @@ def with_context(state, *args, child=None):
200186
close_student_context = breakDownNewEnvInProcess(process=state.student_process)
201187
if isinstance(close_student_context, Exception):
202188
state.report(
203-
Feedback(
204-
"Your `with` statement can not be closed off correctly, you're "
205-
+ "not using the context manager correctly.",
206-
state,
207-
)
189+
"Your `with` statement can not be closed off correctly, you're "
190+
"not using the context manager correctly."
208191
)
209192
return state
210193

pythonwhat/checks/check_function.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
from pythonwhat.checks.check_funcs import part_to_child, StubState
1+
from pythonwhat.checks.check_funcs import part_to_child
22
from pythonwhat.tasks import getSignatureInProcess
33
from pythonwhat.utils import get_ord, get_times
4-
from protowhat.Test import Test
54
from protowhat.Feedback import InstructorError
6-
from pythonwhat.Feedback import Feedback
75
from pythonwhat.parsing import IndexedDict
86
from functools import partial
97

@@ -131,7 +129,7 @@ def check_function(
131129
stu_parts = {**stu_out[name][index]}
132130
except (KeyError, IndexError):
133131
_msg = state.build_message(missing_msg, fmt_kwargs, append=append_missing)
134-
state.report(Feedback(_msg, state))
132+
state.report(_msg)
135133

136134
# Signatures -----
137135
if signature:
@@ -163,11 +161,7 @@ def check_function(
163161
_msg = state.build_message(
164162
params_not_matched_msg, fmt_kwargs, append=append_params_not_matched
165163
)
166-
state.report(
167-
Feedback(
168-
_msg, StubState(stu_parts["node"], state.highlighting_disabled)
169-
)
170-
)
164+
state.to_child(highlight=stu_parts["node"]).report(_msg)
171165

172166
# three types of parts: pos_args, keywords, args (e.g. these are bound to sig)
173167
append_message = {"msg": expand_msg, "kwargs": fmt_kwargs}

pythonwhat/checks/check_has_context.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from pythonwhat.Test import EqualTest
2-
from protowhat.Feedback import InstructorError
3-
from pythonwhat.Feedback import Feedback
2+
from protowhat.Feedback import Feedback, InstructorError
43
from pythonwhat.State import State
54
from functools import singledispatch
65
from pythonwhat.checks.check_funcs import check_part_index

pythonwhat/checks/check_object.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
InstanceProcessTest,
55
DefinedCollProcessTest,
66
)
7-
from protowhat.Feedback import InstructorError
8-
from pythonwhat.Feedback import Feedback
7+
from protowhat.Feedback import Feedback, InstructorError
98
from pythonwhat.tasks import (
109
isDefinedInProcess,
1110
isInstanceInProcess,

pythonwhat/checks/has_funcs.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
)
1111
from protowhat.Test import Test
1212
from pythonwhat.Test import EqualTest, DefinedCollTest
13-
from protowhat.Feedback import InstructorError
14-
from pythonwhat.Feedback import Feedback
13+
from protowhat.Feedback import Feedback, InstructorError
1514
from pythonwhat import utils
1615
from functools import partial
1716
import re
@@ -53,7 +52,7 @@ def verify(part, index):
5352
try:
5453
verify(state.student_parts[name], index)
5554
except (KeyError, IndexError):
56-
state.report(Feedback(_msg, state))
55+
state.report(_msg)
5756

5857
return state
5958

@@ -101,7 +100,7 @@ def shout(word):
101100

102101
if d["stu_len"] != d["sol_len"]:
103102
_msg = state.build_message(unequal_msg, d)
104-
state.report(Feedback(_msg, state))
103+
state.report(_msg)
105104

106105
return state
107106

@@ -195,7 +194,7 @@ def parse_tree(tree):
195194
if exact and not code:
196195
state.do_test(EqualTest(stu_rep, sol_rep, Feedback(_msg, state)))
197196
elif not sol_rep in stu_rep:
198-
state.report(Feedback(_msg, state))
197+
state.report(_msg)
199198

200199
return state
201200

@@ -347,13 +346,12 @@ def has_expr(
347346
if (test == "error") ^ isinstance(eval_stu, Exception):
348347
fmt_kwargs["stu_str"] = str_stu
349348
_msg = state.build_message(error_msg, fmt_kwargs, append=append)
350-
feedback = Feedback(_msg, state)
351-
state.report(feedback)
349+
state.report(_msg)
352350

353351
# name is undefined after running expression
354352
if isinstance(eval_stu, UndefinedValue):
355353
_msg = state.build_message(undefined_msg, fmt_kwargs, append=append)
356-
state.report(Feedback(_msg, state))
354+
state.report(_msg)
357355

358356
# test equality of results
359357
_msg = state.build_message(incorrect_msg, fmt_kwargs, append=append)
@@ -755,7 +753,7 @@ def has_no_error(
755753
_msg = state.build_message(
756754
incorrect_msg, {"error": str(state.reporter.errors[0])}
757755
)
758-
state.report(Feedback(_msg, state))
756+
state.report(_msg)
759757

760758
return state
761759

pythonwhat/test_funcs/utils.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import ast
22

3-
from protowhat.Feedback import InstructorError
4-
from pythonwhat.Feedback import Feedback
3+
from protowhat.Feedback import Feedback, InstructorError
54
from pythonwhat.Test import EqualTest
6-
from pythonwhat.checks.check_funcs import StubState
75
from pythonwhat.checks.has_funcs import evalCalls
86
from pythonwhat.tasks import ReprFail
97

@@ -130,10 +128,10 @@ def call(
130128

131129
# either error test and no error, or vice-versa
132130
stu_node = state.student_parts["node"]
133-
stu_state = StubState(stu_node, state.highlighting_disabled)
131+
stu_state = state.to_child(highlight=stu_node)
134132
if (test == "error") ^ isinstance(eval_stu, Exception):
135133
_msg = state.build_message(error_msg, fmt_kwargs)
136-
state.report(Feedback(_msg, stu_state))
134+
stu_state.report(_msg)
137135

138136
# incorrect result
139137
_msg = state.build_message(incorrect_msg, fmt_kwargs)

0 commit comments

Comments
 (0)