From 14e1a7cc29853163039384652fb30c1f581012a6 Mon Sep 17 00:00:00 2001 From: rocky Date: Thu, 12 Jan 2023 21:55:52 -0500 Subject: [PATCH] Last of the apply->eval conversions Some type annoations for options as a dict were done here. --- mathics/algorithm/integrators.py | 2 +- mathics/builtin/atomic/strings.py | 6 +-- mathics/builtin/atomic/symbols.py | 3 +- mathics/builtin/base.py | 2 +- mathics/builtin/box/layout.py | 16 ++++---- mathics/builtin/colors/color_directives.py | 4 +- mathics/builtin/colors/color_operations.py | 13 ++++-- mathics/builtin/compress.py | 3 +- mathics/builtin/datentime.py | 8 +++- mathics/builtin/distance/clusters.py | 13 +++--- mathics/builtin/evaluation.py | 8 +++- mathics/builtin/files_io/files.py | 41 ++++++++++--------- mathics/builtin/files_io/filesystem.py | 27 ++++++------ mathics/builtin/forms/output.py | 2 +- mathics/builtin/functional/application.py | 40 ++++++++++-------- .../builtin/functional/apply_fns_to_lists.py | 37 +++++++++-------- .../functional/functional_iteration.py | 17 ++++---- mathics/builtin/image/basic.py | 2 +- mathics/builtin/makeboxes.py | 3 +- mathics/builtin/numbers/algebra.py | 25 ++++++----- mathics/builtin/numbers/calculus.py | 22 +++++----- mathics/builtin/numbers/diffeqns.py | 2 +- mathics/builtin/string/operations.py | 9 ++-- mathics/builtin/string/patterns.py | 6 +-- mathics/builtin/trace.py | 4 +- mathics/core/element.py | 2 +- mathics/core/rules.py | 5 ++- mathics/core/systemsymbols.py | 1 + test/builtin/box/test_custom_boxexpression.py | 5 ++- 29 files changed, 185 insertions(+), 143 deletions(-) diff --git a/mathics/algorithm/integrators.py b/mathics/algorithm/integrators.py index cd0c777a9..db3d18f4b 100644 --- a/mathics/algorithm/integrators.py +++ b/mathics/algorithm/integrators.py @@ -162,7 +162,7 @@ def ff(*z): return val -def apply_D_to_Integral(func, domain, var, evaluation, options, head): +def eval_D_to_Integral(func, domain, var, evaluation, options, head): """Implements D[%(name)s[func_, domain__, OptionsPattern[%(name)s]], var_Symbol]""" if head is SymbolNIntegrate: options = tuple( diff --git a/mathics/builtin/atomic/strings.py b/mathics/builtin/atomic/strings.py index 7c2839e73..fd92d40a6 100644 --- a/mathics/builtin/atomic/strings.py +++ b/mathics/builtin/atomic/strings.py @@ -937,7 +937,7 @@ class StringContainsQ(Builtin): summary_text = "test whether a pattern matches with a substring" - def eval(self, string, patt, evaluation, options): + def eval(self, string, patt, evaluation: Evaluation, options: dict): "StringContainsQ[string_, patt_, OptionsPattern[%(name)s]]" return _pattern_search( self.__class__.__name__, string, patt, evaluation, options, True @@ -1223,11 +1223,11 @@ class ToString(Builtin): summary_text = "format an expression and produce a string" - def eval_default(self, value, evaluation, options): + def eval_default(self, value, evaluation: Evaluation, options: dict): "ToString[value_, OptionsPattern[ToString]]" return self.eval_form(value, SymbolOutputForm, evaluation, options) - def eval_form(self, expr, form, evaluation, options): + def eval_form(self, expr, form, evaluation: Evaluation, options: dict): "ToString[expr_, form_, OptionsPattern[ToString]]" encoding = options["System`CharacterEncoding"] return eval_ToString(expr, form, encoding.value, evaluation) diff --git a/mathics/builtin/atomic/symbols.py b/mathics/builtin/atomic/symbols.py index 9847acac5..a68f69f01 100644 --- a/mathics/builtin/atomic/symbols.py +++ b/mathics/builtin/atomic/symbols.py @@ -22,6 +22,7 @@ attributes_bitset_to_list, ) from mathics.core.convert.expression import to_mathics_list +from mathics.core.evaluation import Evaluation from mathics.core.expression import Expression from mathics.core.list import ListExpression from mathics.core.rules import Rule @@ -583,7 +584,7 @@ def rhs(expr): ) return - def format_definition_input(self, symbol, evaluation, options): + def format_definition_input(self, symbol, evaluation: Evaluation, options: dict): "InputForm: Information[symbol_, OptionsPattern[Information]]" self.format_definition(symbol, evaluation, options, grid=False) ret = SymbolNull diff --git a/mathics/builtin/base.py b/mathics/builtin/base.py index 2cdd55590..18599bbf9 100644 --- a/mathics/builtin/base.py +++ b/mathics/builtin/base.py @@ -134,7 +134,7 @@ def eval(x, evaluation): For rules including ``OptionsPattern`` ``` - def eval_with_options(x, evaluation, options): + def eval_with_options(x, evaluation: Evaluation, options: dict): '''F[x_Real, OptionsPattern[]]''' ... ``` diff --git a/mathics/builtin/box/layout.py b/mathics/builtin/box/layout.py index 72cca105f..261bd2143 100644 --- a/mathics/builtin/box/layout.py +++ b/mathics/builtin/box/layout.py @@ -106,7 +106,7 @@ class FractionBox(BoxExpression): "FractionLine": "Automatic", } - def eval(self, num, den, evaluation, options): + def eval(self, num, den, evaluation: Evaluation, options: dict): """FractionBox[num_, den_, OptionsPattern[]]""" num_box, den_box = ( to_boxes(num, evaluation, options), @@ -322,7 +322,7 @@ class SqrtBox(BoxExpression): "MinSize": "Automatic", } - def eval_index(self, radicand, index, evaluation, options): + def eval_index(self, radicand, index, evaluation: Evaluation, options: dict): """SqrtBox[radicand_, index_, OptionsPattern[]]""" radicand_box, index_box = ( to_boxes(radicand, evaluation, options), @@ -330,7 +330,7 @@ def eval_index(self, radicand, index, evaluation, options): ) return SqrtBox(radicand_box, index_box, **options) - def eval(self, radicand, evaluation, options): + def eval(self, radicand, evaluation: Evaluation, options: dict): """SqrtBox[radicand_, OptionsPattern[]]""" radicand_box = to_boxes(radicand, evaluation, options) return SqrtBox(radicand_box, None, **options) @@ -363,11 +363,11 @@ class StyleBox(BoxExpression): attributes = A_PROTECTED | A_READ_PROTECTED summary_text = "associate boxes with styles" - def eval_options(self, boxes, evaluation, options): + def eval_options(self, boxes, evaluation: Evaluation, options: dict): """StyleBox[boxes_, OptionsPattern[]]""" return StyleBox(boxes, style="", **options) - def eval_style(self, boxes, style, evaluation, options): + def eval_style(self, boxes, style, evaluation: Evaluation, options: dict): """StyleBox[boxes_, style_String, OptionsPattern[]]""" return StyleBox(boxes, style=style, **options) @@ -418,7 +418,7 @@ class SubscriptBox(BoxExpression): "MultilineFunction": "Automatic", } - def eval(self, a, b, evaluation, options): + def eval(self, a, b, evaluation: Evaluation, options: dict): """SubscriptBox[a_, b__, OptionsPattern[]]""" a_box, b_box = ( to_boxes(a, evaluation, options), @@ -456,7 +456,7 @@ class SubsuperscriptBox(BoxExpression): "MultilineFunction": "Automatic", } - def eval(self, a, b, c, evaluation, options): + def eval(self, a, b, c, evaluation: Evaluation, options: dict): """SubsuperscriptBox[a_, b__, c__, OptionsPattern[]]""" a_box, b_box, c_box = ( to_boxes(a, evaluation, options), @@ -498,7 +498,7 @@ class SuperscriptBox(BoxExpression): "MultilineFunction": "Automatic", } - def eval(self, a, b, evaluation, options): + def eval(self, a, b, evaluation: Evaluation, options: dict): """SuperscriptBox[a_, b__, OptionsPattern[]]""" a_box, b_box = ( to_boxes(a, evaluation, options), diff --git a/mathics/builtin/colors/color_directives.py b/mathics/builtin/colors/color_directives.py index 8bdacddfa..d4ef29d94 100644 --- a/mathics/builtin/colors/color_directives.py +++ b/mathics/builtin/colors/color_directives.py @@ -16,7 +16,7 @@ from mathics.core.convert.python import from_python from mathics.core.element import ImmutableValueMixin from mathics.core.exceptions import BoxExpressionError -from mathics.core.expression import Expression +from mathics.core.expression import Evaluation, Expression from mathics.core.list import ListExpression from mathics.core.number import machine_epsilon from mathics.core.symbols import Symbol @@ -326,7 +326,7 @@ class ColorDistance(Builtin): / 100, } - def eval(self, c1, c2, evaluation, options): + def eval(self, c1, c2, evaluation: Evaluation, options: dict): "ColorDistance[c1_, c2_, OptionsPattern[ColorDistance]]" distance_function = options.get("System`DistanceFunction") diff --git a/mathics/builtin/colors/color_operations.py b/mathics/builtin/colors/color_operations.py index 589e18f66..7559f7ff6 100644 --- a/mathics/builtin/colors/color_operations.py +++ b/mathics/builtin/colors/color_operations.py @@ -13,7 +13,7 @@ from mathics.builtin.colors.color_directives import ColorError, RGBColor, _ColorObject from mathics.builtin.colors.color_internals import convert_color from mathics.builtin.image.base import Image -from mathics.core.atoms import Integer, MachineReal, Rational, Real +from mathics.core.atoms import Integer, MachineReal, Rational, Real, String from mathics.core.convert.expression import to_expression, to_mathics_list from mathics.core.evaluation import Evaluation from mathics.core.expression import Expression @@ -337,10 +337,17 @@ class DominantColors(Builtin): options = {"ColorCoverage": "Automatic", "MinColorDistance": "Automatic"} summary_text = "find a list of dominant colors" - def eval(self, image, n, prop, evaluation, options): + def eval( + self, + image: Image, + n: Integer, + prop: String, + evaluation: Evaluation, + options: dict, + ): "DominantColors[image_Image, n_Integer, prop_String, OptionsPattern[%(name)s]]" - py_prop = prop.get_string_value() + py_prop = prop.value if py_prop not in ("Color", "LABColor", "Count", "Coverage", "CoverageImage"): return diff --git a/mathics/builtin/compress.py b/mathics/builtin/compress.py index 86be1caea..340c2d3ae 100644 --- a/mathics/builtin/compress.py +++ b/mathics/builtin/compress.py @@ -6,6 +6,7 @@ from mathics.builtin.base import Builtin from mathics.core.atoms import String +from mathics.core.evaluation import Evaluation class Compress(Builtin): @@ -29,7 +30,7 @@ class Compress(Builtin): } summary_text = "compress an expression" - def eval(self, expr, evaluation, options): + def eval(self, expr, evaluation: Evaluation, options: dict): "Compress[expr_, OptionsPattern[Compress]]" if isinstance(expr, String): string = '"' + expr.value + '"' diff --git a/mathics/builtin/datentime.py b/mathics/builtin/datentime.py index 8f550d4a2..ca92db99f 100644 --- a/mathics/builtin/datentime.py +++ b/mathics/builtin/datentime.py @@ -26,7 +26,11 @@ from mathics.core.convert.expression import to_expression, to_mathics_list from mathics.core.convert.python import from_python from mathics.core.element import ImmutableValueMixin -from mathics.core.evaluation import TimeoutInterrupt, run_with_timeout_and_stack +from mathics.core.evaluation import ( + Evaluation, + TimeoutInterrupt, + run_with_timeout_and_stack, +) from mathics.core.expression import Expression from mathics.core.list import ListExpression from mathics.core.symbols import Symbol, SymbolNull @@ -625,7 +629,7 @@ class DateObject(_DateFormat, ImmutableValueMixin): " an object representing a date of any granularity (year, hour, instant, ...)" ) - def eval_any(self, args, evaluation, options): + def eval_any(self, args, evaluation: Evaluation, options: dict): "DateObject[args_, OptionsPattern[]]" datelist = None tz = None diff --git a/mathics/builtin/distance/clusters.py b/mathics/builtin/distance/clusters.py index 77d0e1714..29c27ed0b 100644 --- a/mathics/builtin/distance/clusters.py +++ b/mathics/builtin/distance/clusters.py @@ -18,6 +18,7 @@ from mathics.builtin.options import options_to_rules from mathics.core.atoms import Integer, Real, String, machine_precision, min_prec from mathics.core.convert.expression import to_mathics_list +from mathics.core.evaluation import Evaluation from mathics.core.expression import Expression from mathics.core.list import ListExpression from mathics.core.symbols import Symbol, strip_context @@ -265,7 +266,7 @@ class ClusteringComponents(_Cluster): summary_text = "label data with the index of the cluster it is in" - def eval(self, p, evaluation, options): + def eval(self, p, evaluation: Evaluation, options: dict): "ClusteringComponents[p_, OptionsPattern[%(name)s]]" return self._cluster( p, @@ -276,7 +277,7 @@ def eval(self, p, evaluation, options): Expression(SymbolClusteringComponents, p, *options_to_rules(options)), ) - def eval_manual_k(self, p, k: Integer, evaluation, options): + def eval_manual_k(self, p, k: Integer, evaluation: Evaluation, options: dict): "ClusteringComponents[p_, k_Integer, OptionsPattern[%(name)s]]" return self._cluster( p, @@ -346,7 +347,7 @@ class FindClusters(_Cluster): summary_text = "divide data into lists of similar elements" - def eval(self, p, evaluation, options): + def eval(self, p, evaluation: Evaluation, options: dict): "FindClusters[p_, OptionsPattern[%(name)s]]" return self._cluster( p, @@ -357,7 +358,7 @@ def eval(self, p, evaluation, options): Expression(SymbolFindClusters, p, *options_to_rules(options)), ) - def eval_manual_k(self, p, k: Integer, evaluation, options): + def eval_manual_k(self, p, k: Integer, evaluation: Evaluation, options: dict): "FindClusters[p_, k_Integer, OptionsPattern[%(name)s]]" return self._cluster( p, @@ -422,7 +423,9 @@ class Nearest(Builtin): } summary_text = "the nearest element from a list" - def eval(self, items, pivot, limit, expression, evaluation, options): + def eval( + self, items, pivot, limit, expression, evaluation: Evaluation, options: dict + ): "Nearest[items_, pivot_, limit_, OptionsPattern[%(name)s]]" method = self.get_option(options, "Method", evaluation) diff --git a/mathics/builtin/evaluation.py b/mathics/builtin/evaluation.py index d4ca1c06c..0e743586b 100644 --- a/mathics/builtin/evaluation.py +++ b/mathics/builtin/evaluation.py @@ -4,7 +4,11 @@ from mathics.builtin.base import Builtin, Predefined from mathics.core.atoms import Integer from mathics.core.attributes import A_HOLD_ALL, A_HOLD_ALL_COMPLETE, A_PROTECTED -from mathics.core.evaluation import MAX_RECURSION_DEPTH, set_python_recursion_limit +from mathics.core.evaluation import ( + MAX_RECURSION_DEPTH, + Evaluation, + set_python_recursion_limit, +) class RecursionLimit(Predefined): @@ -376,7 +380,7 @@ class Quit(Builtin): } summary_text = "terminate the session" - def apply(self, evaluation, n): + def eval(self, evaluation: Evaluation, n): "%(name)s[n___]" exitcode = 0 if isinstance(n, Integer): diff --git a/mathics/builtin/files_io/files.py b/mathics/builtin/files_io/files.py index 35731d81e..cc02f9812 100644 --- a/mathics/builtin/files_io/files.py +++ b/mathics/builtin/files_io/files.py @@ -26,6 +26,7 @@ from mathics.core.attributes import A_PROTECTED, A_READ_PROTECTED from mathics.core.convert.expression import to_expression, to_mathics_list from mathics.core.convert.python import from_python +from mathics.core.evaluation import Evaluation from mathics.core.expression import BoxError, Expression from mathics.core.parser import MathicsFileLineFeeder, parse from mathics.core.read import ( @@ -110,7 +111,7 @@ class _OpenAction(Builtin): ), } - def eval_empty(self, evaluation, options): + def eval_empty(self, evaluation: Evaluation, options: dict): "%(name)s[OptionsPattern[]]" if isinstance(self, (OpenWrite, OpenAppend)): @@ -128,7 +129,7 @@ def eval_empty(self, evaluation, options): evaluation.message("OpenRead", "argx") return - def eval_path(self, path, evaluation, options): + def eval_path(self, path, evaluation: Evaluation, options: dict): "%(name)s[path_?NotOptionQ, OptionsPattern[]]" # Options @@ -267,8 +268,8 @@ class Expression_(Builtin): https://mathics-development-guide.readthedocs.io/en/latest/extending/code-overview/ast.html. """ - summary_text = "WL expression" name = "Expression" + summary_text = "WL expression" class FilePrint(Builtin): @@ -294,7 +295,6 @@ class FilePrint(Builtin): = FilePrint[] """ - summary_text = "display the contents of a file" messages = { "fstr": ( "File specification `1` is not a string of " "one or more characters." @@ -306,8 +306,9 @@ class FilePrint(Builtin): "RecordSeparators": '{"\r\n", "\n", "\r"}', "WordSeparators": '{" ", "\t"}', } + summary_text = "display the contents of a file" - def eval(self, path, evaluation, options): + def eval(self, path, evaluation: Evaluation, options: dict): "FilePrint[path_, OptionsPattern[FilePrint]]" pypath = path.to_python() if not ( @@ -367,8 +368,8 @@ class Number_(Builtin): """ - summary_text = "exact or approximate number in Fortran‐like notation" name = "Number" + summary_text = "exact or approximate number in Fortran‐like notation" class Get(PrefixOperator): @@ -408,14 +409,14 @@ class Get(PrefixOperator): #> Hold[<<`/.\-_:$*~?] // FullForm = Hold[Get["`/.\\\\-_:$*~?"]] """ - summary_text = "read in a file and evaluate commands in it" operator = "<<" - precedence = 720 options = { "Trace": "False", } + precedence = 720 + summary_text = "read in a file and evaluate commands in it" - def eval(self, path, evaluation, options): + def eval(self, path, evaluation: Evaluation, options: dict): "Get[path_String, OptionsPattern[Get]]" def check_options(options): @@ -607,11 +608,11 @@ class OpenAppend(_OpenAction): #> DeleteFile["MathicsNonExampleFile"] """ + mode = "a" + stream_type = "OutputStream" summary_text = ( "open an output stream to a file, appending to what was already in the file" ) - mode = "a" - stream_type = "OutputStream" class Put(BinaryOperator): @@ -667,9 +668,9 @@ class Put(BinaryOperator): S> DeleteFile[filename] """ - summary_text = "write an expression to a file" operator = ">>" precedence = 30 + summary_text = "write an expression to a file" def eval(self, exprs, filename, evaluation): "Put[exprs___, filename_String]" @@ -765,9 +766,9 @@ class PutAppend(BinaryOperator): = x >>> /proc/uptime """ - summary_text = "append an expression to a file" operator = ">>>" precedence = 30 + summary_text = "append an expression to a file" def eval(self, exprs, filename, evaluation): "PutAppend[exprs___, filename_String]" @@ -962,7 +963,6 @@ class Read(Builtin): """ - summary_text = "read an object of the specified type from a stream" messages = { "openx": "`1` is not open.", "readf": "`1` is not a valid format specification.", @@ -984,6 +984,7 @@ class Read(Builtin): "TokenWords": "{}", "WordSeparators": '{" ", "\t"}', } + summary_text = "read an object of the specified type from a stream" def check_options(self, options): # Options @@ -1050,7 +1051,7 @@ def check_options(self, options): return result - def eval(self, channel, types, evaluation, options): + def eval(self, channel, types, evaluation: Evaluation, options: dict): "Read[channel_, types_, OptionsPattern[Read]]" name, n, stream = read_name_and_stream_from_channel(channel, evaluation) @@ -1258,7 +1259,6 @@ class ReadList(Read): >> InputForm[%] = {123, abc} """ - summary_text = "read a sequence of elements from a file, and put them in a WL list" rules = { "ReadList[stream_]": "ReadList[stream, Expression]", } @@ -1270,8 +1270,9 @@ class ReadList(Read): "TokenWords": "{}", "WordSeparators": '{" ", "\t"}', } + summary_text = "read a sequence of elements from a file, and put them in a WL list" - def eval(self, channel, types, evaluation, options): + def eval(self, channel, types, evaluation: Evaluation, options: dict): "ReadList[channel_, types_, OptionsPattern[ReadList]]" # Options @@ -1298,7 +1299,7 @@ def eval(self, channel, types, evaluation, options): result.append(tmp) return from_python(result) - def eval_m(self, channel, types, m, evaluation, options): + def eval_m(self, channel, types, m, evaluation: Evaluation, options: dict): "ReadList[channel_, types_, m_, OptionsPattern[ReadList]]" # Options @@ -1507,7 +1508,7 @@ class Skip(Read): } summary_text = "skip over an object of the specified type in an input stream" - def eval(self, name, n, types, m, evaluation, options): + def eval(self, name, n, types, m, evaluation: Evaluation, options: dict): "Skip[InputStream[name_, n_], types_, m_, OptionsPattern[Skip]]" channel = to_expression("InputStream", name, n) @@ -1571,7 +1572,7 @@ class Find(Read): } summary_text = "find the next occurrence of a string" - def eval(self, name, n, text, evaluation, options): + def eval(self, name, n, text, evaluation: Evaluation, options: dict): "Find[InputStream[name_, n_], text_, OptionsPattern[Find]]" # Options diff --git a/mathics/builtin/files_io/filesystem.py b/mathics/builtin/files_io/filesystem.py index eea97e6f7..c7dadbba5 100644 --- a/mathics/builtin/files_io/filesystem.py +++ b/mathics/builtin/files_io/filesystem.py @@ -27,6 +27,7 @@ ) from mathics.core.convert.expression import to_expression, to_mathics_list from mathics.core.convert.python import from_python +from mathics.core.evaluation import Evaluation from mathics.core.expression import Expression from mathics.core.streams import ( HOME_DIR, @@ -270,7 +271,7 @@ class CreateDirectory(Builtin): } summary_text = "create a directory" - def eval(self, dirname, evaluation, options): + def eval(self, dirname, evaluation: Evaluation, options: dict): "CreateDirectory[dirname_, OptionsPattern[CreateDirectory]]" expr = to_expression("CreateDirectory", dirname) @@ -294,7 +295,7 @@ def eval(self, dirname, evaluation, options): return String(osp.abspath(py_dirname)) - def eval_empty(self, evaluation, options): + def eval_empty(self, evaluation: Evaluation, options: dict): "CreateDirectory[OptionsPattern[CreateDirectory]]" dirname = tempfile.mkdtemp(prefix="m", dir=TMP_DIR) return String(dirname) @@ -391,7 +392,7 @@ class DeleteDirectory(Builtin): } summary_text = "delete a directory" - def eval(self, dirname, evaluation, options): + def eval(self, dirname, evaluation: Evaluation, options: dict): "DeleteDirectory[dirname_, OptionsPattern[DeleteDirectory]]" expr = to_expression("DeleteDirectory", dirname) @@ -554,7 +555,7 @@ class DirectoryName(Builtin): } summary_text = "directory part of a filename" - def eval_with_n(self, name, n, evaluation, options): + def eval_with_n(self, name, n, evaluation: Evaluation, options: dict): "DirectoryName[name_, n_, OptionsPattern[DirectoryName]]" if n is None: @@ -580,7 +581,7 @@ def eval_with_n(self, name, n, evaluation, options): return String(result) - def eval(self, name, evaluation, options): + def eval(self, name, evaluation: Evaluation, options: dict): "DirectoryName[name_, OptionsPattern[DirectoryName]]" return self.eval_with_n(name, None, evaluation, options) @@ -723,7 +724,7 @@ class FileBaseName(Builtin): } summary_text = "base name of the file" - def eval(self, filename, evaluation, options): + def eval(self, filename, evaluation: Evaluation, options: dict): "FileBaseName[filename_String, OptionsPattern[FileBaseName]]" path = filename.to_python()[1:-1] @@ -944,7 +945,7 @@ class FileExtension(Builtin): } summary_text = "file extension" - def eval(self, filename, evaluation, options): + def eval(self, filename, evaluation: Evaluation, options: dict): "FileExtension[filename_String, OptionsPattern[FileExtension]]" path = filename.to_python()[1:-1] filename_base, filename_ext = osp.splitext(path) @@ -1116,7 +1117,7 @@ class FileNameJoin(Builtin): } summary_text = "join parts into a path" - def eval(self, pathlist, evaluation, options): + def eval(self, pathlist, evaluation: Evaluation, options: dict): "FileNameJoin[pathlist_List, OptionsPattern[FileNameJoin]]" py_pathlist = pathlist.to_python() @@ -1420,7 +1421,7 @@ class FileNameSplit(Builtin): summary_text = "split the file name in a list of parts" - def eval(self, filename, evaluation, options): + def eval(self, filename, evaluation: Evaluation, options: dict): "FileNameSplit[filename_String, OptionsPattern[FileNameSplit]]" path = filename.to_python()[1:-1] @@ -1483,12 +1484,12 @@ class FileNameTake(Builtin): } summary_text = "take a part of the filename" - def eval(self, filename, evaluation, options): + def eval(self, filename, evaluation: Evaluation, options: dict): "FileNameTake[filename_String, OptionsPattern[FileBaseName]]" path = pathlib.Path(filename.to_python()[1:-1]) return String(path.name) - def eval_n(self, filename, n, evaluation, options): + def eval_n(self, filename, n, evaluation: Evaluation, options: dict): "FileNameTake[filename_String, n_Integer, OptionsPattern[FileBaseName]]" n_int = n.get_int_value() parts = pathlib.Path(filename.to_python()[1:-1]).parts @@ -1545,11 +1546,11 @@ class FindList(Builtin): # TODO: Extra options AnchoredSearch, IgnoreCase RecordSeparators, # WordSearch, WordSeparators this is probably best done with a regex - def eval_without_n(self, filename, text, evaluation, options): + def eval_without_n(self, filename, text, evaluation: Evaluation, options: dict): "FindList[filename_, text_, OptionsPattern[FindList]]" return self.eval(filename, text, None, evaluation, options) - def eval(self, filename, text, n, evaluation, options): + def eval(self, filename, text, n, evaluation: Evaluation, options: dict): "FindList[filename_, text_, n_, OptionsPattern[FindList]]" py_text = text.to_python() py_name = filename.to_python() diff --git a/mathics/builtin/forms/output.py b/mathics/builtin/forms/output.py index 5e66a2095..cc12d2642 100644 --- a/mathics/builtin/forms/output.py +++ b/mathics/builtin/forms/output.py @@ -275,7 +275,7 @@ class _NumberForm(Builtin): "sigz": "In addition to the number of digits requested, one or more zeros will appear as placeholders.", } - def check_options(self, options, evaluation: Evaluation): + def check_options(self, options: dict, evaluation: Evaluation): """ Checks options are valid and converts them to python. """ diff --git a/mathics/builtin/functional/application.py b/mathics/builtin/functional/application.py index c39c29ac6..acdeb8c56 100644 --- a/mathics/builtin/functional/application.py +++ b/mathics/builtin/functional/application.py @@ -13,6 +13,7 @@ from mathics.builtin.base import Builtin, PostfixOperator from mathics.core.attributes import A_HOLD_ALL, A_N_HOLD_ALL, A_PROTECTED from mathics.core.convert.sympy import SymbolFunction +from mathics.core.evaluation import Evaluation from mathics.core.expression import Expression from mathics.core.symbols import Symbol @@ -66,11 +67,11 @@ class Function(PostfixOperator): In the evaluation process, the attributes associated with an Expression are \ determined by its Head. If the Head is also a non-atomic Expression, in general,\ - no Attribute is assumed. In particular, it is what happens when the head of the expression \ - has the form + no Attribute is assumed. In particular, it is what happens when the head \ + of the expression has the form: ``Function[$body$]`` - or + or: ``Function[$vars$, $body$]`` >> h := Function[{x}, Hold[1+x]] @@ -81,11 +82,11 @@ class Function(PostfixOperator): the evaluation of $1+1$. To avoid that evaluation, of its arguments, the Head \ should have the attribute 'HoldAll'. This behavior can be obtained by using the \ three arguments form version of this expression: - + >> h:= Function[{x}, Hold[1+x], HoldAll] >> h[1+1] = Hold[1 + (1 + 1)] - + In this case, the attribute 'HoldAll' is assumed, \ preventing the evaluation of the argument $1+1$ before passing it \ to the function body. @@ -103,13 +104,13 @@ class Function(PostfixOperator): } summary_text = "define an anonymous (pure) function" - def apply_slots(self, body, args, evaluation): + def eval_slots(self, body, args, evaluation: Evaluation): "Function[body_][args___]" args = list(chain([Expression(SymbolFunction, body)], args.get_sequence())) return body.replace_slots(args, evaluation) - def apply_named(self, vars, body, args, evaluation): + def eval_named(self, vars, body, args, evaluation: Evaluation): "Function[vars_, body_][args___]" if vars.has_form("List", None): @@ -138,7 +139,7 @@ def apply_named(self, vars, body, args, evaluation): return # Not sure if DRY is possible here... - def apply_named_attr(self, vars, body, attr, args, evaluation): + def eval_named_attr(self, vars, body, attr, args, evaluation: Evaluation): "Function[vars_, body_, attr_][args___]" if vars.has_form("List", None): vars = vars.elements @@ -159,12 +160,14 @@ def apply_named_attr(self, vars, body, attr, args, evaluation): class Slot(Builtin): """
-
'#$n$' -
represents the $n$th argument to a pure function. -
'#' -
is short-hand for '#1'. -
'#0' -
represents the pure function itself. +
'#$n$' +
represents the $n$th argument to a pure function. + +
'#' +
is short-hand for '#1'. + +
'#0' +
represents the pure function itself.
X> # @@ -199,10 +202,11 @@ class Slot(Builtin): class SlotSequence(Builtin): """
-
'##' -
is the sequence of arguments supplied to a pure function. -
'##$n$' -
starts with the $n$th argument. +
'##' +
is the sequence of arguments supplied to a pure function. + +
'##$n$' +
starts with the $n$th argument.
>> Plus[##]& [1, 2, 3] diff --git a/mathics/builtin/functional/apply_fns_to_lists.py b/mathics/builtin/functional/apply_fns_to_lists.py index 9bbcf9c3d..7e581c140 100644 --- a/mathics/builtin/functional/apply_fns_to_lists.py +++ b/mathics/builtin/functional/apply_fns_to_lists.py @@ -2,9 +2,11 @@ """ Applying Functions to Lists -Many computations can be conveniently specified in terms of applying functions in parallel to many elements in a list. +Many computations can be conveniently specified in terms of applying functions \ +in parallel to many elements in a list. -Many mathematical functions are automatically taken to be "listable", so that they are always applied to every element in a list. +Many mathematical functions are automatically taken to be "listable", so that \ +they are always applied to every element in a list. """ # This tells documentation how to sort this module @@ -17,6 +19,7 @@ from mathics.builtin.lists import List from mathics.core.atoms import Integer from mathics.core.convert.expression import to_mathics_list +from mathics.core.evaluation import Evaluation from mathics.core.exceptions import ( InvalidLevelspecError, MessageException, @@ -25,9 +28,7 @@ from mathics.core.expression import Expression from mathics.core.list import ListExpression from mathics.core.symbols import Atom, Symbol, SymbolNull, SymbolTrue -from mathics.core.systemsymbols import SymbolRule - -SymbolMapThread = Symbol("MapThread") +from mathics.core.systemsymbols import SymbolMapThread, SymbolRule class Apply(BinaryOperator): @@ -80,12 +81,12 @@ class Apply(BinaryOperator): "Heads": "False", } - def apply_invalidlevel(self, f, expr, ls, evaluation, options={}): + def eval_invalidlevel(self, f, expr, ls, evaluation, options={}): "Apply[f_, expr_, ls_, OptionsPattern[Apply]]" evaluation.message("Apply", "level", ls) - def apply(self, f, expr, ls, evaluation, options={}): + def eval(self, f, expr, ls, evaluation, options={}): """Apply[f_, expr_, Optional[Pattern[ls, _?LevelQ], {0}], OptionsPattern[Apply]]""" @@ -144,12 +145,12 @@ class Map(BinaryOperator): "Heads": "False", } - def apply_invalidlevel(self, f, expr, ls, evaluation, options={}): + def eval_invalidlevel(self, f, expr, ls, evaluation, options={}): "Map[f_, expr_, ls_, OptionsPattern[Map]]" evaluation.message("Map", "level", ls) - def apply_level(self, f, expr, ls, evaluation, options={}): + def eval_level(self, f, expr, ls, evaluation, options={}): """Map[f_, expr_, Optional[Pattern[ls, _?LevelQ], {1}], OptionsPattern[Map]]""" @@ -211,7 +212,7 @@ class MapAt(Builtin): "MapAt[f_, pos_][expr_]": "MapAt[f, expr, pos]", } - def apply(self, f, expr, args, evaluation, options={}): + def eval(self, f, expr, args, evaluation, options={}): "MapAt[f_, expr_, args_]" m = len(expr.elements) @@ -294,12 +295,12 @@ class MapIndexed(Builtin): "Heads": "False", } - def apply_invalidlevel(self, f, expr, ls, evaluation, options={}): + def eval_invalidlevel(self, f, expr, ls, evaluation, options={}): "MapIndexed[f_, expr_, ls_, OptionsPattern[MapIndexed]]" evaluation.message("MapIndexed", "level", ls) - def apply_level(self, f, expr, ls, evaluation, options={}): + def eval_level(self, f, expr, ls, evaluation, options={}): """MapIndexed[f_, expr_, Optional[Pattern[ls, _?LevelQ], {1}], OptionsPattern[MapIndexed]]""" @@ -372,12 +373,12 @@ class MapThread(Builtin): "list": "List expected at position `2` in `1`.", } - def apply(self, f, expr, evaluation): + def eval(self, f, expr, evaluation): "MapThread[f_, expr_]" - return self.apply_n(f, expr, None, evaluation) + return self.eval_n(f, expr, None, evaluation) - def apply_n(self, f, expr, n, evaluation): + def eval_n(self, f, expr, n, evaluation): "MapThread[f_, expr_, n_]" if n is None: @@ -469,12 +470,12 @@ class Scan(Builtin): "Scan[f_][expr_]": "Scan[f, expr]", } - def apply_invalidlevel(self, f, expr, ls, evaluation, options={}): + def eval_invalidlevel(self, f, expr, ls, evaluation, options={}): "Scan[f_, expr_, ls_, OptionsPattern[Map]]" return evaluation.message("Map", "level", ls) - def apply_level(self, f, expr, ls, evaluation, options={}): + def eval_level(self, f, expr, ls, evaluation, options={}): """Scan[f_, expr_, Optional[Pattern[ls, _?LevelQ], {1}], OptionsPattern[Map]]""" @@ -526,7 +527,7 @@ class Thread(Builtin): summary_text = '"thread" a function across lists that appear in its arguments' - def apply(self, f, args, h, evaluation): + def eval(self, f, args, h, evaluation: Evaluation): "Thread[f_[args___], h_]" args = args.get_sequence() diff --git a/mathics/builtin/functional/functional_iteration.py b/mathics/builtin/functional/functional_iteration.py index ea3893676..db123a2c0 100644 --- a/mathics/builtin/functional/functional_iteration.py +++ b/mathics/builtin/functional/functional_iteration.py @@ -8,6 +8,7 @@ from mathics.builtin.base import Builtin from mathics.core.atoms import Integer1 from mathics.core.convert.python import from_python +from mathics.core.evaluation import Evaluation from mathics.core.expression import Expression from mathics.core.symbols import Symbol, SymbolTrue from mathics.core.systemsymbols import SymbolDirectedInfinity @@ -48,7 +49,7 @@ class FixedPoint(Builtin): summary_text = "nest until a fixed point is reached returning the last expression" - def apply(self, f, expr, n, evaluation, options): + def eval(self, f, expr, n, evaluation: Evaluation, options: dict): "FixedPoint[f_, expr_, n_:DirectedInfinity[1], OptionsPattern[FixedPoint]]" if n == Expression(SymbolDirectedInfinity, Integer1): count = None @@ -127,7 +128,7 @@ class FixedPointList(Builtin): summary_text = "nest until a fixed point is reached return a list " - def apply(self, f, expr, n, evaluation): + def eval(self, f, expr, n, evaluation: Evaluation): "FixedPointList[f_, expr_, n_:DirectedInfinity[1]]" if n == Expression(SymbolDirectedInfinity, Integer1): @@ -218,7 +219,7 @@ class Nest(Builtin): summary_text = "give the result of nesting a function" - def apply(self, f, expr, n, evaluation): + def eval(self, f, expr, n, evaluation): "Nest[f_, expr_, n_Integer]" n = n.get_int_value() @@ -234,7 +235,8 @@ class NestList(Builtin): """
'NestList[$f$, $expr$, $n$]' -
starting with $expr$, iteratively applies $f$ $n$ times and returns a list of all intermediate results. +
starting with $expr$, iteratively applies $f$ $n$ times and \ + returns a list of all intermediate results.
>> NestList[f, x, 3] @@ -252,7 +254,7 @@ class NestList(Builtin): summary_text = "successively nest a function" - def apply(self, f, expr, n, evaluation): + def eval(self, f, expr, n, evaluation): "NestList[f_, expr_, n_Integer]" n = n.get_int_value() @@ -273,7 +275,8 @@ class NestWhile(Builtin): """
'NestWhile[$f$, $expr$, $test$]' -
applies a function $f$ repeatedly on an expression $expr$, until applying $test$ on the result no longer yields 'True'. +
applies a function $f$ repeatedly on an expression $expr$, until \ + applying $test$ on the result no longer yields 'True'.
'NestWhile[$f$, $expr$, $test$, $m$]'
supplies the last $m$ results to $test$ (default value: 1). @@ -310,7 +313,7 @@ class NestWhile(Builtin): "NestWhile[f_, expr_, test_]": "NestWhile[f, expr, test, 1]", } - def apply(self, f, expr, test, m, evaluation): + def eval(self, f, expr, test, m, evaluation: Evaluation): "NestWhile[f_, expr_, test_, Pattern[m,_Integer|All]]" results = [expr] diff --git a/mathics/builtin/image/basic.py b/mathics/builtin/image/basic.py index 207ee9099..cd3af05e1 100644 --- a/mathics/builtin/image/basic.py +++ b/mathics/builtin/image/basic.py @@ -244,7 +244,7 @@ class Threshold(Builtin): "skimage": "Please install scikit-image to use Method -> Cluster.", } - def eval(self, image, evaluation: Evaluation, options): + def eval(self, image, evaluation: Evaluation, options: dict): "Threshold[image_Image, OptionsPattern[Threshold]]" pixels = image.grayscale().pixels diff --git a/mathics/builtin/makeboxes.py b/mathics/builtin/makeboxes.py index 95359ec83..20b2c4336 100644 --- a/mathics/builtin/makeboxes.py +++ b/mathics/builtin/makeboxes.py @@ -13,6 +13,7 @@ from mathics.core.attributes import A_HOLD_ALL_COMPLETE, A_READ_PROTECTED from mathics.core.convert.op import operator_to_ascii, operator_to_unicode from mathics.core.element import BaseElement, BoxElementMixin +from mathics.core.evaluation import Evaluation from mathics.core.expression import Expression from mathics.core.list import ListExpression from mathics.core.number import dps @@ -120,7 +121,7 @@ def real_to_s_exp(expr, n): return s, exp, nonnegative -def number_form(expr, n, f, evaluation, options): +def number_form(expr, n, f, evaluation: Evaluation, options: dict): """ Converts a Real or Integer instance to Boxes. diff --git a/mathics/builtin/numbers/algebra.py b/mathics/builtin/numbers/algebra.py index c7067396b..481c07efe 100644 --- a/mathics/builtin/numbers/algebra.py +++ b/mathics/builtin/numbers/algebra.py @@ -811,11 +811,14 @@ def split_coeff_pow(term) -> Tuple[Optional[list], Optional[list]]: class CoefficientArrays(_CoefficientHandler): """ - :WMA link:https://reference.wolfram.com/language/ref/CoefficientArrays.html + + :WMA link: + https://reference.wolfram.com/language/ref/CoefficientArrays.html
'CoefficientArrays[$polys$, $vars$]' -
returns a list of arrays of coefficients of the variables $vars$ in the polynomial $poly$. +
returns a list of arrays of coefficients of the variables $vars$ \ + in the polynomial $poly$.
>> CoefficientArrays[1 + x^3, x] @@ -841,7 +844,7 @@ class CoefficientArrays(_CoefficientHandler): "array of coefficients associated with a polynomial in many variables" ) - def eval_list(self, polys, varlist, evaluation, options): + def eval_list(self, polys, varlist, evaluation: Evaluation, options: dict): "%(name)s[polys_, varlist_, OptionsPattern[]]" from mathics.algorithm.parts import walk_parts @@ -1130,7 +1133,7 @@ class _Expand(Builtin): "opttf": "Value of option `1` -> `2` should be True or False.", } - def convert_options(self, options, evaluation): + def convert_options(self, options: dict, evaluation: Evaluation): modulus = options["System`Modulus"] py_modulus = modulus.get_int_value() if py_modulus is None: @@ -1153,7 +1156,9 @@ def convert_options(self, options, evaluation): class Expand(_Expand): """ - :WMA link:https://reference.wolfram.com/language/ref/Expand.html + + :WMA link: + https://reference.wolfram.com/language/ref/Expand.html
'Expand[$expr$]' @@ -1221,7 +1226,7 @@ class Expand(_Expand): summary_text = "expand out products and powers" - def eval_patt(self, expr, target, evaluation, options): + def eval_patt(self, expr, target, evaluation: Evaluation, options: dict): "Expand[expr_, target_, OptionsPattern[Expand]]" if target.get_head_name() in ("System`Rule", "System`DelayedRule"): @@ -1238,7 +1243,7 @@ def eval_patt(self, expr, target, evaluation, options): kwargs["evaluation"] = evaluation return expand(expr, True, False, **kwargs) - def eval(self, expr, evaluation, options): + def eval(self, expr, evaluation: Evaluation, options: dict): "Expand[expr_, OptionsPattern[Expand]]" kwargs = self.convert_options(options, evaluation) @@ -1285,7 +1290,7 @@ class ExpandAll(_Expand): summary_text = "expand products and powers, including negative integer powers" - def eval_patt(self, expr, target, evaluation, options): + def eval_patt(self, expr, target, evaluation: Evaluation, options: dict): "ExpandAll[expr_, target_, OptionsPattern[Expand]]" if target.get_head_name() in ("System`Rule", "System`DelayedRule"): optname = target.elements[0].get_name() @@ -1301,7 +1306,7 @@ def eval_patt(self, expr, target, evaluation, options): kwargs["evaluation"] = evaluation return expand(expr, numer=True, denom=True, deep=True, **kwargs) - def eval(self, expr, evaluation, options): + def eval(self, expr, evaluation: Evaluation, options: dict): "ExpandAll[expr_, OptionsPattern[ExpandAll]]" kwargs = self.convert_options(options, evaluation) @@ -1335,7 +1340,7 @@ class ExpandDenominator(_Expand): summary_text = "expand just the denominator of a rational expression" - def eval(self, expr, evaluation, options): + def eval(self, expr, evaluation: Evaluation, options: dict): "ExpandDenominator[expr_, OptionsPattern[ExpandDenominator]]" kwargs = self.convert_options(options, evaluation) diff --git a/mathics/builtin/numbers/calculus.py b/mathics/builtin/numbers/calculus.py index b65dee73d..34e90331b 100644 --- a/mathics/builtin/numbers/calculus.py +++ b/mathics/builtin/numbers/calculus.py @@ -18,8 +18,8 @@ from mathics.algorithm.integrators import ( _fubini, _internal_adaptative_simpsons_rule, - apply_D_to_Integral, decompose_domain, + eval_D_to_Integral, ) from mathics.algorithm.series import ( build_series, @@ -554,7 +554,7 @@ class DiscreteLimit(Builtin): } summary_text = "limits of sequences including recurrence and number theory" - def eval(self, f, n, n0, evaluation, options={}): + def eval(self, f, n, n0, evaluation: Evaluation, options: dict = {}): "DiscreteLimit[f_, n_->n0_, OptionsPattern[DiscreteLimit]]" f = f.to_sympy(convert_all_global_functions=True) @@ -612,7 +612,7 @@ class _BaseFinder(Builtin): "Jacobian": "Automatic", } - def eval(self, f, x, x0, evaluation, options): + def eval(self, f, x, x0, evaluation: Evaluation, options: dict): "%(name)s[f_, {x_, x0_}, OptionsPattern[]]" # This is needed to get the right messages options["_isfindmaximum"] = self.__class__ is FindMaximum @@ -694,7 +694,7 @@ def diff(evaluation): else: return ListExpression(Expression(SymbolRule, x, x0)) - def eval_with_x_tuple(self, f, xtuple, evaluation, options): + def eval_with_x_tuple(self, f, xtuple, evaluation: Evaluation, options: dict): "%(name)s[f_, xtuple_, OptionsPattern[]]" f_val = f.evaluate(evaluation) @@ -1071,7 +1071,7 @@ def from_sympy(self, sympy_name, elements): new_elements = [elements[0]] + args return Expression(Symbol(self.get_name()), *new_elements) - def eval(self, f, xs, evaluation, options): + def eval(self, f, xs, evaluation: Evaluation, options: dict): "Integrate[f_, xs__, OptionsPattern[]]" f_sympy = f.to_sympy() if f_sympy.is_infinite: @@ -1199,9 +1199,9 @@ def eval(self, f, xs, evaluation, options): evaluation.definitions.set_ownvalue("System`$Assumptions", old_assumptions) return result - def eval_D(self, func, domain, var, evaluation: Evaluation, options): + def eval_D(self, func, domain, var, evaluation: Evaluation, options: dict): """D[%(name)s[func_, domain__, OptionsPattern[%(name)s]], var_Symbol]""" - return apply_D_to_Integral( + return eval_D_to_Integral( func, domain, var, evaluation, options, SymbolIntegrate ) @@ -1388,7 +1388,9 @@ class NIntegrate(Builtin): } ) - def eval_with_func_domain(self, func, domain, evaluation, options): + def eval_with_func_domain( + self, func, domain, evaluation: Evaluation, options: dict + ): "%(name)s[func_, domain__, OptionsPattern[%(name)s]]" if func.is_numeric() and func.is_zero: return Integer0 @@ -1557,9 +1559,9 @@ def func2_(*u): # be implemented... return from_python(result) - def eval_D(self, func, domain, var, evaluation, options): + def eval_D(self, func, domain, var, evaluation: Evaluation, options: dict): """D[%(name)s[func_, domain__, OptionsPattern[%(name)s]], var_Symbol]""" - return apply_D_to_Integral( + return eval_D_to_Integral( func, domain, var, evaluation, options, SymbolNIntegrate ) diff --git a/mathics/builtin/numbers/diffeqns.py b/mathics/builtin/numbers/diffeqns.py index 86482f863..0548416a5 100644 --- a/mathics/builtin/numbers/diffeqns.py +++ b/mathics/builtin/numbers/diffeqns.py @@ -112,7 +112,7 @@ class DSolve(Builtin): } summary_text = "Differential equation analytical solver." - def apply(self, eqn, y, x, evaluation: Evaluation): + def eval(self, eqn, y, x, evaluation: Evaluation): "DSolve[eqn_, y_, x_]" if eqn.has_form("List", None): diff --git a/mathics/builtin/string/operations.py b/mathics/builtin/string/operations.py index 85d7d751f..00b45b732 100644 --- a/mathics/builtin/string/operations.py +++ b/mathics/builtin/string/operations.py @@ -24,6 +24,7 @@ A_READ_PROTECTED, ) from mathics.core.convert.python import from_python +from mathics.core.evaluation import Evaluation from mathics.core.expression import Expression, string_list from mathics.core.list import ListExpression from mathics.core.symbols import Symbol, SymbolFalse, SymbolList, SymbolTrue @@ -486,7 +487,7 @@ class StringPosition(Builtin): summary_text = "range of positions where substrings match a pattern" - def eval(self, string, patt, evaluation, options): + def eval(self, string, patt, evaluation: Evaluation, options: dict): "StringPosition[string_, patt_, OptionsPattern[StringPosition]]" return self.eval_n( string, @@ -496,7 +497,7 @@ def eval(self, string, patt, evaluation, options): options, ) - def eval_n(self, string, patt, n, evaluation, options): + def eval_n(self, string, patt, n, evaluation: Evaluation, options: dict): "StringPosition[string_, patt_, n:(_Integer|DirectedInfinity[1]), OptionsPattern[StringPosition]]" expr = Expression(SymbolStringPosition, string, patt, n) @@ -683,7 +684,7 @@ def cases(): return Expression(SymbolStringJoin, *list(cases())) - def eval(self, string, rule, n, evaluation, options): + def eval(self, string, rule, n, evaluation: Evaluation, options: dict): "%(name)s[string_, rule_, OptionsPattern[%(name)s], n_:System`Private`Null]" # this pattern is a slight hack to get around missing Shortest/Longest. return self._apply(string, rule, n, evaluation, options, False) @@ -912,7 +913,7 @@ class StringSplit(Builtin): summary_text = "split strings at whitespace, or at a pattern" - def eval(self, string, patt, evaluation, options): + def eval(self, string, patt, evaluation: Evaluation, options: dict): "StringSplit[string_, patt_, OptionsPattern[%(name)s]]" if string.get_head_name() == "System`List": diff --git a/mathics/builtin/string/patterns.py b/mathics/builtin/string/patterns.py index 99dc2877d..12f8efbdd 100644 --- a/mathics/builtin/string/patterns.py +++ b/mathics/builtin/string/patterns.py @@ -234,7 +234,7 @@ def cases(): return ListExpression(*list(cases())) - def eval(self, string, rule, n, evaluation: Evaluation, options): + def eval(self, string, rule, n, evaluation: Evaluation, options: dict): "%(name)s[string_, rule_, OptionsPattern[%(name)s], n_:System`Private`Null]" # this pattern is a slight hack to get around missing Shortest/Longest. return self._apply(string, rule, n, evaluation, options, True) @@ -377,7 +377,7 @@ class StringFreeQ(Builtin): summary_text = "test whether a string is free of substrings matching a pattern" - def eval(self, string, patt, evaluation: Evaluation, options): + def eval(self, string, patt, evaluation: Evaluation, options: dict): "StringFreeQ[string_, patt_, OptionsPattern[%(name)s]]" return _pattern_search( self.__class__.__name__, string, patt, evaluation, options, False @@ -462,7 +462,7 @@ class StringMatchQ(Builtin): } summary_text = "test whether a string matches a pattern" - def eval(self, string, patt, evaluation: Evaluation, options): + def eval(self, string, patt, evaluation: Evaluation, options: dict): "StringMatchQ[string_, patt_, OptionsPattern[%(name)s]]" py_string = string.get_string_value() if py_string is None: diff --git a/mathics/builtin/trace.py b/mathics/builtin/trace.py index 84a7c161c..3cca7c8c4 100644 --- a/mathics/builtin/trace.py +++ b/mathics/builtin/trace.py @@ -24,7 +24,7 @@ from mathics.core.symbols import SymbolFalse, SymbolNull, SymbolTrue, strip_context -def traced_do_replace(self, expression, vars, options, evaluation: Evaluation): +def traced_do_replace(self, expression, vars, options: dict, evaluation: Evaluation): if options and self.check_options: if not self.check_options(options, evaluation): return None @@ -339,7 +339,7 @@ class TraceEvaluation(Builtin): } summary_text = "trace the succesive evaluations" - def eval(self, expr, evaluation, options): + def eval(self, expr, evaluation: Evaluation, options: dict): "TraceEvaluation[expr_, OptionsPattern[]]" curr_trace_evaluation = evaluation.definitions.trace_evaluation curr_time_by_steps = evaluation.definitions.timing_trace_evaluation diff --git a/mathics/core/element.py b/mathics/core/element.py index b299d4c54..ec569638b 100644 --- a/mathics/core/element.py +++ b/mathics/core/element.py @@ -344,7 +344,7 @@ def get_sequence(self) -> Union[tuple, list]: # Below, we special-case for SymbolSequence. Here is an example to suggest why. # Suppose we have this evaluation method: # - # def apply(x, evaluation): + # def eval(x, evaluation: Evaluation): # """F[x__]""" # args = x.get_sequence() # diff --git a/mathics/core/rules.py b/mathics/core/rules.py index 9fac71636..f593ad4a1 100644 --- a/mathics/core/rules.py +++ b/mathics/core/rules.py @@ -5,6 +5,7 @@ from itertools import chain from mathics.core.element import KeyComparable +from mathics.core.evaluation import Evaluation from mathics.core.expression import Expression from mathics.core.pattern import Pattern, StopGenerator from mathics.core.symbols import strip_context @@ -137,7 +138,7 @@ def __init__(self, pattern, replace, system=False) -> None: super(Rule, self).__init__(pattern, system=system) self.replace = replace - def do_replace(self, expression, vars, options, evaluation): + def do_replace(self, expression, vars, options: dict, evaluation: Evaluation): new = self.replace.replace_vars(vars) new.options = options @@ -209,7 +210,7 @@ def __init__(self, name, pattern, function, check_options, system=False) -> None # If you update this, you must also update traced_do_replace # (that's in the same file TraceBuiltins is) - def do_replace(self, expression, vars, options, evaluation): + def do_replace(self, expression, vars, options: dict, evaluation: Evaluation): if options and self.check_options: if not self.check_options(options, evaluation): return None diff --git a/mathics/core/systemsymbols.py b/mathics/core/systemsymbols.py index 291021fa2..2e46cc6b3 100644 --- a/mathics/core/systemsymbols.py +++ b/mathics/core/systemsymbols.py @@ -126,6 +126,7 @@ SymbolMachinePrecision = Symbol("System`MachinePrecision") SymbolMakeBoxes = Symbol("System`MakeBoxes") SymbolMap = Symbol("System`Map") +SymbolMapThread = Symbol("System`MapThread") SymbolMatchQ = Symbol("System`MatchQ") SymbolMatrixQ = Symbol("System`MatrixQ") SymbolMathMLForm = Symbol("System`MathMLForm") diff --git a/test/builtin/box/test_custom_boxexpression.py b/test/builtin/box/test_custom_boxexpression.py index 0223a19d0..9ac6116fb 100644 --- a/test/builtin/box/test_custom_boxexpression.py +++ b/test/builtin/box/test_custom_boxexpression.py @@ -4,6 +4,7 @@ from mathics.builtin.box.expression import BoxExpression from mathics.builtin.graphics import GRAPHICS_OPTIONS from mathics.core.attributes import A_HOLD_ALL, A_PROTECTED, A_READ_PROTECTED +from mathics.core.evaluation import Evaluation from mathics.core.expression import Expression from mathics.core.symbols import Symbol @@ -41,7 +42,7 @@ class CustomAtom(Predefined): "N[System`CustomAtom]": "37", } - def apply_to_boxes(self, evaluation): + def eval_to_boxes(self, evaluation): "System`MakeBoxes[System`CustomAtom, StandardForm|TraditionalForm|OutputForm|InputForm]" return CustomBoxExpression(evaluation=evaluation) @@ -60,7 +61,7 @@ def init(self, *elems, **options): def to_expression(self): return Expression(SymbolCustomGraphicsBox, *self.elements) - def apply_box(self, expr, evaluation, options): + def eval_box(self, expr, evaluation: Evaluation, options: dict): """System`MakeBoxes[System`Graphics[System`expr_, System`OptionsPattern[System`Graphics]], System`StandardForm|System`TraditionalForm|System`OutputForm]""" instance = CustomGraphicsBox(*(expr.elements), evaluation=evaluation)