News for hackers. Stuff that matters.
Re:Python Language Summit: PEP 654 – Exception Groups and Ex... by formerly_proven on Sunday May 16, 2021 @05:52AM (#27172518)
Recently I came up with a related idea for repeated error handling code, in the usual Python vein of introducing an abstraction to save 2-3 lines:

    try:
        foobar
    delegate handle_stuff:
    delegate handler_factory(something):
    except Foo:
        ...
    else:
        ...
    finally
        ...
Where "delegate handle_stuff" means that for any exception handle_stuff is called with the exception tuple and the exception is considered handled if it returns truthy. "delegate" of course takes an expression so that you can have Proper Adult Fun Handling Exceptions.
Re:Python Language Summit: PEP 654 – Exception Groups and Ex... by mfgs on Sunday May 16, 2021 @06:36AM (#27172687)
How is that ultimately different from handling the exception under `except`?
Re:Python Language Summit: PEP 654 – Exception Groups and Ex... by coldtea on Sunday May 16, 2021 @07:20AM (#27172875)
"in the usual Python vein of introducing an abstraction to save 2-3 lines"
Re:Python Language Summit: PEP 654 – Exception Groups and Ex... by ledauphin on Sunday May 16, 2021 @10:48AM (#27174080)
this is what abstractions are for. they can be done poorly or well, but there's a reason iterators are favored in most use cases over

    for (i = 0, i < n; i++) { a[i] }
- they're simpler to reason about because they restrict the conceptual operational space.
Re:Python Language Summit: PEP 654 – Exception Groups and Ex... by formerly_proven on Sunday May 16, 2021 @08:05AM (#27173103)
The "delegate" statement encapsulates which exceptions are handled and how in the supplied callable expression. This is functionally different from repeating "except (FooExc, BarExc, BazExc) as exc: handle(exc)". It would also save two to three lines on average.