On Fri, Sep 25, 2020 at 3:38 PM Steven D'Aprano <st...@pearwood.info> wrote:
> The last thing I want to see is people being encouraged to write code > like this: > > def demo(arg)->Something: [... elided ...] > except: > # Any other unexpected error. > raise ValueError('something unexpected') > > just to ensure that the declared exception is correct. Chris Angelico follows up: > Another thing I don't want to see is: [... example which only catches the subset named in raise elided ...] > where people feel they HAVE to catch everything that a function could > raise. (Which, btw, still ignores the fact that basically any code > could raise MemoryError, KeyboardInterrupt, etc.) I'm -1 on this because I don't see how it could possibly be more useful than a tool that greps all the class and def statements (to identify functions) and all the raises (and presumably caches at least the builtin and stdlib raise information), and then tells your IDE about it. But "encouraging people to write bad code" seems a bit unfair, and probably invalidated in practice by the experience with mypy annotations (and certainly mitigated by the fact that a lot of annotations end up in stub files that only mypy users care much about). > Only catch those exceptions that you can actually handle. Otherwise, > it's irrelevant what the function might raise. This is a good rule. It seems to me that this proposal is intended to address the question: how do you know what subset of exceptions you can handle (and care to do so) are raised? This is why I don't see this proposal as useful to me. It leaves it up to the writer of the function to decide what exceptions interest me. Will the list be sufficiently complete from my point of view? Will it be correctly updated in new versions? _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/R7QTUQCQQLAK27PSOAVXUUDNCORMM55Q/ Code of Conduct: http://python.org/psf/codeofconduct/