Skip to content

Commit 7a19bf0

Browse files
committed
Format code
1 parent 4b18744 commit 7a19bf0

File tree

13 files changed

+86
-56
lines changed

13 files changed

+86
-56
lines changed

docs/conf.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,12 @@
4949
# Add any Sphinx extension module names here, as strings. They can be
5050
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
5151
# ones.
52-
extensions = ["sphinx.ext.autodoc", "sphinx.ext.napoleon", "sphinxcontrib.jinja", 'sphinxprettysearchresults']
52+
extensions = [
53+
"sphinx.ext.autodoc",
54+
"sphinx.ext.napoleon",
55+
"sphinxcontrib.jinja",
56+
"sphinxprettysearchresults",
57+
]
5358

5459
# Add any paths that contain templates here, relative to this directory.
5560
templates_path = ["_templates"]

pythonwhat/State.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,7 @@ def parse_external(self, code):
210210
e.filename = "script.py"
211211
# no line info for now
212212
self.report(
213-
"Your code can not be executed due to a syntax error:<br>`%s.`"
214-
% str(e)
213+
"Your code can not be executed due to a syntax error:<br>`%s.`" % str(e)
215214
)
216215

217216
# Can happen, can't catch this earlier because we can't differentiate between
@@ -258,12 +257,10 @@ def __init__(self, context_code=""):
258257
self._parser_cache = dict()
259258
context_ast = getattr(self._context_cache, context_code, None)
260259
if context_ast is None:
261-
context_ast = self._context_cache[context_code] = self.parse(
262-
context_code
263-
)[1]
264-
self.context_mappings = self._getx(
265-
FunctionParser, "mappings", context_ast
266-
)
260+
context_ast = self._context_cache[context_code] = self.parse(context_code)[
261+
1
262+
]
263+
self.context_mappings = self._getx(FunctionParser, "mappings", context_ast)
267264

268265
def find(self, name, node, *args, **kwargs):
269266
return getattr(self, name)(node)

pythonwhat/checks/check_logic.py

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
from protowhat.checks.check_logic import multi, check_not, check_or, check_correct, disable_highlighting, fail
1+
from protowhat.checks.check_logic import (
2+
multi,
3+
check_not,
4+
check_or,
5+
check_correct,
6+
disable_highlighting,
7+
fail,
8+
)
29
from protowhat.Feedback import InstructorError
310
import ast
411

512

6-
multi.__doc__ = str(multi.__doc__) + """
13+
multi.__doc__ = (
14+
str(multi.__doc__)
15+
+ """
716
:Example:
817
918
Suppose we want to verify the following function call: ::
@@ -18,9 +27,12 @@
1827
check_args('ndigits').has_equal_value()
1928
)
2029
"""
30+
)
2131

2232

23-
check_not.__doc__ = str(check_not.__doc__) + """
33+
check_not.__doc__ = (
34+
str(check_not.__doc__)
35+
+ """
2436
:Example:
2537
The SCT fails with feedback for a specific incorrect value, defined using an override: ::
2638
@@ -52,9 +64,12 @@
5264
- This function can be considered a direct counterpart of multi.
5365
5466
"""
67+
)
5568

5669

57-
check_or.__doc__ = str(check_or.__doc__) + """
70+
check_or.__doc__ = (
71+
str(check_or.__doc__)
72+
+ """
5873
:Example:
5974
6075
The SCT below tests that the student typed either 'mean' or 'median': ::
@@ -68,9 +83,12 @@
6883
the first SCT, will be presented to the student.
6984
7085
"""
86+
)
7187

7288

73-
check_correct.__doc__ = str(check_correct.__doc__) + """
89+
check_correct.__doc__ = (
90+
str(check_correct.__doc__)
91+
+ """
7492
:Example:
7593
7694
The SCT below tests whether an object is correct. Only if the object is not correct, will
@@ -82,12 +100,15 @@
82100
)
83101
84102
"""
103+
)
85104

86105

87106
# utility functions -----------------------------------------------------------
88107

89108

90-
fail.__doc__ = str(fail.__doc__) + """
109+
fail.__doc__ = (
110+
str(fail.__doc__)
111+
+ """
91112
:Example:
92113
93114
As a trivial SCT example, ::
@@ -96,6 +117,7 @@
96117
97118
This can also be helpful for debugging SCTs, as it can be used to stop testing as a given point.
98119
"""
120+
)
99121

100122

101123
def override(state, solution):
@@ -271,7 +293,9 @@ def set_env(state, **kwargs):
271293
)
272294

273295

274-
disable_highlighting.__doc__ = str(disable_highlighting.__doc__) + """
296+
disable_highlighting.__doc__ = (
297+
str(disable_highlighting.__doc__)
298+
+ """
275299
:Examples:
276300
277301
SCT that will mark the 'number' portion if it is incorrect::
@@ -284,3 +308,4 @@ def set_env(state, **kwargs):
284308
Ex().check_function('round').disable_highlighting().check_args(0).has_equal_ast()
285309
Ex().check_function('round').check_args(0).disable_highlighting().has_equal_ast()
286310
"""
311+
)

