Skip to content

Commit bee7dc5

Browse files
committed
Move nodes_of_class null check out of inner loop
The check was being repeated unnecessarily in a tight loop.
1 parent 2563960 commit bee7dc5

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

astroid/node_classes.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,8 +627,16 @@ def nodes_of_class(self, klass, skip_klass=None):
627627
"""
628628
if isinstance(self, klass):
629629
yield self
630+
631+
if skip_klass is None:
632+
for child_node in self.get_children():
633+
for matching in child_node.nodes_of_class(klass, skip_klass):
634+
yield matching
635+
636+
return
637+
630638
for child_node in self.get_children():
631-
if skip_klass is not None and isinstance(child_node, skip_klass):
639+
if isinstance(child_node, skip_klass):
632640
continue
633641
for matching in child_node.nodes_of_class(klass, skip_klass):
634642
yield matching

0 commit comments

Comments
 (0)