-
-
Notifications
You must be signed in to change notification settings - Fork 65
Add Box type annotations to render routines. #1674
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
Conversation
Also: remove "_" from non-private classes. Go over render docstrings.
|
@mmatera: you asked for changes in #1671 to be split out. Here, we just go over type annotations. This aspect was, in fact, a larger problem than just MathML. But it should come first because, in order have a more informed discussion of MathML, we need a better foundation. The changes here seem larger than what's really going on: renaming "self" to "box" and adding specific type definitions. (And in doing so, already I am seeing a type failure.) |
|
I am seing now some type errors in master too, with the latest version of mypy (1.19.1). Some of the errors here should be fixed by adding an assertion / condition to narrow the type of the argument. But I guess that in all the render routines, the type of the argument |
|
BTW, thanks for the work of splitting this in parts. |
|
|
||
|
|
||
| class _GraphicsElementBox(BoxExpression, ABC): | ||
| class GraphicsElementBox(BoxExpression, ABC): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the underscore was to avoid considering this class as a Builtin to be shown in the documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(In WMA this builtin does not exist)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the underscore was to avoid considering this class as a Builtin to be shown in the documentation.
The entire module is marked no-doc. So this should no longer be a reason for having an underscore. In Python, an underscore typically indicates a private class, and this is not private. If it had an underscore previously, that was the wrong way to solve the problem. But at any rate this problem does not exist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(In WMA this builtin does not exist)
I don't understand what this is getting at. We have many classes in Mathics3 and some built-in function classes that do not exist in WMA.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the underscore was to avoid considering this class as a Builtin to be shown in the documentation.
The entire module is marked no-doc. So this should no longer be a reason for having an underscore. In Python, an underscore typically indicates a private class, and this is not private. If it had an underscore previously, that was the wrong way to solve the problem. But at any rate this problem does not exist.
It should not be loaded as a Built-in symbol. Check what happens in the CLI when you entry
?BoxGraphicsElement
The underscore prevents that this class contribute with a definition. But this is a symptom that this module does not belongs to mathics.builtin.box module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what I get in this branch:
In[1]:= ? GraphicsElementBox
Out[1]= box representation for a graphics element
Attributes[GraphicsElementBox] = {Protected, ReadProtected}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should not be loaded as a Built-in symbol. Check what happens in the CLI when you entry
?BoxGraphicsElement
I think you mean ?GraphicsElementBox, right?
The underscore prevents that this class contribute with a definition. But this is a symptom that this module does not belongs here.
If it gets renamed with the word Box first, I don't think that will get added as a definition, right? I think that's how BoxExpression works, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should not be loaded as a Built-in symbol. Check what happens in the CLI when you entry
?BoxGraphicsElementI think you mean
?GraphicsElementBox, right?
yep
The underscore prevents that this class contribute with a definition. But this is a symptom that this module does not belongs here.
If it gets renamed with the word Box first, I don't think that will get added as a definition, right? I think that's how BoxExpression works, right?
We was very clever if we did that...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As it is, it is loaded. But OK, it is not terrible. We can adjust it later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just looked at the code. What is done to define list DOES_NOT_ADD_BUILTIN_DEFINITION = [...] in the module.
See https://github.com/Mathics3/mathics-core/blob/master/mathics/builtin/forms/base.py#L51
And that is far better than overloading the meaning of underscore at the beginning of a list. I'll add this in there now.
Initialize: * BoxExpression.boxes * GraphicsBox.boxwidth * GraphicsBox.boxheight * GrapnicsBox.boxes Make sure to convert sympy.Float to Python float
Ok.
I don't think "all", but just the top-level generic ones. |
0fcab42 to
7325a25
Compare
I mean, all the functions which are registered. |
This is not the situation for RowBox, and several other boxes like that. |
7325a25 to
942752a
Compare
mmatera
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Merge when you feel it is ready.
so ??GraphicsElementBox is not predefined inside a Mathics3 session.
Great! Tomorrow, I'll look over the separation of box attributes, which belong to the box object, from boxing options, which are passed via the After that, we can then start a discussion on the code that needs to compute box information and where and how that should work. |
Uh oh!
There was an error while loading. Please reload this page.