Skip to content

Commit 52e6765

Browse files
nickdrozdPCManticore
authored andcommitted
Add type-specific get_children
get_children is elegant and flexible and slow. def get_children(self): for field in self._astroid_fields: attr = getattr(self, field) if attr is None: continue if isinstance(attr, (list, tuple)): for elt in attr: yield elt else: yield attr It iterates over a list, dynamically accesses attributes, does null checks, and does type checking. This function gets called a lot, and all that extra work is a real drag on performance. In most cases there isn't any need to do any of these checks. Take an Assign node for instance: def get_children(self): for elt in self.targets: yield elt yield self.value It's known in advance that Assign nodes have a list of targets and a value, so just yield those without checking anything.
1 parent 7ead5dd commit 52e6765

File tree

2 files changed

+273
-8
lines changed

2 files changed

+273
-8
lines changed

0 commit comments

Comments
 (0)