@@ -296,7 +296,7 @@ def _analyze_ast(self) -> None:
296
296
297
297
"""
298
298
assert self ._ast_root is not None
299
- aaa = AstArcAnalyzer (self ._ast_root , self .raw_statements , self ._multiline )
299
+ aaa = AstArcAnalyzer (self .filename , self . _ast_root , self .raw_statements , self ._multiline )
300
300
aaa .analyze ()
301
301
self ._with_jump_fixers = aaa .with_jump_fixers ()
302
302
@@ -337,9 +337,7 @@ def exit_counts(self) -> dict[TLineNo, int]:
337
337
"""
338
338
exit_counts : dict [TLineNo , int ] = collections .defaultdict (int )
339
339
for l1 , l2 in self .arcs ():
340
- if l1 < 0 :
341
- # Don't ever report -1 as a line number
342
- continue
340
+ assert l1 > 0 , f"{ l1 = } should be greater than zero in { self .filename } "
343
341
if l1 in self .excluded :
344
342
# Don't report excluded lines as line numbers.
345
343
continue
@@ -437,15 +435,15 @@ def _line_numbers(self) -> Iterable[TLineNo]:
437
435
byte_num = 0
438
436
for byte_incr , line_incr in zip (byte_increments , line_increments ):
439
437
if byte_incr :
440
- if line_num != last_line_num :
441
- yield line_num
442
- last_line_num = line_num
438
+ assert line_num != last_line_num , f"Oops, { byte_incr = } , { line_incr = } "
439
+ yield line_num
440
+ last_line_num = line_num
443
441
byte_num += byte_incr
444
442
if line_incr >= 0x80 :
445
443
line_incr -= 0x100
446
444
line_num += line_incr
447
- if line_num != last_line_num :
448
- yield line_num
445
+ assert line_num != last_line_num
446
+ yield line_num
449
447
450
448
def _find_statements (self ) -> Iterable [TLineNo ]:
451
449
"""Find the statements in `self.code`.
@@ -643,10 +641,12 @@ class AstArcAnalyzer:
643
641
644
642
def __init__ (
645
643
self ,
644
+ filename : str ,
646
645
root_node : ast .AST ,
647
646
statements : set [TLineNo ],
648
647
multiline : dict [TLineNo , TLineNo ],
649
648
) -> None :
649
+ self .filename = filename
650
650
self .root_node = root_node
651
651
# TODO: I think this is happening in too many places.
652
652
self .statements = {multiline .get (l , l ) for l in statements }
@@ -1076,9 +1076,9 @@ def _handle_decorated(self, node: ast.FunctionDef) -> set[ArcStart]:
1076
1076
# in `self.statements`. For some constructs, `line_for_node` is
1077
1077
# not what we'd think of as the first line in the statement, so map
1078
1078
# it to the first one.
1079
- if node .body :
1080
- body_start = self .line_for_node (node .body [0 ])
1081
- body_start = self .multiline .get (body_start , body_start )
1079
+ assert node .body , f"Oops: { node . body = } in { self . filename } @ { node . lineno } "
1080
+ body_start = self .line_for_node (node .body [0 ])
1081
+ body_start = self .multiline .get (body_start , body_start )
1082
1082
# The body is handled in collect_arcs.
1083
1083
assert last is not None
1084
1084
return {ArcStart (last )}
0 commit comments