From ee744b524553a1b108c284d1f4e2ec5eb16a3504 Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 21 Oct 2022 19:39:45 -0700 Subject: [PATCH] Type fixes --- runner.py | 12 +++++------- tokens.py | 12 ++++++------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/runner.py b/runner.py index f67efe1..e11dfb4 100644 --- a/runner.py +++ b/runner.py @@ -10,10 +10,6 @@ from runstatus import ReduceStatus from runstatus import CommandStatus - - - - class Runner: def __init__(self): self.macro_table = {} @@ -43,7 +39,7 @@ class Runner: i = 0 macro_expansions = 0 - while i < self.reduction_limit: + while (self.reduction_limit is None) or (i < self.reduction_limit): r = expr.reduce(self.macro_table) expr = r.output @@ -64,7 +60,7 @@ class Runner: return ReduceStatus( reduction_count = i - macro_expansions, stop_reason = StopReason.MAX_EXCEEDED, - result = r.output + result = r.output # type: ignore ) @@ -89,9 +85,11 @@ class Runner: return self.exec_command(e.name) # If this line is a plain expression, reduce it. - else: + elif isinstance(e, tokens.LambdaToken): e.bind_variables() return self.reduce_expression(e) + else: + raise TypeError(f"I don't know what to do with a {type(e)}") def run_lines(self, lines: list[str]): diff --git a/tokens.py b/tokens.py index 267884b..7f615620 100755 --- a/tokens.py +++ b/tokens.py @@ -302,9 +302,9 @@ class lambda_func(LambdaToken): # Bind variables inside this function. - if isinstance(self.output, macro): + if isinstance(self.output, macro) and placeholder is not None: if self.output == placeholder: - self.output = val + self.output = val # type: ignore elif isinstance(self.output, lambda_func): self.output.bind_variables(placeholder, val) elif isinstance(self.output, lambda_apply): @@ -345,7 +345,7 @@ class lambda_func(LambdaToken): calling_self = False if bound_var is None: calling_self = True - bound_var = self.input + bound_var = self.input # type: ignore new_out = self.output if isinstance(self.output, bound_variable): if self.output == bound_var: @@ -353,7 +353,7 @@ class lambda_func(LambdaToken): elif isinstance(self.output, lambda_func): new_out = self.output.apply(val, bound_var = bound_var) elif isinstance(self.output, lambda_apply): - new_out = self.output.sub_bound_var(val, bound_var = bound_var) + new_out = self.output.sub_bound_var(val, bound_var = bound_var) # type: ignore # If we're applying THIS function, # just give the output @@ -430,7 +430,7 @@ class lambda_apply(LambdaToken): # everything below should still work as expected. if isinstance(self.fn, macro) and placeholder is not None: if self.fn == placeholder: - self.fn = val + self.fn = val # type: ignore elif isinstance(self.fn, lambda_func): self.fn.bind_variables(placeholder, val) elif isinstance(self.fn, lambda_apply): @@ -438,7 +438,7 @@ class lambda_apply(LambdaToken): if isinstance(self.arg, macro) and placeholder is not None: if self.arg == placeholder: - self.arg = val + self.arg = val # type: ignore elif isinstance(self.arg, lambda_func): self.arg.bind_variables(placeholder, val) elif isinstance(self.arg, lambda_apply):