2 ms·
Then Alice can catch the exceptions and put them into a list for later, if that's what she really wants. This feels like a pretty contrived example. The genera
by dahfizz 4y ago
Then Alice can catch the exceptions and put them into a list for later, if that's what she really wants. This feels like a pretty contrived example.
The general case is that `get_foo()` should return a Foo, or throw an exception if it can't. It shouldn't return a Foo, or a BarError, or a BazError.
The fact that you can tuck these completely different objects away for processing later without knowing what they are is not a desirable feature. That's just going to be a source of bugs.
In a language with a stronger type system, I see the benefit of option types and the like. But in Python, having a list of `my_foos` contain mostly Foos, but also some garbage, is not something you want.
- tialaramex 4y ago> This feels like a pretty contrived example. Well, it's certainly not popular in Python today. And it seems the reaction from most Python programmers is they'd just force Alice to take the hit, whereupon presumably Alice ceases using Python for this application, and that's maybe fine, it's not as though there aren't other languages. But it seems like a shame because Python can do this the other way. > In a language with a stronger type system, I see the benefit My instinct is that the direction of Python is towards a stronger type system. I remember when Python's type hints were a very obscure feature few ever cared about and now it seems like every other Python story involves the type system and type annotation is strongly encouraged. But I could be wrong.