Re: Access to return / exception context in finally block

2025-09-01 Thread marius.spix--- via Python-list
>In your example when would isinstance(__exit_context__, ReturnContext) >be True and when would it be False? What would __exit_context__.value >be? I can't think of a sensible meaning for it. If no exception occurs, >is the value returned by f supposed to be 10/x or __exit_context__.value >+ 1

Re: Access to return / exception context in finally block

2025-09-02 Thread marius.spix--- via Python-list
>def f(x): > try: > quot = 10 / x > except ZeroDivisionError as exc: > log_error(exc) > return 0 > else: > log_return(quot) > return quot + 1 > finally: > "Any cleanup processing needed before returning" This involves defining the new

Access to return / exception context in finally block

2025-08-30 Thread marius.spix--- via Python-list
Dear mailing list, there is currently no direct way to observe the current interpreter state in a finally block without tracing. My idea is introducing an immutable __exit_context__ magic variable, which would have one of three possible values: * ReturnContext(value), if a return statement is