-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Add in ordering='none' capability to srepr printer #18777
Conversation
✅ Hi, I am the SymPy bot (v158). I'm here to help you write a release notes entry. Please read the guide on how to write release notes. Your release notes are in good order. Here is what the release notes will look like:
This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.6. Note: This comment will be updated with the latest check if you edit the pull request. You need to reload the page to see it. Click here to see the pull request description that was parsed.
Update The release notes on the wiki have been updated. |
This looks good. Actually I would rather expect srepr to show the true args ordering by default. As an aside, I wonder why we don't just support |
Looks like tests are failing here. |
sympy/printing/repr.py
Outdated
@@ -48,7 +49,10 @@ def emptyPrinter(self, expr): | |||
return str(expr) | |||
|
|||
def _print_Add(self, expr, order=None): | |||
args = self._as_ordered_terms(expr, order=order) | |||
if self.order == 'none': |
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.
Could we make this order == None
? Do we have precedent for string vs None elsewhere?
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.
There are a few different ordering options that each printer supports (such as 'old'
and 'lex'
) so that keeps in line with that convention. Having order=None
means no ordering was provided rather than the "none" (aka don't reorder terms) ordering we are looking for. The overlap in terminology is confusing I do agree. The other printers use 'none' to denote no reordering of terms. We can revisit that terminology and sync the other printers accordingly but that would be backwards compatibility breaking and require to keep the old string lookup around.
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.
Yeah, 'none' is already a pre-existing thing. It's pretty confusing I agree. IIRC None
means use the default (which I think is 'lex'
) whereas 'none'
means no ordering (all the orderings are strings).
@asmeurer I should've left WIP in the title. I quickly put together this PR when I came across this issue on a project I'm working on. I'll take a look at the tests now. I agree. I think we should allow for the |
Codecov Report
@@ Coverage Diff @@
## master #18777 +/- ##
===========================================
- Coverage 75.66% 75.64% -0.021%
===========================================
Files 647 647
Lines 168420 168433 +13
Branches 39682 39687 +5
===========================================
- Hits 127428 127404 -24
- Misses 35441 35473 +32
- Partials 5551 5556 +5 |
@asmeurer I'm worried about making |
That's fine. My comment wasn't meant to mean that it needs to be done in this PR. |
Brief description of what is fixed or changed
Currently the
LatexPrinter
andStrPrinter
allow for ordering to be turned off (similar toevaluate=False
in sympify. This capability however doesn't exist in theReprPrinter
.StrPrinter(dict(order='none')).doprint(expr)
Now this is equivalent:
ReprPrinter(dict(order='none')).doprint(sympify('x + 3 - 2', evaluate=False)) == 'Add(Symbol('x'), Integer(3), Integer(-2))'
Other comments
Release Notes