Live data from Hacker News

Python exceptions considered an anti-pattern

sobolevn.me

1–10 of 69 posts

Re: Python exceptions considered an anti-pattern

#2
The interesting bit starts at https://sobolevn.me/2019/02/python-exceptions-considered-an-..., where it introduces a library for wrapping errors in return types, even if it got little to do with the headline. IMHO the article would be stronger with a title about what it presents and without the first half.

Re: Python exceptions considered an anti-pattern

#3
post #2

The interesting bit starts at https://sobolevn.me/2019/02/python-exceptions-considered-an-... , where it introduces a library for wrapping errors in return types, even if it got little to do with the headline. IMHO the article would be stronger with a title about what it presents and without the first half.

Thanks, my idea was to state the problem and propose a solution. Hope, that you will find `returns` helpful.

Re: Python exceptions considered an anti-pattern

#4
post #3
post #2

The interesting bit starts at https://sobolevn.me/2019/02/python-exceptions-considered-an-... , where it introduces a library for wrapping errors in return types, even if it got little to do with the headline. IMHO the article would be stronger with a title about what it presents and without the first half.

Thanks, my idea was to state the problem and propose a solution. Hope, that you will find `returns` helpful.

One risk with the title is that it doesn't convey that it's actually proposing a solution instead of being one of many "$languagefeature is bad" articles. I personally also found the problem statement presentation not all that convincing and almost closed the tab before reaching the interesting section, which is why I made the comment above.

Re: Python exceptions considered an anti-pattern

#5
post #3
post #2

The interesting bit starts at https://sobolevn.me/2019/02/python-exceptions-considered-an-... , where it introduces a library for wrapping errors in return types, even if it got little to do with the headline. IMHO the article would be stronger with a title about what it presents and without the first half.

Thanks, my idea was to state the problem and propose a solution. Hope, that you will find `returns` helpful.

Thanks for the solution! It's elegant and is a great fit for my current work which involves retrofitting my codebase with type annotations.

Re: Python exceptions considered an anti-pattern

#7
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)

Re: Python exceptions considered an anti-pattern

#9
I'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 to happen when unexpected situations happen.

Re: Python exceptions considered an anti-pattern

#10
post #7

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.
Post reply on HN