Thanks, Mark... I had missed that aspect entirely. I think there might be a way round it... which actually was something I had been thinking of including in the same suggestion but thought was perhaps too obscure, but now I've realized it would integrate well with it. That is to have a value-returning form of try... except... But perhaps the two of them together are too much of a change. John On Mon, Oct 25, 2021 at 10:03 PM Mark Gordon <msg555@gmail.com> wrote:
What should happen if the context manager attempts to suppress a raised exception? In cases where you applied the context manager to an entire line, e.g.
data = fail() with contextlib.suppress(Exception)
Then it would make sense to treat it like
with contextlib.suppress(Exception): data = fail()
Where `data` remains unassigned after the block executes assuming `fail` raises an exception. However, with the initial proposal you run into trouble when you apply this to sub-expressions that are expected to themselves have a value. For example, what should happen here?
more_work(fail() with contextlib.suppress(Exception))
We have no value to pass as an argument to `more_work` so there's no way we can call it. Yet it would be odd to not call it if there's no exception being raised since it exists outside of any context manager itself. _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@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/Y7WZDD... Code of Conduct: http://python.org/psf/codeofconduct/