On Sat, Sep 26, 2020 at 3:42 AM Steven D'Aprano <st...@pearwood.info> wrote: > > In the list of all possible failures, will you include MemoryError? > > Sure, if I'm writing some sort of ultra-high availability server > application that is expected to run 24/7 for months at a time. > > while memory_in_reserve(): > try: > something() > break > except MemoryError: > release_rainy_day_fund() # Frees some emergency memory.
But if you DON'T have code like that, will you declare that your function might raise MemoryError? Just because it might be raised doesn't mean it's part of what needs to be documented. Nor because it might be caught. The problem with a proposal like this is that it is impossible to determine which exceptions make sense to document. My alarm script attempts to query upcoming events, and it catches ssl.SSLError, OSError, IOError, socket.error, and googleapiclient.http.HttpError. Should my upcoming_events function (a call to which is the only line in the 'try' block) be declared as raising all of those? Are there any other exceptions that I should declare? How would I know what set of exceptions is relevant to my caller? Only my caller knows what's relevant, so that's where the list of exceptions belongs: in the try/except block itself. Oh, I just discovered that that function can raise OverflowError if the script is run with --days=99999999999999999999999999999 - should I add that to the annotated list of exceptions? Is it relevant? How would I know? ChrisA _______________________________________________ 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/MSI5KHXWBLMMG5BUSM2JIHJIJUJIN7O7/ Code of Conduct: http://python.org/psf/codeofconduct/