On Fri, Apr 9, 2021 at 6:16 AM Ethan Furman <et...@stoneleaf.us> wrote: > > On 4/8/21 11:25 AM, Chris Angelico wrote: > > > Similar question: What would be the semantics of this? > > > > with contextlib.suppress(BaseException): > > a = b / c > > except BaseException as e: > > print(e) > > > > What types of exception could be caught and what types couldn't? > > Well, if every exception is derived from BaseException (they are) and > contextlib.suppress(BaseException) suppresses all > BaseException-derived exceptions (it does) then the semantics of the above > are: > > - "a" will be the result of "b / c" if no exception occurs > - otherwise, "a" will be whatever it was before the with-block > - no exception will ever be caught by the except-clause > > Generally speaking, no exception that a context manager handles (i.e. > suppresses) will ever be available to be caught. >
What about NameError looking up contextlib, or AttributeError looking up suppress? Will they be caught by that except clause, or not? Thank you for making my point: your assumption is completely the opposite of the OP's, given the same syntactic structure. 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/E3C5T727AWFPYVBVNPQSQNRL4CLKAKRP/ Code of Conduct: http://python.org/psf/codeofconduct/