@@ -596,46 +596,48 @@ def stripped_lines(
596
596
the line
597
597
:return: the collection of line/line number/line type tuples
598
598
"""
599
- # pylint: disable=possibly-used-before-assignment
599
+ ignore_lines : set [ int ] = set ()
600
600
if ignore_imports or ignore_signatures :
601
601
tree = astroid .parse ("" .join (lines ))
602
- if ignore_imports :
603
- import_lines = {}
604
- for node in tree .nodes_of_class ((nodes .Import , nodes .ImportFrom )):
605
- for lineno in range (node .lineno , (node .end_lineno or node .lineno ) + 1 ):
606
- import_lines [lineno ] = True
607
- if ignore_signatures :
608
-
609
- def _get_functions (
610
- functions : list [nodes .NodeNG ], tree : nodes .NodeNG
611
- ) -> list [nodes .NodeNG ]:
612
- """Recursively get all functions including nested in the classes from the
613
- tree.
614
- """
615
- for node in tree .body :
616
- if isinstance (node , (nodes .FunctionDef , nodes .AsyncFunctionDef )):
617
- functions .append (node )
618
-
619
- if isinstance (
620
- node ,
621
- (nodes .ClassDef , nodes .FunctionDef , nodes .AsyncFunctionDef ),
622
- ):
623
- _get_functions (functions , node )
624
-
625
- return functions
626
-
627
- functions = _get_functions ([], tree )
628
- signature_lines = set (
629
- chain (
630
- * (
602
+ if ignore_imports :
603
+ ignore_lines .update (
604
+ chain .from_iterable (
605
+ range (node .lineno , (node .end_lineno or node .lineno ) + 1 )
606
+ for node in tree .nodes_of_class ((nodes .Import , nodes .ImportFrom ))
607
+ )
608
+ )
609
+ if ignore_signatures :
610
+
611
+ def _get_functions (
612
+ functions : list [nodes .NodeNG ], tree : nodes .NodeNG
613
+ ) -> list [nodes .NodeNG ]:
614
+ """Recursively get all functions including nested in the classes from
615
+ the.
616
+
617
+ tree.
618
+ """
619
+ for node in tree .body :
620
+ if isinstance (node , (nodes .FunctionDef , nodes .AsyncFunctionDef )):
621
+ functions .append (node )
622
+
623
+ if isinstance (
624
+ node ,
625
+ (nodes .ClassDef , nodes .FunctionDef , nodes .AsyncFunctionDef ),
626
+ ):
627
+ _get_functions (functions , node )
628
+
629
+ return functions
630
+
631
+ functions = _get_functions ([], tree )
632
+ ignore_lines .update (
633
+ chain .from_iterable (
631
634
range (
632
635
func .lineno ,
633
636
func .body [0 ].lineno if func .body else func .tolineno + 1 ,
634
637
)
635
638
for func in functions
636
639
)
637
640
)
638
- )
639
641
640
642
strippedlines = []
641
643
docstring = None
@@ -657,13 +659,9 @@ def _get_functions(
657
659
if line .endswith (docstring ):
658
660
docstring = None
659
661
line = ""
660
- if ignore_imports :
661
- current_line_is_import = import_lines .get (lineno , False )
662
- if current_line_is_import :
663
- line = ""
664
662
if ignore_comments :
665
663
line = line .split ("#" , 1 )[0 ].strip ()
666
- if ignore_signatures and lineno in signature_lines :
664
+ if lineno in ignore_lines :
667
665
line = ""
668
666
if line :
669
667
strippedlines .append (
0 commit comments