From 57ecaf27a9e7f31aa91ee5e294f194f6b1f09b4d Mon Sep 17 00:00:00 2001 From: Gail Weiss Date: Mon, 5 Feb 2024 14:56:58 +0100 Subject: [PATCH] make all the Unfinished and RASPFunction calls explicit, so they can be easily found whenever editing things --- RASP_support/DrawCompFlow.py | 5 ++--- RASP_support/Evaluator.py | 12 ++++++------ RASP_support/FunctionalSupport.py | 8 ++++---- RASP_support/REPL.py | 6 +++--- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/RASP_support/DrawCompFlow.py b/RASP_support/DrawCompFlow.py index 58a8f72..726b910 100644 --- a/RASP_support/DrawCompFlow.py +++ b/RASP_support/DrawCompFlow.py @@ -556,12 +556,11 @@ def draw_comp_flow(self, w, filename=None, keep_dot=False, show=True, force_vertical_layers=True, add_tokens_on_ff=False): if w is not None: - self(w) # execute seq (and all its ancestors) on the given input w. - # if w==None, assume seq has already been executed on some input. + self.call(w) # execute seq (and all its ancestors) on the given input if not self.last_w == w: print("evaluating input failed") return - else: + else: # if w == None, assume seq has already been executed on some input. w = self.last_w if None is filename: name = self.name diff --git a/RASP_support/Evaluator.py b/RASP_support/Evaluator.py index e2b87f7..ee566d4 100644 --- a/RASP_support/Evaluator.py +++ b/RASP_support/Evaluator.py @@ -107,7 +107,7 @@ def __str__(self): return self.creator + " function: " + self.name \ + "(" + ", ".join(self.argnames) + ")" - def __call__(self, *args): + def call(self, *args): top_eval = args[-1] args = args[:-1] # nesting, because function shouldn't affect the enclosing environment @@ -165,7 +165,7 @@ def draw(self, ast): if not isinstance(unf, UnfinishedSequence): raise RASPTypeError("draw expects unfinished sequence, got:", unf) unf.draw_comp_flow(example) - res = unf(example) + res = unf.call(example) res.created_from_input = example self.backup_example = prev_backup return JustVal(res) @@ -557,7 +557,7 @@ def _evaluateApplication(self, ast, unf): raise RASPTypeError( "Applying unfinished expects iterable input, got:", strdesc(input_val)) - res = unf(input_val) + res = unf.call(input_val) res.created_from_input = input_val return res @@ -565,7 +565,7 @@ def _evaluateRASPFunction(self, ast, raspfun): args_trees = self._get_first_cont_list(ast.inputexprs) args = tuple(self.evaluateExpr(t) for t in args_trees) + (self,) real_args = args[:-1] - res = raspfun(*args) + res = raspfun.call(*args) if isinstance(res, Unfinished): res.setname( raspfun.name+"("+" , ".join(strdesc(a, desc_cap=20) @@ -629,7 +629,7 @@ def _test_res(self, res): if isinstance(res, Unfinished): def succeeds_with(exampe): try: - res(example, just_pass_exception_up=True) + res.call(example, just_pass_exception_up=True) except Exception: return False else: @@ -643,7 +643,7 @@ def succeeds_with(exampe): return example = self.sequence_running_example if self.backup_example \ is None else self.backup_example - res(example, just_pass_exception_up=True) + res.call(example, just_pass_exception_up=True) def evaluateExpr(self, ast, from_top=False): def format_return(res, resname="out", diff --git a/RASP_support/FunctionalSupport.py b/RASP_support/FunctionalSupport.py index 1be6c5f..e970792 100644 --- a/RASP_support/FunctionalSupport.py +++ b/RASP_support/FunctionalSupport.py @@ -175,7 +175,7 @@ def get_sorted_full_parents(self): self._sort_full_parents() return copy(self._sorted_full_parents) - def __call__(self, w, topcall=True, just_pass_exception_up=False): + def call(self, w, topcall=True, just_pass_exception_up=False): if (not isinstance(w, Iterable)) or (not w): raise RASPTypeError( "RASP sequences/selectors expect non-empty iterables, got: " @@ -201,11 +201,11 @@ def __call__(self, w, topcall=True, just_pass_exception_up=False): # further back as they use memoization for unf in self.get_sorted_full_parents(): # evaluate - unf(w, topcall=False, + unf.call(w, topcall=False, just_pass_exception_up=just_pass_exception_up) j_p_e_u = just_pass_exception_up - args = tuple(p(w, + args = tuple(p.call(w, topcall=False, just_pass_exception_up=j_p_e_u) for p in self.parents_tuple) @@ -232,7 +232,7 @@ def __call__(self, w, topcall=True, just_pass_exception_up=False): a, b, tb = sys.exc_info() tt = traceback.extract_tb(tb) last_call = max([i for i, t in enumerate(tt) - if "__call__" in str(t)]) + if "in call" in str(t)]) print(''.join(traceback.format_list(tt[last_call+1:]))) # traceback.print_exception(a,b,tb) diff --git a/RASP_support/REPL.py b/RASP_support/REPL.py index 174c141..ac79aaa 100644 --- a/RASP_support/REPL.py +++ b/RASP_support/REPL.py @@ -123,19 +123,19 @@ def print_named_val(self, name, val, ntabs=0, extra_first_pref=""): optional_exampledesc = name + \ "("+formatstr(self.sequence_running_example)+") =" print_seq(self.selector_running_example, - val(self.sequence_running_example), + val.call(self.sequence_running_example), still_on_prev_line=True, extra_pref=pref, lastpref_if_shortprint=optional_exampledesc) else: print(pref, "\t Example:", name + "(" + formatstr(self.sequence_running_example) + ") =", - val(self.sequence_running_example)) + val.call(self.sequence_running_example)) elif isinstance(val, UnfinishedSelect): print(pref, extra_first_pref, " selector:", name) if self.show_selector_examples: print(pref, "\t Example:") - print_select(self.selector_running_example, val( + print_select(self.selector_running_example, val.call( self.selector_running_example), extra_pref=pref) elif isinstance(val, RASPFunction): print(pref, extra_first_pref, " "+str(val))