Skip to content

Commit a83a83f

Browse files
rockymmatera
andauthored
flycheck two pytests (#1294)
@mmatera I was trying to add a test for `HoldForm[Times[x]] == Times[x]` of a recent PR of yours (from a while ago) but haven't been able to figure out how to do. in the process, I have this lint stuff from the tests. --------- Co-authored-by: Juan Mauricio Matera <[email protected]>
1 parent 3f1fb46 commit a83a83f

File tree

4 files changed

+24
-29
lines changed

4 files changed

+24
-29
lines changed

mathics/builtin/arithfns/basic.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -287,16 +287,16 @@ def format_plus(self, items, evaluation):
287287
"Plus[items__]"
288288

289289
def negate(item): # -> Expression (see FIXME below)
290-
if item.has_form("Times", 1, None):
290+
if item.has_form("Times", 2, None):
291291
if isinstance(item.elements[0], Number):
292-
neg = -item.elements[0]
293-
if neg.sameQ(Integer1):
294-
if len(item.elements) == 1:
295-
return neg
296-
else:
297-
return Expression(SymbolTimes, *item.elements[1:])
298-
else:
299-
return Expression(SymbolTimes, neg, *item.elements[1:])
292+
first, *rest = item.elements
293+
first = -first
294+
if first.sameQ(Integer1):
295+
if len(rest) == 1:
296+
return rest[0]
297+
return Expression(SymbolTimes, *rest)
298+
299+
return Expression(SymbolTimes, first, *rest)
300300
else:
301301
return Expression(SymbolTimes, IntegerM1, *item.elements)
302302
elif isinstance(item, Number):
@@ -632,6 +632,8 @@ def inverse(item):
632632
return item
633633

634634
items = items.get_sequence()
635+
if len(items) < 2:
636+
return
635637
positive = []
636638
negative = []
637639
for item in items:

test/builtin/arithmetic/test_basic.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,16 @@ def test_exponential(str_expr, str_expected):
109109
"ComplexInfinity",
110110
"Goes to the previous case because of the rule in Power",
111111
),
112+
(
113+
"HoldForm[Times[]]",
114+
"Times[]",
115+
"Times without arguments is not formatted",
116+
),
117+
(
118+
"HoldForm[Times[x]]",
119+
"Times[x]",
120+
"Times with a single argument is not formatted",
121+
),
112122
],
113123
)
114124
def test_multiply(str_expr, str_expected, msg):

test/builtin/test_evaluation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
import sys
8-
from test.helper import check_evaluation_as_in_cli, session
8+
from test.helper import check_evaluation_as_in_cli
99

1010
import pytest
1111

test/core/convert/test_sympy.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,13 @@
1212
Integer2,
1313
Integer3,
1414
IntegerM1,
15-
MachineReal,
16-
PrecisionReal,
1715
Rational,
18-
RationalOneHalf,
1916
Real,
2017
String,
2118
)
2219
from mathics.core.convert.sympy import from_sympy, sympy_singleton_to_mathics
2320
from mathics.core.expression import Expression
24-
from mathics.core.expression_predefined import (
25-
MATHICS3_COMPLEX_INFINITY,
26-
MATHICS3_INFINITY,
27-
)
21+
from mathics.core.expression_predefined import MATHICS3_COMPLEX_INFINITY
2822
from mathics.core.symbols import (
2923
Symbol,
3024
SymbolFalse,
@@ -34,18 +28,7 @@
3428
SymbolTimes,
3529
SymbolTrue,
3630
)
37-
from mathics.core.systemsymbols import (
38-
SymbolAnd,
39-
SymbolComplexInfinity,
40-
SymbolDirectedInfinity,
41-
SymbolE,
42-
SymbolExp,
43-
SymbolI,
44-
SymbolIndeterminate,
45-
SymbolInfinity,
46-
SymbolPi,
47-
SymbolSin,
48-
)
31+
from mathics.core.systemsymbols import SymbolE, SymbolExp, SymbolI, SymbolPi, SymbolSin
4932

5033
Symbol_a = Symbol("Global`a")
5134
Symbol_b = Symbol("Global`b")

0 commit comments

Comments
 (0)