Skip to content

Commit c2affac

Browse files
committed
isort, black, shorten long lines, apply->eval
1 parent 9cc443f commit c2affac

File tree

4 files changed

+60
-55
lines changed

4 files changed

+60
-55
lines changed

mathics/builtin/attributes.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@
1414
"""
1515

1616

17-
from mathics.builtin.base import Predefined, Builtin
17+
from mathics.builtin.base import Builtin, Predefined
1818
from mathics.core.assignment import get_symbol_list
1919
from mathics.core.atoms import String
2020
from mathics.core.attributes import (
21-
attributes_bitset_to_list,
22-
attribute_string_to_number,
2321
A_HOLD_ALL,
2422
A_HOLD_FIRST,
2523
A_LISTABLE,
2624
A_LOCKED,
2725
A_PROTECTED,
26+
attribute_string_to_number,
27+
attributes_bitset_to_list,
2828
)
2929
from mathics.core.expression import Expression
3030
from mathics.core.list import ListExpression
@@ -256,8 +256,8 @@ class HoldAllComplete(Predefined):
256256
<dl>
257257
<dt>'HoldAllComplete'
258258
<dd>is an attribute that includes the effects of 'HoldAll' and \
259-
'SequenceHold', and also protects the function from being \
260-
affected by the upvalues of any arguments.
259+
'SequenceHold', and also protects the function from being \
260+
affected by the upvalues of any arguments.
261261
</dl>
262262
263263
'HoldAllComplete' even prevents upvalues from being used, and \
@@ -271,7 +271,8 @@ class HoldAllComplete(Predefined):
271271
= f[Sequence[a, b]]
272272
"""
273273

274-
summary_text = "attribute for symbols that keep unevaluated all their elements, and discards upvalues"
274+
summary_text = "attribute for symbols that keep unevaluated all \
275+
their elements, and discards upvalues"
275276

276277

277278
class HoldFirst(Predefined):
@@ -290,7 +291,8 @@ class HoldFirst(Predefined):
290291
= {HoldFirst, Protected, SequenceHold}
291292
"""
292293

293-
summary_text = "attribute for symbols that keep unevaluated their first element"
294+
summary_text = "attribute for symbols that keep unevaluated their \
295+
first element"
294296

295297

296298
class HoldRest(Predefined):

mathics/builtin/binary/io.py

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,33 @@
44
"""
55

66
import math
7-
import mpmath
87
import struct
9-
import sympy
10-
118
from itertools import chain
129

10+
import mpmath
11+
import sympy
12+
1313
from mathics.builtin.base import Builtin
1414
from mathics.core.atoms import Complex, Integer, MachineReal, Real, String
1515
from mathics.core.convert.expression import to_expression, to_mathics_list
1616
from mathics.core.convert.mpmath import from_mpmath
1717
from mathics.core.expression import Expression
18-
19-
from mathics.core.systemsymbols import (
20-
SymbolDirectedInfinity,
21-
SymbolIndeterminate,
22-
)
23-
2418
from mathics.core.number import dps
2519
from mathics.core.read import SymbolEndOfFile
2620
from mathics.core.streams import stream_manager
2721
from mathics.core.symbols import Symbol
28-
from mathics.core.systemsymbols import SymbolComplex
29-
22+
from mathics.core.systemsymbols import (
23+
SymbolComplex,
24+
SymbolDirectedInfinity,
25+
SymbolIndeterminate,
26+
)
3027
from mathics.eval.nevaluator import eval_N
3128

3229
SymbolBinaryWrite = Symbol("BinaryWrite")
3330

3431

3532
class _BinaryFormat:
3633
"""
37-
3834
Container for BinaryRead readers and BinaryWrite writers
3935
"""
4036

@@ -363,14 +359,18 @@ def _UnsignedInteger128_writer(s, x):
363359

