Skip to content

Commit 2a27d46

Browse files
authored
Lint found in ListPlot-point checking branch (#1246)
The good stuff from #1245, but alas the thing we were trying to do there can cause an infinite loop in the eval_ListPlot routine. So let's do this part and narrow that PR.
1 parent 2aecdb3 commit 2a27d46

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

.github/workflows/packages.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ jobs:
3838
cd mathics/packages/Combinatorica-repo
3939
# If Combinatorica repo changes, we may need the below altered
4040
# with a branch name, (not HEAD) for testing.
41-
# git pull origin HEAD
41+
git pull origin HEAD
4242
pip install -e .[dev]
4343
remake -x check

mathics/core/expression.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -1417,8 +1417,13 @@ def rules():
14171417
if not isinstance(result, EvalMixin):
14181418
return result, False
14191419
if result.sameQ(new):
1420-
new._timestamp_cache(evaluation)
1421-
return new, False
1420+
# Even though result and new may be the same,
1421+
# new can be a Expression[SymbolConstant: System`List...]
1422+
# while "result' might be ListExpression!?
1423+
# So make sure to use "result", not "new".
1424+
if isinstance(result, Expression):
1425+
result._timestamp_cache(evaluation)
1426+
return result, False
14221427
else:
14231428
return result, True
14241429

mathics/eval/drawing/plot.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -201,19 +201,20 @@ def eval_ListPlot(
201201
[xx for xx, yy in plot_groups], [xx for xx, yy in plot_groups], x_range
202202
)
203203
plot_groups = [plot_groups]
204-
elif all(isinstance(line, list) for line in plot_groups):
205-
if not all(isinstance(line, list) for line in plot_groups):
204+
elif all(isinstance(line, (list, tuple)) for line in plot_groups):
205+
if not all(isinstance(line, (list, tuple)) for line in plot_groups):
206206
return
207207

208208
# He have a list of plot groups
209209
if all(
210-
isinstance(point, list) and len(point) == 2
211-
for plot_group in plot_groups
210+
isinstance(point, (list, tuple)) and len(point) == 2
212211
for point in plot_groups
213212
):
214213
pass
215214
elif not is_discrete_plot and all(
216-
not isinstance(point, list) for line in plot_groups for point in line
215+
not isinstance(point, (list, tuple))
216+
for line in plot_groups
217+
for point in line
217218
):
218219
# FIXME: is this right?
219220
y_min = min(plot_groups)[0]
@@ -229,7 +230,7 @@ def eval_ListPlot(
229230
# Split into plot segments
230231
plot_groups = [[plot_group] for plot_group in plot_groups]
231232
if isinstance(x_range, (list, tuple)):
232-
x_min, m_max = x_range
233+
x_min, x_max = x_range
233234
y_min, y_max = y_range
234235

235236
for lidx, plot_group in enumerate(plot_groups):

test/helper.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def evaluate(str_expr: str):
3838
def check_evaluation(
3939
str_expr: Optional[str],
4040
str_expected: Optional[str] = None,
41-
failure_message: str = "",
41+
failure_message: Optional[str] = "",
4242
hold_expected: bool = False,
4343
to_string_expr: Optional[bool] = True,
4444
to_string_expected: bool = True,

0 commit comments

Comments
 (0)