-
Notifications
You must be signed in to change notification settings - Fork 5
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
Importing friendly into IPython appears to break %pprint functionality #14
Comments
I've never used pprint with IPython. I will need to investigate. |
I believe that I have found the cause of the error and could create a workaround. With Friendly, I use https://github.com/willmcgugan/rich to do some formatting (including adding colours) and when I install Rich, it seems to override some ipython defaults. (I don't know how yet). As a work around, I could create a new version of friendly that would never use Rich. This would preclude having coloured tracebacks from friendly, but it would still work. This is what it would look like: I'd need to change the way it is invoked; likely something like:
If this would be useful to you, I could have this done within an hour (easily!). |
Thanks for the quick reply! As far as using %pprint in IPython, take something like this, for example: |
I've uploaded a new version to PyPI: friendly version 0.4.19. To use it so that you can use IPython's %pprint, import the following: from friendly.ipython_plain import * This will not use Rich (and no colours). I'm going to ask a question on Rich's forum, referring to this issue. Perhaps there might be a way to disable the pprint done by Rich, to achieve something similar to turning off IPython's own pprint. |
See Textualize/rich#1603, and feel free to add any useful information! |
Toggling %pprint now seems to work as expected. Detailed error messages from friendly also appear to be working for me. Thanks for the really quick response and (partial) resolution! Hopefully, a solution for restoring color to the messages via rich is possible. Feel free to ping me if you want me to look into anything further. I'll check back later tonight, or tomorrow. |
Keeping this issue open until I can figure out if it is possible to use Rich and toggle pprint (or equivalent). |
Would it be worthwhile, for me, to test anything for you with the new version? Happy to help out. Haven't seen any response from the rich project on your bug report. |
I have not changed anything since I uploaded to PyPI the last version (which you already tried, I believe). I've tried to dig in the code for Rich to see if I could fint a way to fix this, but without success so far. I might give it another try later this week. |
OK. Thanks. I may poke around at rich. Not a terribly high priority for myself either. |
For some reason, this bug doesn't appear as an open issue on the rich repo. |
I put this in the "Discussion" area of the project, as it did not seem to be suitable to call it a bug as such. |
OK. In my opinion, is should be a bug, But, thanks for engaging them. I think, if they are indeed, overwriting pprint, that is unexpected behavior. We'll see what they say, if anything. |
Filed as an explicit issue: Textualize/rich#1611 |
I've uploaded a new version of
|
Hmm. I'm not sure that 4.20 is working as expected. I am using |
@kevinbowen777 My apologies: I messed up by putting the redefinition of I'm attempting to correct this now. I will need to do another correction later, to prevent changing the formatter via |
New version uploaded. If |
Just installed 4.21, and it is working as expected with both |
@kevinbowen777 New version (0.4.22) which no longer require the use of Entering |
What I am seeing when re-enabling %pprint, is that I need to quit and then re-start ipython before the syntax highlighting is restored. I am using an xfce4-terminal with a black background. |
Ah. I see what you are saying. I had missed your point re: using dark() and light(). Thanks for spelling it out for me. ;-) |
@kevinbowen777 I'm going to leave this issue open until I add some relevant information in the documentation. Feel free to comment further, especially if you find some bugs! ;-) |
With the newest version of Rich, After uploading a new version of friendly (0.4.25) to Pypi, this issue can now be closed. |
I've upgraded both friendly and rich, now when I start IPython, I am getting the following:
I can confirm that I do not need to re-rerun either dark() or light() after running %pprint again. Let me know if you need additional info from me. Thanks. |
On Mon, Nov 8, 2021 at 12:05 AM Kevin Bowen ***@***.***> wrote:
I've upgraded both friendly and rich, now when I start IPython, I am
getting the following:
Traceback (most recent call last):
Code block [1], line 1, in <module>
from friendly.ipython import *
AttributeError: '_State' object has no attribute 'exception_before_import'
I can confirm that I do not need to re-rerun either dark() or light()
after running %pprint again. Let me know if you need additional info from
me. Thanks.
When you start friendly, do you get the following:
friendly-traceback: 0.4.59
friendly: 0.4.25
The attribute 'exception_before_import' is a recent addition to
friendly-traceback (which should have been updated when you updated
friendly).
… —
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#14 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAEZXQWHTBN2YNPRPJPJLTDUK5EAZANCNFSM5GD7QBWA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
Hrm. No, I was getting I ran another IIRC, upgrading friendly also pulled in the upgrade for friendly-traceback; but, that doesn't seem to be the case, for me, this time. |
Weird ... it did work for me in a new environment, even though the specific requirement was not updated everywhere. I've updated setup.cfg and uploaded a new version for friendly (0.4.26) which should work properly. |
Just tried it out in a new venv and it works cleanly now, for me. An upgrade of friendly now pulls in the new friendly-traceback version. Let me know if you want me to check anything else out. Thanks for your work. Cheers! |
Hello,
I am running into an issue when working within IPython and need to toggle
the pprint functionality either 'off' or 'on'.
Here is the error message I receive when trying to run the "%pprint" magic
command from within IPython:
IPython config information for importing friendly:
Should I be placing a set_formatter() call here? I tried set_formatter('rich') or 'jupyter' with no success.
I have also tried commenting the above out of my ipython_config, starting
IPython, and then manually importing with the same results. Additionally,
I tried to limit my import of friendly from a * import to only using:
from friendly.ipython import what, where, why
again with the same error message.
Here is my system information:
I have confirmed that this also happens with IPython 7.20 & Python 3.8.10.
My distros are Mint 20.2 & Manjaro 21.1.5
Please let me know if you need any additional information, from me. Or, let
me know if I am doing something wrong, myself, to cause this problem.
Thanks for your work on this module. I appreciate it.
The text was updated successfully, but these errors were encountered: