Skip to content

Commit 22b15dd

Browse files
committed
mypy woes
1 parent ba86148 commit 22b15dd

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

mathics/__main__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,7 @@ def eval_loop(feeder: MathicsFileLineFeeder, shell: TerminalShell):
337337
print("\nKeyboardInterrupt")
338338

339339

340-
def interactive_eval_loop(
341-
shell: TerminalShell, full_form: bool, strict_wl_output: bool
342-
):
340+
def interactive_eval_loop(shell, full_form: bool, strict_wl_output: bool):
343341
"""
344342
A read eval/loop for an interactive session.
345343
`shell` is a shell session

mathics/core/evaluation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def __init__(
138138

139139
# Interrupt handlers may need access to the shell
140140
# that invoked the evaluation.
141-
self.shell: Optional[Any] = None
141+
self.shell = None
142142

143143
self.stopped = False
144144
self.timeout = False

mathics/interrupt.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,26 @@ def inspect_eval_loop(evaluation: Evaluation):
2222
A read eval/loop for an Interrupt's "inspect" command.
2323
"""
2424
shell = evaluation.shell
25-
was_inside_interrupt = shell.is_inside_interrupt
26-
shell.is_inside_interrupt = True
25+
if shell is not None:
26+
was_inside_interrupt = shell.is_inside_interrupt
27+
shell.is_inside_interrupt = True
28+
else:
29+
was_inside_interrupt = False
30+
2731
previous_recursion_depth = evaluation.recursion_depth
2832
while True:
2933
try:
3034
query, source_code = evaluation.parse_feeder_returning_code(shell)
3135
# show_echo(source_code, evaluation)
32-
if len(source_code) and source_code[0] == "!":
36+
if len(source_code) and source_code[0] == "!" and shell is not None:
3337
subprocess.run(source_code[1:], shell=True)
34-
shell.definitions.increment_line_no(1)
38+
if shell.definitions is not None:
39+
shell.definitions.increment_line_no(1)
3540
continue
3641
if query is None:
3742
continue
3843
result = evaluation.evaluate(query, timeout=settings.TIMEOUT)
39-
if result is not None:
44+
if result is not None and shell is not None:
4045
shell.print_result(result, strict_wl_output=True)
4146
except TimeoutInterrupt:
4247
print("\nTimeout occurred - ignored.")
@@ -56,7 +61,8 @@ def inspect_eval_loop(evaluation: Evaluation):
5661
raise
5762
finally:
5863
evaluation.recursion_depth = previous_recursion_depth
59-
shell.is_inside_interrupt = was_inside_interrupt
64+
if shell is not None:
65+
shell.is_inside_interrupt = was_inside_interrupt
6066

6167

6268
def mathics3_interrupt_handler(evaluation: Optional[Evaluation]):
@@ -81,12 +87,14 @@ def mathics3_interrupt_handler(evaluation: Optional[Evaluation]):
8187
print("inspecting")
8288
if evaluation is not None:
8389
evaluation.message("Interrupt", "dgbgn")
84-
inspect_eval_loop(evaluation)
90+
inspect_eval_loop(evaluation)
8591

8692
elif user_input in ("show", "s"):
8793
# In some cases we can better, by going back to the caller
8894
# and reconstructing the actual call with arguments.
8995
eval_frame = find_mathics3_evaluation_method(inspect.currentframe())
96+
if eval_frame is None:
97+
continue
9098
eval_method_name = eval_frame.f_code.co_name
9199
eval_method = getattr(eval_frame.f_locals.get("self"), eval_method_name)
92100
if eval_method:

0 commit comments

Comments
 (0)