Skip to content

Display message from TryNext error in magic_paste #1741

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

Closed
wants to merge 1 commit into from

Conversation

takluyver
Copy link
Member

If you do %paste on a system without Tkinter installed, this makes sure you get the more informative error message.

Closes gh-1736

if exc.args or exc.kwargs:
args = exc.args
kw = exc.kwargs
# if no function will accept it, raise TryNext up to the caller
raise TryNext(*args, **kw)
raise lastexc
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the behavior slightly, as before we'd guarantee the exception's args and kw attributes would be as passed to __call__, but now we only take the results from the raised exception (which likely have args = (), and kw = {}).

Is the ability of the exception to change the calling arguments ever actually used? I can't seem to find an instance of this in the IPython source.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At a quick look, here and in magic_paste are the only code where TryNext is caught and captured. I think the ability to change args/kwargs is intended to act within CommandChainDispatcher, not to propagate to calling code, and this doesn't affect that. But no, I don't think it's actually used at all. It's hard to see a use case that maintains weak coupling. Maybe it should just be ditched...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should consider removing the args/kw capability in TryNext. It's been present, in its current form, since the dawn of time (or at least since 2f09c2a which is the start of the history in git).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, let's take this to the mailing list. I'll make a post about it.

@bfroehle
Copy link
Contributor

Certainly the PR works:

In [1]: import sys; sys.modules['Tkinter'] = None

In [2]: paste
ERROR: Getting text from the clipboard on this platform requires Tkinter.

@Carreau
Copy link
Member

Carreau commented Jun 2, 2012

@takluyver,
nobody seem to have complained, do you want to fix the conflict and merge ?

@bfroehle
Copy link
Contributor

bfroehle commented Jun 3, 2012

Started a branch for this: https://github.com/bfroehle/ipython/compare/_1736_try_next

Haven't tested it, but can open a pull request later this evening.

@takluyver
Copy link
Member Author

@bfroehle : At a glance, that branch looks good, so go for a pull request. I'm with my family for a long weekend, so I'm checking email, but I don't have much time to actually code.

@takluyver
Copy link
Member Author

Superseded by #1850 - closing.

@takluyver takluyver closed this Jun 7, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

no good error message on missing tkinter and %paste
3 participants