Skip to content

Commit

Permalink
tweak docstring, more type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
rocky committed Dec 27, 2022
1 parent e3c545c commit 2fde486
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions mathics/eval/makeboxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,36 @@ def _boxed_string(string: str, **options):
return StyleBox(String(string), **options)


def eval_fullform_makeboxes(self, expr, evaluation, f=SymbolStandardForm):
def eval_fullform_makeboxes(
self, expr, evaluation: Evaluation, form=SymbolStandardForm
) -> Expression:
"""
This function takes the definitions provided by the evaluation
object, and produces a boxed form for expr.
Basically: MakeBoxes[expr // FullForm]
"""
# This is going to be reimplemented.
expr = Expression(SymbolFullForm, expr)
return Expression(SymbolMakeBoxes, expr, f).evaluate(evaluation)
return Expression(SymbolMakeBoxes, expr, form).evaluate(evaluation)


def eval_makeboxes(self, expr, evaluation, f=SymbolStandardForm):
def eval_makeboxes(
self, expr, evaluation: Evaluation, form=SymbolStandardForm
) -> Expression:
"""
This function takes the definitions provided by the evaluation
object, and produces a boxed fullform for expr.
Basically: MakeBoxes[expr // form]
"""
# This is going to be reimplemented.
return Expression(SymbolMakeBoxes, expr, f).evaluate(evaluation)
return Expression(SymbolMakeBoxes, expr, form).evaluate(evaluation)


def format_element(
element: BaseElement, evaluation: Evaluation, form: Symbol, **kwargs
) -> BaseElement:
) -> Type[BaseElement]:
"""
Applies formats associated to the expression, and then calls Makeboxes
"""
Expand All @@ -95,14 +103,14 @@ def format_element(

def do_format(
element: BaseElement, evaluation: Evaluation, form: Symbol
) -> BaseElement:
) -> Type[BaseElement]:
do_format_method = element_formatters.get(type(element), do_format_element)
return do_format_method(element, evaluation, form)


def do_format_element(
element: BaseElement, evaluation: Evaluation, form: Symbol
) -> BaseElement:
) -> Type[BaseElement]:
"""
Applies formats associated to the expression and removes
superfluous enclosing formats.
Expand Down Expand Up @@ -220,7 +228,7 @@ def format_expr(expr):

def do_format_rational(
element: BaseElement, evaluation: Evaluation, form: Symbol
) -> BaseElement:
) -> Type[BaseElement]:
if form is SymbolFullForm:
return do_format_expression(
Expression(
Expand All @@ -245,7 +253,7 @@ def do_format_rational(

def do_format_complex(
element: BaseElement, evaluation: Evaluation, form: Symbol
) -> BaseElement:
) -> Type[BaseElement]:
if form is SymbolFullForm:
return do_format_expression(
Expression(
Expand Down Expand Up @@ -273,7 +281,7 @@ def do_format_complex(

def do_format_expression(
element: BaseElement, evaluation: Evaluation, form: Symbol
) -> BaseElement:
) -> Type[BaseElement]:
# # not sure how much useful is this format_cache
# if element._format_cache is None:
# element._format_cache = {}
Expand Down

0 comments on commit 2fde486

Please sign in to comment.