Skip to content

Commit de14b91

Browse files
committed
do not catch Out and MakeBoxes
blacken
1 parent 74ae499 commit de14b91

File tree

7 files changed

+32
-24
lines changed

7 files changed

+32
-24
lines changed

mathics/builtin/assignment.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,8 @@ def assign_elementary(self, lhs, rhs, evaluation, tags=None, upset=False):
315315
# $Context = $Context <> "test`"
316316
#
317317
if new_context.startswith("`"):
318-
new_context = (
319-
evaluation.definitions.get_current_context()
320-
+ new_context.lstrip("`")
318+
new_context = evaluation.definitions.get_current_context() + new_context.lstrip(
319+
"`"
321320
)
322321

323322
evaluation.definitions.set_current_context(new_context)
@@ -1320,7 +1319,7 @@ def do_clear(self, definition):
13201319
def apply_all(self, evaluation):
13211320
"ClearAll[System`All]"
13221321
evaluation.cache_result = False
1323-
evaluation.cache_expr = {}
1322+
evaluation.cache_expr = {}
13241323
evaluation.definitions.set_user_definitions({})
13251324
evaluation.definitions.clear_pymathics_modules()
13261325
return
@@ -1929,7 +1928,7 @@ class LoadModule(Builtin):
19291928

19301929
def apply(self, module, evaluation):
19311930
"LoadModule[module_String]"
1932-
evaluation.cache_result = False
1931+
evaluation.cache_result = False
19331932
try:
19341933
evaluation.definitions.load_pymathics_module(module.value)
19351934
except PyMathicsLoadException:

mathics/builtin/datentime.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ def apply(self, expr, evaluation):
213213
"Timing[expr_]"
214214
start = time.process_time()
215215
result = expr.evaluate(evaluation)
216-
evaluation.cache_result = False
217216
stop = time.process_time()
217+
evaluation.cache_result = False
218218
return Expression("List", Real(stop - start), result)
219219

220220

mathics/builtin/files_io/files.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2152,7 +2152,7 @@ class Put(BinaryOperator):
21522152
def apply(self, exprs, filename, evaluation):
21532153
"Put[exprs___, filename_String]"
21542154
evaluation.cache_result = False
2155-
2155+
21562156
instream = Expression("OpenWrite", filename).evaluate(evaluation)
21572157
if len(instream.leaves) == 2:
21582158
name, n = instream.leaves
@@ -2165,7 +2165,7 @@ def apply(self, exprs, filename, evaluation):
21652165
def apply_input(self, exprs, name, n, evaluation):
21662166
"Put[exprs___, OutputStream[name_, n_]]"
21672167
evaluation.cache_result = False
2168-
2168+
21692169
stream = stream_manager.lookup_stream(n.get_int_value())
21702170

21712171
if stream is None or stream.io.closed:
@@ -2186,7 +2186,7 @@ def apply_input(self, exprs, name, n, evaluation):
21862186
def apply_default(self, exprs, filename, evaluation):
21872187
"Put[exprs___, filename_]"
21882188
evaluation.cache_result = False
2189-
2189+
21902190
expr = Expression("Put", exprs, filename)
21912191
evaluation.message("General", "stream", filename)
21922192
return expr
@@ -2248,7 +2248,7 @@ class PutAppend(BinaryOperator):
22482248
def apply(self, exprs, filename, evaluation):
22492249
"PutAppend[exprs___, filename_String]"
22502250
evaluation.cache_result = False
2251-
2251+
22522252
instream = Expression("OpenAppend", filename).evaluate(evaluation)
22532253
if len(instream.leaves) == 2:
22542254
name, n = instream.leaves
@@ -2261,7 +2261,7 @@ def apply(self, exprs, filename, evaluation):
22612261
def apply_input(self, exprs, name, n, evaluation):
22622262
"PutAppend[exprs___, OutputStream[name_, n_]]"
22632263
evaluation.cache_result = False
2264-
2264+
22652265
stream = stream_manager.lookup_stream(n.get_int_value())
22662266

22672267
if stream is None or stream.io.closed:
@@ -2282,7 +2282,7 @@ def apply_input(self, exprs, name, n, evaluation):
22822282
def apply_default(self, exprs, filename, evaluation):
22832283
"PutAppend[exprs___, filename_]"
22842284
evaluation.cache_result = False
2285-
2285+
22862286
expr = Expression("PutAppend", exprs, filename)
22872287
evaluation.message("General", "stream", filename)
22882288
return expr
@@ -2452,7 +2452,7 @@ class FilePrint(Builtin):
24522452
def apply(self, path, evaluation, options):
24532453
"FilePrint[path_ OptionsPattern[FilePrint]]"
24542454
evaluation.cache_result = False
2455-
2455+
24562456
pypath = path.to_python()
24572457
if not (
24582458
isinstance(pypath, str)
@@ -2584,13 +2584,13 @@ def apply_input(self, name, n, evaluation):
25842584
def apply_output(self, name, n, evaluation):
25852585
"StreamPosition[OutputStream[name_, n_]]"
25862586
evaluation.cache_result = False
2587-
2587+
25882588
self.input_apply(name, n, evaluation)
25892589

25902590
def apply_default(self, stream, evaluation):
25912591
"StreamPosition[stream_]"
25922592
evaluation.cache_result = False
2593-
2593+
25942594
evaluation.message("General", "stream", stream)
25952595
return
25962596

@@ -2639,7 +2639,7 @@ class SetStreamPosition(Builtin):
26392639
def apply_input(self, name, n, m, evaluation):
26402640
"SetStreamPosition[InputStream[name_, n_], m_]"
26412641
evaluation.cache_result = False
2642-
2642+
26432643
stream = stream_manager.lookup_stream(n.get_int_value())
26442644

26452645
if stream is None or stream.io is None or stream.io.closed:
@@ -2672,13 +2672,13 @@ def apply_input(self, name, n, m, evaluation):
26722672
def apply_output(self, name, n, m, evaluation):
26732673
"SetStreamPosition[OutputStream[name_, n_], m_]"
26742674
evaluation.cache_result = False
2675-
2675+
26762676
return self.apply_input(name, n, m, evaluation)
26772677

26782678
def apply_default(self, stream, evaluation):
26792679
"SetStreamPosition[stream_]"
26802680
evaluation.cache_result = False
2681-
2681+
26822682
evaluation.message("General", "stream", stream)
26832683
return
26842684

@@ -2854,7 +2854,7 @@ class InputStream(Builtin):
28542854
def apply(self, name, n, evaluation):
28552855
"InputStream[name_, n_]"
28562856
evaluation.cache_result = False
2857-
2857+
28582858
return
28592859

28602860

@@ -2876,7 +2876,7 @@ class OutputStream(Builtin):
28762876
def apply(self, name, n, evaluation):
28772877
"OutputStream[name_, n_]"
28782878
evaluation.cache_result = False
2879-
2879+
28802880
return
28812881

28822882

@@ -2905,7 +2905,7 @@ class StringToStream(Builtin):
29052905
def apply(self, string, evaluation):
29062906
"StringToStream[string_]"
29072907
evaluation.cache_result = False
2908-
2908+
29092909
pystring = string.to_python()[1:-1]
29102910
fp = io.StringIO(str(pystring))
29112911

@@ -2941,13 +2941,13 @@ class Streams(Builtin):
29412941
def apply(self, evaluation):
29422942
"Streams[]"
29432943
evaluation.cache_result = False
2944-
2944+
29452945
return self.apply_name(None, evaluation)
29462946

29472947
def apply_name(self, name, evaluation):
29482948
"Streams[name_String]"
29492949
evaluation.cache_result = False
2950-
2950+
29512951
result = []
29522952
for stream in stream_manager.STREAMS.values():
29532953
if stream is None or stream.io.closed:

mathics/builtin/files_io/importexport.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,7 @@ def apply(self, url, elements, evaluation, options={}):
12071207

12081208
import tempfile
12091209
import os
1210+
12101211
evaluation.cache_result = False
12111212
py_url = url.get_string_value()
12121213

mathics/builtin/system.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,7 @@ class ClearSystemCache(Builtin):
623623
</dl>
624624
625625
"""
626+
626627
def apply_clear(self, evaluation):
627628
"ClearSystemCache[]"
628629
evaluation.cache_result = False
@@ -640,4 +641,3 @@ def apply_clear_numeric(self, evaluation):
640641
evaluation.cache_result = False
641642
evaluation.definitions.cache_eval = {}
642643
return
643-

mathics/core/evaluation.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ def __init__(
238238
) -> None:
239239
from mathics.core.definitions import Definitions
240240
from mathics.core.expression import Symbol
241+
241242
if definitions is None:
242243
definitions = Definitions()
243244
self.definitions = definitions

mathics/core/expression.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,6 +1318,13 @@ def evaluate(self, evaluation) -> typing.Union["Expression", "Symbol"]:
13181318
# evaluation.cache_result can be set here or from inside the evaluation
13191319
# of a branch. Once it is set to false, the result is not cached,
13201320
# and hence, not used.
1321+
if evaluation.cache_result and (self.get_head_name() in (
1322+
"System`Out",
1323+
"System`ToBoxes",
1324+
"System`MakeBoxes",
1325+
)):
1326+
evaluation.cache_result = False
1327+
13211328
if evaluation.cache_result:
13221329
expr_hash = str(self.__hash__())
13231330
else:

0 commit comments

Comments
 (0)