rich icon indicating copy to clipboard operation
rich copied to clipboard

Don't display() spurious newlines in jupyter

Open NickCrews opened this issue 10 months ago • 2 comments

Fixes #3274

I couldn't think of a way to test the "real" behavior that we are looking for, which is "are random newlines appearing in jupyter's output?", so I had to settle for the proxy of "is ipython's display() ever called?".

I materialized the Iterable[Segment]s into a list, IDK if there are some performance concerns with this (we're about to materialize them all to strings anyway???). If so then I could come up with a less-clean way of checking for "did we get passed nothing")

Type of changes

  • [x] Bug fix
  • [ ] New feature
  • [ ] Documentation / docstrings
  • [x] Tests
  • [ ] Other

Checklist

  • [ ] I've run the latest black with default args on new code.
  • [ ] I've updated CHANGELOG.md and CONTRIBUTORS.md where appropriate.
  • [x] I've added tests for new code.
  • [x] I accept that @willmcgugan may be pedantic in the code review.

NickCrews avatar Apr 12 '24 20:04 NickCrews

@huzecong does this look like it solves your issue you described in #3274 ?

@willmcgugan friendly ping here, I realize you must have a lot on your plate, but think this should be a fairly easy review. Thank you!

NickCrews avatar Aug 06 '24 21:08 NickCrews

Hey @NickCrews, thanks for putting up this PR! This looks good to me and should solve the issue in #3274.

I materialized the Iterable[Segment]s into a list, IDK if there are some performance concerns with this (we're about to materialize them all to strings anyway???).

This seems reasonable to me too, but I'm no expert in this project and will leave it to the maintainers. One thing I'd like to mention is that our in-house patch only checked if not text, and that was sufficient for us. So if you're concerned about the list conversion, you might want to consider just dropping the check on segments.

huzecong avatar Aug 06 '24 21:08 huzecong