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 TryNext to have an error message without it affecting the command chain #1703

Merged
merged 1 commit into from
May 9, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion IPython/core/error.py
Expand Up @@ -38,11 +38,18 @@ class TryNext(IPythonCoreError):
should be used to handle the operation. If you pass arguments to the
constructor those arguments will be used by the next hook instead of the
original ones.

A _msg argument will not be passed on, so it can be used as a displayable
error message.
"""

def __init__(self, *args, **kwargs):
def __init__(self, _msg="", *args, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

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

Why is this _msg instead of msg?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because you can give it keyword arguments to pass to the next function in the chain, and it's possible, if unlikely, that you might use msg as a keyword argument. So it deliberately looks special because it's handled differently to other keyword arguments.

self.args = args
self.kwargs = kwargs
self.msg = _msg

def __str__(self):
return str(self.msg)

class UsageError(IPythonCoreError):
"""Error in magic function arguments, etc.
Expand Down
4 changes: 2 additions & 2 deletions IPython/lib/clipboard.py
Expand Up @@ -17,7 +17,7 @@ def win32_clipboard_get():
except ImportError:
message = ("Getting text from the clipboard requires the pywin32 "
"extensions: http://sourceforge.net/projects/pywin32/")
raise TryNext(message)
raise TryNext(_msg=message)
win32clipboard.OpenClipboard()
text = win32clipboard.GetClipboardData(win32clipboard.CF_TEXT)
# FIXME: convert \r\n to \n?
Expand Down Expand Up @@ -46,7 +46,7 @@ def tkinter_clipboard_get():
except ImportError:
message = ("Getting text from the clipboard on this platform "
"requires Tkinter.")
raise TryNext(message)
raise TryNext(_msg=message)
root = Tkinter.Tk()
root.withdraw()
text = root.clipboard_get()
Expand Down