This looks like an attempt to use Rust-type error handling in Python. This is pounding a screw. Rust does it that way because Rust doesn't have exceptions. (Although, as with Go, all the heavy machinery for exception unwinding has been retrofitted so "recover" will work. Rust and Go just don't have the syntax for exceptions.) Python doesn't need to become Rust, or Haskell.
Writing
except Exception as e:
is clueless Python. If you're checking for something that went wrong in the outside world, you catch EnvironmentError. Catching Exception catches far too much, including syntax errors. It's sometimes useful to catch Exception at the top level of a program, log an error, and restart, but not in interior code.
Note how useless the examples in the article are. It's not like someone is trying to handle all the things that can go wrong in a network connection, or in nested code where you have a network connection and a database transaction open at the same time, either can fail, and you have to unwind properly.
Typed language are fine, but this semi-checked addition of types to Python is a mess. Python doesn't need this. I'm in favor of design by contract, typing, and assertions, but not in this broken semi-optional way.
I know. Python is one of the few languages to get exceptions right. There's a reasonably sane exception hierarchy, and if you catch something, you get everything in its subtree. The "with" clause and exceptions interact properly, so if you hit a problem closing a resource in a "with", the right stuff happens. Since Python is reference counted/garbage collected, you don't have the ownership problem of exception objects you have in C++. Python isn't big on RAII, so you don't have the exception-in-a-destructor problem (or worse, the exception during GC problem) unless you do something to force that.
Python is probably the best type declaration free language around. Trying to make it into something else damages the language. Python has become uncool, though, and so "cool features" are being added that don't quite fit.
These changes to Python are so big that this should have been called Python 4. But if Guido had done that, the reply from the big users would have been "Hell, no, we won't go!".
Writing
is clueless Python. If you're checking for something that went wrong in the outside world, you catch EnvironmentError. Catching Exception catches far too much, including syntax errors. It's sometimes useful to catch Exception at the top level of a program, log an error, and restart, but not in interior code.Note how useless the examples in the article are. It's not like someone is trying to handle all the things that can go wrong in a network connection, or in nested code where you have a network connection and a database transaction open at the same time, either can fail, and you have to unwind properly.
Typed language are fine, but this semi-checked addition of types to Python is a mess. Python doesn't need this. I'm in favor of design by contract, typing, and assertions, but not in this broken semi-optional way.
Stop Guido before he kills again.