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
ENH: Adds excepts #262
ENH: Adds excepts #262
Conversation
Wouldn't this be more curry-able if the exceptions were the first argument? |
I hadn't considered that. The reason behind the order is I was mapping the syntax of a try/except into a call like: try:
f(*args, **kwargs) # 1
except exc: # 2
default() # 3 Also to match the rejected pep 463 http://legacy.python.org/dev/peps/pep-0463/ I think that the curry case (meaning it can be used as a decorator) far outweighs my reasons. |
pushed the flip change. |
Last commit was strange, apparently |
ping @eriknw |
I made a slight api change: This change makes this function a try/except analog to ifexprs. |
Cool. I'll check this out (again) very soon. Somebody actually just asked me whether something like this exists. (btw, I do get pings. Sorry again for my delay. |
Bump. I've wanted to use something like this in toolz-ish code a few times. |
In general I like the idea. The class within a class rings my (admittedly irrational) complexity warning bells. Is there a way to de-fancify that, perhaps using |
I think the |
Is the docstring of the underlying callable sufficient? If not then we On Wed, Dec 2, 2015 at 4:31 PM, Joe Jevnik notifications@github.com wrote:
|
I think these are different use-cases. I expect that 99% of the usage of By contrast, the primary use-case for |
Also, I'm not sure if setting The primary use-case I had in mind for #286 was showing the source code via IPython's |
OK, I guess my principle concern is the high-tech nature of generating and presenting the docstring. Is there a lower-tech solution? |
I don't know know if there is a way to preserve the class docstring on the class itself while still giving each instance a nice docstring explaining what the new function will do. If you have a suggestion I am open to changing the current implementation. |
|
||
excepting = excepts(object(), object(), object()) | ||
assert excepting.__name__ == 'excepting' | ||
assert excepting.__doc__ == excepts.__doc__ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to test that we only pass on the provided Exception
type. A small test that raises a different kind of error than the provided type would be useful.
I'm still not super happy about the dynamic class generation. I would not want to see this kind of solution percolate more broadly throughout So I suggest that we go ahead with what's here for now to see if perhaps my paranoia is unjustified. |
I can pull the inner class out of the body of |
That sounds great :) |
I pulled the inner class out and added the test for exceptions not masked by |
ping @mrocklin |
Merged. Thanks @llllllllll |
The idea of this is to use exception based api functions alongside your normal functional code.
for example:
This helps us get around the fact that I cannot put an
except
clause in a lambda. I have found this to be very useful in my own code.Most of this code is for fresh
__name__
and__doc__
attributes.