364360
class BinaryRead(Builtin):
365361
"""
366-
<url>:WMA link:https://reference.wolfram.com/language/ref/BinaryRead.html</url>
362+
<url>
363+
:WMA link:
364+
https://reference.wolfram.com/language/ref/BinaryRead.html</url>
367365
368366
<dl>
369-
<dt>'BinaryRead[$stream$]'
367+
<dt>'BinaryRead[$stream$]'
370368
<dd>reads one byte from the stream as an integer from 0 to 255.
371-
<dt>'BinaryRead[$stream$, $type$]'
369+
370+
<dt>'BinaryRead[$stream$, $type$]'
372371
<dd>reads one object of specified type from the stream.
373-
<dt>'BinaryRead[$stream$, {$type1$, $type2$, ...}]'
372+
373+
<dt>'BinaryRead[$stream$, {$type1$, $type2$, ...}]'
374374
<dd>reads a sequence of objects of specified types.
375375
</dl>
376376
@@ -606,11 +606,11 @@ class BinaryRead(Builtin):
606606
"bfmt": "The stream `1` has been opened with BinaryFormat -> False and cannot be used with binary data.",
607607
}
608608

609-
def apply_empty(self, name, n, evaluation):
609+
def eval_empty(self, name, n, evaluation):
610610
"BinaryRead[InputStream[name_, n_Integer]]"
611-
return self.apply(name, n, None, evaluation)
611+
return self.eval(name, n, None, evaluation)
612612

613-
def apply(self, name, n, typ, evaluation):
613+
def eval(self, name, n, typ, evaluation):
614614
"BinaryRead[InputStream[name_, n_Integer], typ_]"
615615

616616
channel = to_expression("InputStream", name, n)
@@ -660,7 +660,9 @@ def apply(self, name, n, typ, evaluation):
660660

661661
class BinaryWrite(Builtin):
662662
"""
663-
<url>:WMA link:https://reference.wolfram.com/language/ref/BinaryWrite.html</url>
663+
<url>
664+
:WMA link:
665+
https://reference.wolfram.com/language/ref/BinaryWrite.html</url>
664666
665667
<dl>
666668
<dt>'BinaryWrite[$channel$, $b$]'
@@ -899,11 +901,11 @@ class BinaryWrite(Builtin):
899901

900902
writers = _BinaryFormat.get_writers()
901903

902-
def apply_notype(self, name, n, b, evaluation):
904+
def eval_notype(self, name, n, b, evaluation):
903905
"BinaryWrite[OutputStream[name_, n_], b_]"
904-
return self.apply(name, n, b, None, evaluation)
906+
return self.eval(name, n, b, None, evaluation)
905907

906-
def apply(self, name, n, b, typ, evaluation):
908+
def eval(self, name, n, b, typ, evaluation):
907909
"BinaryWrite[OutputStream[name_, n_], b_, typ_]"
908910

909911
channel = to_expression("OutputStream", name, n)

mathics/builtin/binary/system.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@
1111

