3 ms·
>actually remove syntactic sugar and force more characters for the same functionality. I fail to see how this is even being considered. Python is not APL. Gett
by zahlman 2y ago
>actually remove syntactic sugar and force more characters for the same functionality. I fail to see how this is even being considered.
Python is not APL. Getting at the functionality in fewer characters is not a design goal - it's just a usually consequence of the actual design goal.
This is being considered because "Explicit is better than implicit." and because it helps avoid a common class of error (e.g. `except: continue` prevents aborting a loop with Ctrl-C, which is often not intentional).
Or as the PEP puts it:
> While this syntax can be convenient for a “catch all” handler, it often leads to poor coding practices:
>
> 1. It can mask important errors that should be propagated.
> 2. It makes debugging more difficult by catching and potentially hiding unexpected exceptions.
> 3. It goes against the Python principle of explicit over implicit.
Python isn't any other language, either. It certainly isn't taking design guidance from JavaScript (which runs in an environment where the page is expected to show something coherent, and not a loud screaming error, no matter how absurd the input data and/or code).
As for how much code it would break, you made me curious:
~/Desktop/dev$ find . -name "*.py" | wc -l
49433
~/Desktop/dev$ grep --include='*.py' -rnw . -e 'except.*:' | wc -l
109801
~/Desktop/dev$ grep --include='*.py' -rnw . -e 'except:' | wc -l
5692
~/Desktop/dev$ grep --include='*.py' -rnw . -e 'except[ \t]*:' | wc -l # just to make sure
5692
But drilling down further, over 2/3 of those bare excepts are in local copies of Python itself (i.e., multiple versions of the standard library) that I built from source. Probably all the rest are in dependencies. I don't write code like that myself if I'm even remotely paying attention. (Of course, that only tells me how many occurrences there were, not how many files have them. But the first two results imply an average of about 2 `except`s per file, so.)