Skip to content

Commit

Permalink
Clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
hermansje committed Mar 25, 2019
1 parent 4688f7a commit f7c85ac
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
1 change: 0 additions & 1 deletion protowhat/checks/check_funcs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from functools import partial, wraps
import copy

from protowhat.Feedback import Feedback

Expand Down
20 changes: 12 additions & 8 deletions protowhat/sct_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,16 @@ def __init__(self, stack=None, attr_scts=None):
self._attr_scts = {} if attr_scts is None else attr_scts

def __call__(self, *args, **kwargs):
if not self._crnt_sct:
if self._crnt_sct:
# calling an SCT function (after attribute access)
call_data = (self._crnt_sct, args, kwargs)
return self.__class__(self._stack + [call_data], self._attr_scts)
else:
# running the chain
state = kwargs.get("state") or args[0]
return reduce(
lambda s, cd: self._call_from_data(s, *cd), self._stack, state
)
else:
call_data = (self._crnt_sct, args, kwargs)
return self.__class__(self._stack + [call_data], self._attr_scts)

@staticmethod
def _call_from_data(state, f, args, kwargs):
Expand Down Expand Up @@ -145,9 +147,11 @@ def create_sct_context(State, sct_dict, root_state=None):
state_dec = state_dec_gen(State, sct_dict)
sct_ctx = {k: state_dec(v) for k, v in sct_dict.items()}

ctx = {**sct_ctx}
ctx["state_dec"] = state_dec # needed by ext packages
ctx["Ex"] = ExGen(root_state, sct_ctx)
ctx["F"] = partial(F, attr_scts=sct_ctx)
ctx = {
**sct_ctx,
"state_dec": state_dec, # needed by ext packages
"Ex": ExGen(root_state, sct_ctx),
"F": partial(F, attr_scts=sct_ctx),
}

return ctx
2 changes: 1 addition & 1 deletion tests/test_check_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_check_file_use_fs_no_parse(state, tf):

def test_check_no_sol(state, tf):
child = cf.check_file(state, tf.name, use_fs = True)
assert child.solution_code == None
assert child.solution_code is None

def test_check_dir(state):
with TemporaryDirectory() as td:
Expand Down
2 changes: 0 additions & 2 deletions tests/test_selectors.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from protowhat.selectors import Selector

import pytest


def test_selector_standalone():
# use python's builtin ast library
Expand Down

0 comments on commit f7c85ac

Please sign in to comment.