New submission from Petr Viktorin <[email protected]>:
I want to test a web application by crawling every reachable page. If an error
occurs, I need to keep track of the page the error occured at (and additional
info like what links were followed to get to the page, so a `__note__` string
isn't enough). This info is in an object I'll call Task.
To use the improvements from PEP 654 but also keep extra info, I tried to make
a subclass of ExceptionGroup:
```python
class MultiError(ExceptionGroup):
def __init__(self, failed_tasks):
super.__init__(
f"{len(tasks)} tasks failed",
[t.exception for t in failed_tasks],
)
self.tasks = tasks
# ... and set __note__ on each exception for nice tracebacks
```
but this fails with a rather opaque message:
```python
>>> class Task: exception = AssertionError() # enough of a Task for this
>>> example
...
>>> MultiError([Task(), Task()])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: function takes exactly 2 arguments (1 given)
```
Knowing about `__new__` and following a note in the docs, I'm able to fix this,
but It's not obvious.
Before suggesting stuff, I'll ask: Am I doing something weird, or should this
be made easier/more obvious?
Another issue I ran into: the list of exceptions is stored in the
publicly-named but undocumented attribute `exceptions`. Am I allowed to use it?
----------
messages: 410942
nosy: iritkatriel, petr.viktorin
priority: normal
severity: normal
status: open
title: Trouble subclassing ExceptionGroup
versions: Python 3.11
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue46431>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com