Skip to content
Merged
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
18 changes: 12 additions & 6 deletions mathics/core/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,23 @@ def __init__(
"System`",
"Global`",
)

# Importing "mathics.format" populates the Symbol of the
# PrintForms and OutputForms sets.
#
# If "importlib" is used instead of "import", then we get:
# TypeError: boxes_to_text() takes 1 positional argument but
# 2 were given
# Rocky: this smells of something not quite right in terms of
# modularity.

import mathics.format # noqa
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, it is a side effect of lack of modularity. The problem is that mathics.format requires mathics.builtin.box, and it depends on mathics.builtin.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. In which line this happens?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not an error, it is just that the output won't get tagged (which is the point of the change) since result.form will be None because nothing in output_forms:

+                if head in output_forms:
+                    form = self.definitions.shorten_name(head.name)


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not directly related to PrintForm. This module contains the routines that render strings from BoxExpressions.

Copy link
Member Author

@rocky rocky Oct 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By PrintForms (note final "s"), I mean the module variable PrintForms (set in self.print_forms) or exposed variable $PrintForms. If you try the branch in mathicsscript that has this name add-to-form and run it against master you will find that the set variables in this module PrintForms and OutputForms are the empty set.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was talking about that variable, sorry.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PrintForms must be populated when mathics.builtin.forms load each subclass of FormsBaseClass, but it should import mathics.core.definitions to do that. I can investigate it latter

self.printforms = list(PrintForms)
self.outputforms = list(OutputForms)
self.trace_evaluation = False
self.timing_trace_evaluation = False

# This loads all the formatting functions.
# It needs to be early because it can be used in
# messages during the builtins loading.
# Rocky: this smells of something not quite right in terms of modularity.
import mathics.format

if add_builtin:
from mathics.builtin import modules, contribute
from mathics.settings import ROOT_DIR
Expand Down