[Python-Dev] Re: PEP 654 -- Exception Groups and except* : request for feedback for SC submission

2021年2月23日 16:13:56 -0800

On 2021年02月23日 23:05, Caleb Donovick wrote:
What is the motivation for returning `None` on empty splits? I feel like this creates an unnecessary asymmetry. I don't personally have a use case for the this feature so I may be missing something but it seems like it would force an annoying pattern:
```
try:
   foo()
except ExceptionGroup as eg:
   g1, g2 = eg.split(predicate)
   for e in g1:
     handle_true(e)
   for e in g2:
     handle_false(e)
```
Would need to be written:
```
try:
   foo()
except ExceptionGroup as eg:
   g1, g2 = eg.split(predicate)
   if g1 is not None:
     for e in g1:
       handle_true(e)
   if g2 is not None:
     for e in g2:
       handle_false(e)
```
Also this creates an subtle difference with subgroup:
```
g1, g2 = eg.split(predicate)
h1, h2 = eg.subgroup(predicate), eg.subgroup(lambda e: not predicate(e))
assert g1 == h1 and g2 == h2 # only true if `None not in {g1, g2}`
```
.subgroup returns an ExceptionGroup and .split returns 2 of them.
ExceptionGroup isn't iterable (it's mentioned in the "Rejected Ideas" section), so your code wouldn't work anyway.
On Mon, Feb 22, 2021 at 4:47 PM Irit Katriel via Python-Dev <[email protected] <mailto:[email protected]>> wrote:
 Hi all,
 We would like to request feedback on PEP 654 -- Exception Groups and
 except*.
 https://www.python.org/dev/peps/pep-0654/
 <https://www.python.org/dev/peps/pep-0654/>
 It proposes language extensions that allow programs to raise and
 handle multiple unrelated
 exceptions simultaneously, motivated by the needs of asyncio and
 other concurrency libraries,
 but with other use cases as well.
 * A new standard exception type, ExceptionGroup, to represent
 multiple exceptions with
  shared traceback.
 * Updates to the traceback printing code to display (possibly
 nested) ExceptionGroups.
 * A new syntax except* for handling ExceptionGroups.
 A reference implementation (unreviewed) can be found at:
 https://github.com/iritkatriel/cpython/pull/10
 <https://github.com/iritkatriel/cpython/pull/10>
 Thank you for your help
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/U7A4PZE7SSDFNKAFZZ3BZBLL7VGTOWVL/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to