3 ms·
> Digging in, it looks like people are working around this by returning exceptions, which is very clever and I hadn't thought of it before. Never came across t
by diarrhea 3y ago
> Digging in, it looks like people are working around this by returning exceptions, which is very clever and I hadn't thought of it before.
Never came across that! Where did you find that? Pretty interesting. I'd call it deeply unpythonic and very surprising. It's unfortunate to not have a Result type/idiom, but IMHO faking it isn't the way to go either.
- maxbond 3y agoI saw it in this Stack Overflow answer: https://stackoverflow.com/a/74192977 https://stackoverflow.com/a/74192977 I haven't given it a great deal if thought, it would probably mess up stack traces if you raised it later, which would be bad. I agree it's unpythonic, I've implemented result-like types in Python before which has worked okay. ETA: That answer links to this library, which uses a decorator technique that I think will still print a good traceback if you reraise it later (definitely will if you use `raise ... from` syntax), but I can't test it at the moment: https://github.com/alexandermalyga/poltergeist https://github.com/alexandermalyga/poltergeist I probably won't be putting this into production anytime soon but it was charming food for thought.