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

Allow subclasses of sympy objects to override _repr_latex_ #19944

Merged
merged 1 commit into from Aug 11, 2020

Conversation

eric-wieser
Copy link
Member

@eric-wieser eric-wieser commented Aug 10, 2020

The previous behavior was to completely ignore this hook once init_printing had been called, which was surprising to the user.

References to other Issues or PRs

This fixes an issue related to #10062, but only for subclasses of sympy types.

Brief description of what is fixed or changed

init_printing() no longer causes _repr_latex_ methods defined on Printable subclasses to be completely ignored. The rules in IPython for looking up magic methods are currently (ipython/ipython#8938):

  • Walk the mro for explicitly-registered printers
  • Walk the mro for method-registered printers

But would make more sense as:

  • Walk the mro for:
    • explicitly-registered printers
    • method-registered printers

Since this probably won't change any time soon, the workaround is to register printers for Printable via methods not explicit hooks - this allows users to override them if they so wish.

Other comments

Release Notes

  • interactive
    • The _repr_latex_, _repr_svg_, and _repr_png_ methods of subclasses of sympy objects are no longer discarded when init_printing() is called.

@sympy-bot
Copy link

sympy-bot commented Aug 10, 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:

  • interactive
    • The _repr_latex_, _repr_svg_, and _repr_png_ methods of subclasses of sympy objects are no longer discarded when init_printing() is called. (#19944 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.

The previous behavior was to completely ignore this hook once `init_printing` had been called, which was surprising to the user.

<!-- 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 fixes an issue related to #10062, but only for subclasses of sympy types.

#### Brief description of what is fixed or changed
`init_printing()` no longer causes `_repr_latex_` methods defined on `Printable` subclasses to be completely ignored. The rules in IPython for looking up magic methods are currently (https://github.com/ipython/ipython/issues/8938):
* Walk the mro for explicitly-registered printers
* Walk the mro for method-registered printers

But would make more sense as:
* Walk the mro for:
   * explicitly-registered printers
   * method-registered printers

Since this probably won't change any time soon, the workaround is to register printers for `Printable` via methods not explicit hooks - this allows users to override them if they so wish.

#### 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 -->
* interactive
   * The `_repr_latex_`, `_repr_svg_`, and `_repr_png_` methods of subclasses of sympy objects are no longer discarded when `init_printing()` is called.
<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

@eric-wieser eric-wieser changed the title Allow subclasses to override _repr_latex_ Allow subclasses of sympy objects to override _repr_latex_ Aug 10, 2020
@codecov
Copy link

codecov bot commented Aug 10, 2020

Codecov Report

Merging #19944 into master will increase coverage by 0.024%.
The diff coverage is 23.076%.

@@              Coverage Diff              @@
##            master    #19944       +/-   ##
=============================================
+ Coverage   75.778%   75.803%   +0.024%     
=============================================
  Files          668       668               
  Lines       173216    173193       -23     
  Branches     40837     40842        +5     
=============================================
+ Hits        131261    131286       +25     
+ Misses       36221     36173       -48     
  Partials      5734      5734               

@oscarbenjamin
Copy link
Contributor

Looks good to me

@eric-wieser
Copy link
Member Author

Might come back and add an xref to the upstream ipython issue tomorrow.

@eric-wieser eric-wieser force-pushed the allow-custom-printers branch 2 times, most recently from 3043b74 to 1ea5f30 Compare August 11, 2020 12:27
The previous behavior was to completely ignore this hook once `init_printing` had been called, which was surprising to the user.
@eric-wieser
Copy link
Member Author

Changed the implementation to be a bit more verbose but hopefully easier to understand - probably needs re-reviewing

@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