pythonwhat/checks/check_object.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
import ast
1717

1818

19-
def check_object(
20-
state, index, missing_msg=None, expand_msg=None, typestr="variable"
21-
):
19+
def check_object(state, index, missing_msg=None, expand_msg=None, typestr="variable"):
2220
"""Check object existence (and equality)
2321
2422
Check whether an object is defined in the student's process, and zoom in on its value in both
@@ -181,8 +179,12 @@ def __init__(self, n):
181179

182180
# create child state, using either parser output, or create part from name
183181
fallback = lambda: ObjectAssignmentParser.get_part(index)
184-
stu_part = state.ast_dispatcher.find("object_assignments", state.student_ast).get(index, fallback())
185-
sol_part = state.ast_dispatcher.find("object_assignments", state.solution_ast).get(index, fallback())
182+
stu_part = state.ast_dispatcher.find("object_assignments", state.student_ast).get(
183+
index, fallback()
184+
)
185+
sol_part = state.ast_dispatcher.find("object_assignments", state.solution_ast).get(
186+
index, fallback()
187+
)
186188

187189
# test object exists
188190
_msg = state.build_message(missing_msg, append_message["kwargs"])
@@ -242,9 +244,7 @@ def is_instance(state, inst, not_instance_msg=None):
242244
return state
243245

244246

245-
def check_df(
246-
state, index, missing_msg=None, not_instance_msg=None, expand_msg=None
247-
):
247+
def check_df(state, index, missing_msg=None, not_instance_msg=None, expand_msg=None):
248248
"""Check whether a DataFrame was defined and it is the right type
249249
250250
``check_df()`` is a combo of ``check_object()`` and ``is_instance()`` that checks whether the specified object exists

pythonwhat/local.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def setup_state(stu_code="", sol_code="", pec="", pid=None):
3838
student_process=stu_process,
3939
solution_process=sol_process,
4040
raw_student_output=raw_stu_output,
41-
reporter=Reporter()
41+
reporter=Reporter(),
4242
)
4343

4444
State.root_state = state

pythonwhat/probe.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ def str_branch(cls, node, str_func=lambda s: str(s)):
6161
# dict(getattr(s.data.get("bound_args", {}), 'arguments', {}))
6262
f = node.data.get("func")
6363
this_node = (
64-
" " * node.depth + "("
64+
" " * node.depth
65+
+ "("
6566
+ getattr(f, "__name__", node.name)
6667
+ str_func(node)
6768
+ ")\n"
@@ -112,7 +113,9 @@ def __call__(self, state=None):
112113
return ba.arguments["state"]
113114

114115
def __str__(self):
115-
return pp.pformat(dict(getattr(self.data.get("bound_args", {}), 'arguments', {})))
116+
return pp.pformat(
117+
dict(getattr(self.data.get("bound_args", {}), "arguments", {}))
118+
)
116119

117120
def __iter__(self):
118121
for c in self.child_list:
@@ -187,7 +190,7 @@ def __call__(self, *args, **kwargs):
187190
"""
188191
if (len(args) > 0 and not isinstance(args[0], State)) or len(args) == 0:
189192
# no state placeholder if a state is passed
190-
args = ['state_placeholder'] + list(args)
193+
args = ["state_placeholder"] + list(args)
191194

192195
bound_args = inspect.signature(self.f).bind(*args, **kwargs)
193196

@@ -200,7 +203,9 @@ def __call__(self, *args, **kwargs):
200203
arguments = bound_args.arguments
201204
for subtest in self.sub_tests: # TODO: auto sub test detection
202205
if subtest in arguments and arguments[subtest]:
203-
self.build_sub_test_nodes(arguments[subtest], self.tree, this_node, subtest)
206+
self.build_sub_test_nodes(
207+
arguments[subtest], self.tree, this_node, subtest
208+
)
204209

205210
# Second pass to build node and all its children into a subtest
206211
for node in this_node.descend(include_me=True):

pythonwhat/test_exercise.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def test_exercise(
4343
solution_process=check_process(solution_process),
4444
raw_student_output=check_str(raw_student_output),
4545
force_diagnose=force_diagnose,
46-
reporter=Reporter(errors=[error] if error else [])
46+
reporter=Reporter(errors=[error] if error else []),
4747
)
4848

4949
State.root_state = state

pythonwhat/test_funcs/test_compound_statement.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,7 @@ def shout( word = 'help', times = 3 ):
292292
"""
293293

294294
# what the function will be referred to as
295-
child = check_node(
296-
state, "function_defs", name, "definition of `{{index}}()`"
297-
)
295+
child = check_node(state, "function_defs", name, "definition of `{{index}}()`")
298296

299297
test_args(
300298
child, arg_names, arg_defaults, nb_args_msg, arg_names_msg, arg_defaults_msg
@@ -339,7 +337,7 @@ def shout( word = 'help', times = 3 ):
339337

340338

341339
def test_args(
342-
state, arg_names, arg_defaults, nb_args_msg, arg_names_msg, arg_defaults_msg
340+
state, arg_names, arg_defaults, nb_args_msg, arg_names_msg, arg_defaults_msg
343341
):
344342

345343
MSG_NUM_ARGS = "You should define {{parent[typestr]}} with {{sol_len}} arguments, instead got {{stu_len}}."
@@ -446,7 +444,11 @@ def test_object_after_expression(
446444
pre_code=None,
447445
**kwargs
448446
):
449-
state.highlight = state.ast_dispatcher.find("object_assignments", state.student_ast).get(name, {}).get("highlight")
447+
state.highlight = (
448+
state.ast_dispatcher.find("object_assignments", state.student_ast)
449+
.get(name, {})
450+
.get("highlight")
451+
)
450452
has_equal_value(
451453
state,
452454
incorrect_msg=incorrect_msg,
@@ -496,9 +498,7 @@ def test_with(
496498
if context_vals:
497499
# test context var names ----
498500
has_context(
499-
child,
500-
incorrect_msg=context_vals_msg or MSG_CTXT_NAMES,
501-
exact_names=True,
501+
child, incorrect_msg=context_vals_msg or MSG_CTXT_NAMES, exact_names=True
502502
)
503503

504504
# test num context vars ----
@@ -511,7 +511,8 @@ def test_with(
511511
for i, context_test in enumerate(context_tests or []):
512512
# partial the substate check, because the function uses two prepended messages
513513
def check_context(state):
514-
return check_part_index(state,
514+
return check_part_index(
515+
state,
515516
"context",
516517
i,
517518
"%s context" % utils.get_ord(i + 1),
@@ -543,8 +544,8 @@ def test_list_comp(
543544
):
544545
"""Test list comprehension."""
545546
kwargs = locals().copy()
546-
kwargs['typestr'] = "{{ordinal}} list comprehension"
547-
kwargs['comptype'] = "list_comps"
547+
kwargs["typestr"] = "{{ordinal}} list comprehension"
548+
kwargs["comptype"] = "list_comps"
548549
test_comp(**kwargs)
549550

550551

@@ -574,9 +575,7 @@ def test_comp(
574575
insufficient_ifs_msg = MSG_INSUFFICIENT_IFS
575576

576577
# get comprehension
577-
child = check_node(
578-
state, comptype, index - 1, typestr, missing_msg=not_called_msg
579-
)
578+
child = check_node(state, comptype, index - 1, typestr, missing_msg=not_called_msg)
580579

581580
# test comprehension iter and its variable names (or number of variables)
582581
if comp_iter:
@@ -601,7 +600,4 @@ def test_comp(
601600
# test that ifs are same length
602601
has_equal_part_len(child, "ifs", insufficient_ifs_msg)
603602
# test individual ifs
604-
multi(
605-
check_part_index(child, "ifs", i, utils.get_ord(i + 1) + " if"),
606-
if_test,
607-
)
603+
multi(check_part_index(child, "ifs", i, utils.get_ord(i + 1) + " if"), if_test)

pythonwhat/test_funcs/test_function.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,7 @@ def test_function_v2(
135135
eligible = do_eval[0] if isinstance(do_eval, list) and len(do_eval) > 0 else do_eval
136136
if name == "print" and state.parent_state is None and eligible:
137137
try:
138-
return has_printout(
139-
state, index=index, not_printed_msg=incorrect_msg[0]
140-
)
138+
return has_printout(state, index=index, not_printed_msg=incorrect_msg[0])
141139
except TestFail:
142140
# The test didn't pass; just continue with the more strict check_function test.
143141
pass

pythonwhat/test_funcs/test_object_accessed.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ def test_object_accessed(state, name, times=1, not_accessed_msg=None):
3434
| ``test_object_accessed("arr.shape")``: pass.
3535
| ``test_object_accessed("arr.dtype")``: fail.
3636
"""
37-
student_object_accesses = state.ast_dispatcher.find("object_accesses", state.student_ast)
37+
student_object_accesses = state.ast_dispatcher.find(
38+
"object_accesses", state.student_ast
39+
)
3840
student_mappings = state.ast_dispatcher.find("oa_mappings", state.student_ast)
3941

4042
if not not_accessed_msg:

0 commit comments

Comments
 (0)