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

Fix double printing in the string and latex printers #19614

Merged
merged 2 commits into from Jun 23, 2020

Conversation

eric-wieser
Copy link
Member

References to other Issues or PRs

This is some preliminary cleanup to prepare for gh-19611

Brief description of what is fixed or changed

LatexPrinter now avoids calling self._print(self._print(x)) in all places reached by the test.
This means that subclasses are free to define _print_str to put quotes around the string, without breaking printing of builtin objects.
It also means printing will be marginally faster.

Other comments

Release Notes

  • printing
    • LatexPrinter._print is no longer called on strings which have already been converted to Latex.

`LatexPrinter._print_Pow` dispatches to `_print(expr.base, exp=_print(expr.pow))`.
Calling `_print(exp)` again in other print functions is at best slow and useless, and otherwise wrong.

This manifests in printer subclasses as `_print_str` being called with string that have already been printed once.
@sympy-bot
Copy link

sympy-bot commented Jun 22, 2020

Hi, I am the SymPy bot (v160). 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:

  • printing
    • LatexPrinter._print is no longer called on strings which have already been converted to Latex. (#19614 by @eric-wieser)

This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.7.

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.

<!-- Your title above should be a short description of what
was changed. Do not include the issue number in the title. -->

#### References to other Issues or PRs
<!-- If this pull request fixes an issue, write "Fixes #NNNN" in that exact
format, e.g. "Fixes #1234" (see
https://tinyurl.com/auto-closing for more information). Also, please
write a comment on that issue linking back to this pull request once it is
open. -->
This is some preliminary cleanup to prepare for gh-19611

#### Brief description of what is fixed or changed

`LatexPrinter` now avoids calling `self._print(self._print(x))` in all places reached by the test.
This means that subclasses are free to define `_print_str` to put quotes around the string, without breaking printing of builtin objects.
It also means printing will be marginally faster.

#### Other comments


#### Release Notes

<!-- Write the release notes for this release below. See
https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more information
on how to write release notes. The bot will check your release notes
automatically to see if they are formatted correctly. -->

<!-- BEGIN RELEASE NOTES -->
* printing
  * `LatexPrinter._print` is no longer called on strings which have already been converted to Latex.
<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

This manifests in printer subclasses as `_print_str` being called with string that have already been printed once.
@eric-wieser eric-wieser marked this pull request as ready for review June 22, 2020 14:31
@eric-wieser eric-wieser changed the title Fix latex double printing Fix double printing in the string and latex printers Jun 22, 2020
@codecov
Copy link

codecov bot commented Jun 22, 2020

Codecov Report

Merging #19614 into master will increase coverage by 11.267%.
The diff coverage is 93.181%.

@@              Coverage Diff               @@
##            master    #19614        +/-   ##
==============================================
+ Coverage   64.420%   75.687%   +11.267%     
==============================================
  Files          656       656                
  Lines       170248    170249         +1     
  Branches     40154     40155         +1     
==============================================
+ Hits        109674    128858     +19184     
+ Misses       54537     35760     -18777     
+ Partials      6037      5631       -406     

@oscarbenjamin
Copy link
Contributor

Looks good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants