Since using Rust, I've longed for this in Python but - imo it effectively requires using type checking (mypy) - Too out of place with the rest of the python ecosystem (even if I like something, I'd rather not force non-standard practices on others dealing with my code)
I don't know, for things where you can get team buy-in, this looks like a great way to have more solid contracts. I've always disliked how you can specify accept/return types in Python but then there's this whole side-channel of exceptions that you can't check or document well.
Python exceptions considered an anti-pattern
11–20 of 69 posts
Re: Python exceptions considered an anti-pattern
#12Earlier quoted context omitted.
I don't know, for things where you can get team buy-in, this looks like a great way to have more solid contracts. I've always disliked how you can specify accept/return types in Python but then there's this whole side-channel of exceptions that you can't check or document well.
How familiar are you with Java?
In java you need to specify what your function can throw and if it tries to throw something that it has not specified as being able to throw, then your program won't compile.
Re: Python exceptions considered an anti-pattern
#13Re: Python exceptions considered an anti-pattern
#14Re: Python exceptions considered an anti-pattern
#15A very strong and emotional point. Accidentally working code will have exceptional handling because of problems during development.
The whole article is depreciated by naive library implementation because unwrap() hides source of original exception. Sadly it's not even a POC.
Edit: Failure doesn't capture trace information at all. Library users will get unusable error in a wrong place.
Re: Python exceptions considered an anti-pattern
#16Earlier quoted context omitted.
I don't know, for things where you can get team buy-in, this looks like a great way to have more solid contracts. I've always disliked how you can specify accept/return types in Python but then there's this whole side-channel of exceptions that you can't check or document well.
How familiar are you with Java?
Re: Python exceptions considered an anti-pattern
#17Earlier quoted context omitted.
How familiar are you with Java?
I was about to post something similar to this. In java you need to specify what your function can throw and if it tries to throw something that it has not specified as being able to throw, then your program won't compile.
Re: Python exceptions considered an anti-pattern
#18Earlier quoted context omitted.
How familiar are you with Java?
I was about to post something similar to this. In java you need to specify what your function can throw and if it tries to throw something that it has not specified as being able to throw, then your program won't compile.
Re: Python exceptions considered an anti-pattern
#19I'm glad this issue is getting some attention. I found the "Exceptions are not exceptional" section to capture something I've noticed several times — that code in Python can fail at a huge number of points even in a small function, nevermind the many exceptions that might happen in nested functions, or code we're using from libraries. We should have language-level mechanisms for being explicit about what's supposed t…
This is why unit-tests are really important in Python.
> We should have language-level mechanisms for being explicit about what's supposed to happen when unexpected situations happen.
That's implemented as a try-except block. You're not supposed to catch errors at the low level unless you're explicitly handling them. If there's an error, bubble it up to the main().
Python's try-except can catch classes, sub-classes, and/or groups (tuples) of classes. It's important to categorize your errors.