13
13
import token
14
14
import tokenize
15
15
16
+ from dataclasses import dataclass
16
17
from types import CodeType
17
18
from typing import (
18
19
cast , Any , Callable , Dict , Iterable , List , Optional , Protocol , Sequence ,
@@ -462,7 +463,8 @@ def _find_statements(self) -> Iterable[TLineNo]:
462
463
# AST analysis
463
464
#
464
465
465
- class ArcStart (collections .namedtuple ("Arc" , "lineno, cause" )):
466
+ @dataclass (frozen = True , order = True )
467
+ class ArcStart :
466
468
"""The information needed to start an arc.
467
469
468
470
`lineno` is the line number the arc starts from.
@@ -474,8 +476,8 @@ class ArcStart(collections.namedtuple("Arc", "lineno, cause")):
474
476
to have `lineno` interpolated into it.
475
477
476
478
"""
477
- def __new__ ( cls , lineno : TLineNo , cause : str | None = None ) -> ArcStart :
478
- return super (). __new__ ( cls , lineno , cause )
479
+ lineno : TLineNo
480
+ cause : str = ""
479
481
480
482
481
483
class TAddArcFn (Protocol ):
@@ -1256,7 +1258,7 @@ def _combine_finally_starts(self, starts: set[ArcStart], exits: set[ArcStart]) -
1256
1258
"""
1257
1259
causes = []
1258
1260
for start in sorted (starts ):
1259
- if start .cause is not None :
1261
+ if start .cause :
1260
1262
causes .append (start .cause .format (lineno = start .lineno ))
1261
1263
cause = " or " .join (causes )
1262
1264
exits = {ArcStart (xit .lineno , cause ) for xit in exits }
0 commit comments