-
-
Notifications
You must be signed in to change notification settings - Fork 130
Variant of safe that preserves the argument that lead to an exception #264
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
Comments
Oh, I see. Do you want to send a PR? |
I haven't worked with mypy plugins/decorators in a while so I'm not sure if there is a neat way to implement |
It can be a good be a start. |
After looking into this for the last half hour I think getting this to typecheck without something like https://www.python.org/dev/peps/pep-0612/ will require its own plugin since one has to get at the types of the arguments of |
I think so too, that's the big problem with |
I was thinking about the implementation here, one thing we need to define is what to do with functions that has multiple parameters, like, if my function has 3 arguments like: def my_func(a, b, *, c):
pass
my_func(1, 2, c=3) What should be inside the Result? A tuple where the first element is the positional args and then the second the keyword args? |
Any thoughts @sobolevn?? |
I think that functions with multiple arguments should not be allowed in this case. |
I propose a function/decorator (maybe
attempt
would be a good name?) similar tosafe
with the twist of returningFailure(bad_input)
fromsafe(f)(bad_input)
instead ofFailure(SomeException)
. An example where this would be useful:The text was updated successfully, but these errors were encountered: