13 Oct
2020
13 Oct
'20
5:26 p.m.
On 10/13/2020 11:09 AM, Chris Angelico wrote:
On Wed, Oct 14, 2020 at 1:41 AM Ronald Oussoren via Python-ideas
wrote: #— (python 3.9)
import dataclasses
@dataclasses.dataclass class MyException (Exception): a : int b : str
try: raise MyException(a=1, b="hello")
except MyException as exc: print(f"{exc.a=}, {exc.b=}”)
# —
I like it. Very elegant. Never thought of a dataclass as an exception.
That's the beauty of dataclasses not using metaclasses or inheritance: they can be used pretty much anywhere, with very few adverse interactions. All credit to attrs for this design. Eric