1212
class ByteOrdering(Predefined):
1313
"""
14-
<url>:WMA link:https://reference.wolfram.com/language/ref/ByteOrdering.html</url>
14+
<url>
15+
:WMA link:
16+
https://reference.wolfram.com/language/ref/ByteOrdering.html</url>
1517
1618
<dl>
1719
<dt>'ByteOrdering'
18-
<dd> is an option for BinaryRead, BinaryWrite, and related functions that specifies what ordering
19-
of bytes should be assumed for your computer system..
20+
<dd> is an option for BinaryRead, BinaryWrite, and related functions \
21+
that specifies what ordering of bytes should be assumed for your \
22+
computer system..
2023
</dl>
2124
2225
X> ByteOrdering

mathics/builtin/comparison.py

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,12 @@
1010
# This tells documentation how to sort this module
1111
sort_order = "mathics.builtin.testing-expressions"
1212

13-
from typing import Optional, Any
13+
from typing import Any, Optional
1414

1515
import sympy
1616

17-
18-
from mathics.builtin.base import (
19-
BinaryOperator,
20-
Builtin,
21-
SympyFunction,
22-
)
23-
17+
from mathics.builtin.base import BinaryOperator, Builtin, SympyFunction
2418
from mathics.builtin.numbers.constants import mp_convert_constant
25-
2619
from mathics.core.atoms import (
2720
COMPARE_PREC,
2821
Complex,
@@ -42,7 +35,6 @@
4235
A_PROTECTED,
4336
)
4437
from mathics.core.convert.expression import to_expression, to_numeric_args
45-
from mathics.eval.nevaluator import eval_N
4638
from mathics.core.expression import Expression
4739
from mathics.core.number import dps
4840
from mathics.core.symbols import Atom, Symbol, SymbolFalse, SymbolList, SymbolTrue
@@ -55,7 +47,7 @@
5547
SymbolMaxPrecision,
5648
SymbolSign,
5749
)
58-
50+
from mathics.eval.nevaluator import eval_N
5951
from mathics.eval.numerify import numerify
6052

6153
operators = {
@@ -201,7 +193,7 @@ def numerify_args(items, evaluation) -> list:
201193
class _ComparisonOperator(_InequalityOperator):
202194
"Compares arguments in a chain e.g. a < b < c compares a < b and b < c."
203195

204-
def apply(self, items, evaluation):
196+
def eval(self, items, evaluation):
205197
"%(name)s[items___]"
206198
items_sequence = items.get_sequence()
207199
if len(items_sequence) <= 1:
@@ -340,7 +332,7 @@ def equal2(self, lhs: Any, rhs: Any, max_extra_prec=None) -> Optional[bool]:
340332
return c
341333
return None
342334

343-
def apply(self, items, evaluation):
335+
def eval(self, items, evaluation):
344336
"%(name)s[items___]"
345337
items_sequence = items.get_sequence()
346338
n = len(items_sequence)
@@ -351,7 +343,7 @@ def apply(self, items, evaluation):
351343
for arg in items_sequence
352344
]
353345
if not all(val is SymbolTrue for val in is_exact_vals):
354-
return self.apply_other(items, evaluation)
346+
return self.eval_other(items, evaluation)
355347
args = self.numerify_args(items, evaluation)
356348
for x, y in self.get_pairs(args):
357349
c = do_cplx_equal(x, y)
@@ -361,7 +353,7 @@ def apply(self, items, evaluation):
361353
return SymbolFalse
362354
return SymbolTrue
363355

364-
def apply_other(self, args, evaluation):
356+
def eval_other(self, args, evaluation):
365357
"%(name)s[args___?(!ExactNumberQ[#]&)]"
366358

367359
args = args.get_sequence()
@@ -388,7 +380,7 @@ class _MinMax(Builtin):
388380
A_FLAT | A_NUMERIC_FUNCTION | A_ONE_IDENTITY | A_ORDERLESS | A_PROTECTED
389381
)
390382

391-
def apply(self, items, evaluation):
383+
def eval(self, items, evaluation):
392384
"%(name)s[items___]"
393385
if hasattr(items, "flatten_with_respect_to_head"):
394386
items = items.flatten_with_respect_to_head(SymbolList)
@@ -447,7 +439,9 @@ def pairs(elements):
447439

448440
class BooleanQ(Builtin):
449441
"""
450-
<url>:WMA link:https://reference.wolfram.com/language/ref/BooleanQ.html</url>
442+
<url>
443+
:WMA link:
444+
https://reference.wolfram.com/language/ref/BooleanQ.html</url>
451445
452446
<dl>
453447
<dt>'BooleanQ[$expr$]'
@@ -481,7 +475,9 @@ class BooleanQ(Builtin):
481475

482476
class Equal(_EqualityOperator, _SympyComparison):
483477
"""
484-
<url>:WMA link:https://reference.wolfram.com/language/ref/Equal.html</url>
478+
<url>
479+
:WMA link:
480+
https://reference.wolfram.com/language/ref/Equal.html</url>
485481
486482
<dl>
487483
<dt>'Equal[$x$, $y$]'
@@ -644,7 +640,9 @@ class Greater(_ComparisonOperator, _SympyComparison):
644640

645641
class GreaterEqual(_ComparisonOperator, _SympyComparison):
646642
"""
647-
<url>:WMA link:https://reference.wolfram.com/language/ref/GreaterEqual.html</url>
643+
<url>
644+
:WMA link:
645+
https://reference.wolfram.com/language/ref/GreaterEqual.html</url>
648646
649647
<dl>
650648
<dt>'GreaterEqual[$x$, $y$]'
@@ -690,7 +688,7 @@ class Inequality(Builtin):
690688
}
691689
summary_text = "chain of inequalities"
692690

693-
def apply(self, items, evaluation):
691+
def eval(self, items, evaluation):
694692
"Inequality[items___]"
695693

696694
elements = numerify(items, evaluation).get_sequence()
@@ -995,7 +993,7 @@ class SameQ(_ComparisonOperator):
995993

996994
summary_text = "literal symbolic identity"
997995

998-
def apply_list(self, items, evaluation):
996+
def eval_list(self, items, evaluation):
999997
"%(name)s[items___]"
1000998
items_sequence = items.get_sequence()
1001999
if len(items_sequence) <= 1:
@@ -1145,7 +1143,7 @@ class UnsameQ(_ComparisonOperator):
11451143

11461144
summary_text = "not literal symbolic identity"
11471145

1148-
def apply_list(self, items, evaluation):
1146+
def eval_list(self, items, evaluation):
11491147
"%(name)s[items___]"
11501148
items_sequence = items.get_sequence()
11511149
if len(items_sequence) <= 1:

0 commit comments

Comments
 (0)