Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Last of the apply->eval conversions #748

Merged
merged 1 commit into from
Jan 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mathics/algorithm/integrators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions mathics/builtin/atomic/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion mathics/builtin/atomic/symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mathics/builtin/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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[]]'''
...
```
Expand Down
16 changes: 8 additions & 8 deletions mathics/builtin/box/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -322,15 +322,15 @@ 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),
to_boxes(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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions mathics/builtin/colors/color_directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
13 changes: 10 additions & 3 deletions mathics/builtin/colors/color_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion mathics/builtin/compress.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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 + '"'
Expand Down
8 changes: 6 additions & 2 deletions mathics/builtin/datentime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 8 additions & 5 deletions mathics/builtin/distance/clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions mathics/builtin/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
Loading