Skip to content

Commit

Permalink
Change _get_assign_nodes() to cached_property
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Mar 12, 2023
1 parent c752c33 commit dcd6a69
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
7 changes: 3 additions & 4 deletions astroid/nodes/_base_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from collections.abc import Iterator
from typing import TYPE_CHECKING, ClassVar

from astroid import decorators
from astroid.exceptions import AttributeInferenceError
from astroid.nodes.node_ng import NodeNG

Expand Down Expand Up @@ -196,10 +195,10 @@ def _get_yield_nodes_skip_lambdas(self):
continue
yield from child_node._get_yield_nodes_skip_lambdas()

@decorators.cached
def _get_assign_nodes(self):
@cached_property
def _assign_nodes_in_scope(self) -> list[nodes.Assign]:
children_assign_nodes = (
child_node._get_assign_nodes()
child_node._assign_nodes_in_scope
for block in self._multi_line_blocks
for child_node in block
)
Expand Down
6 changes: 3 additions & 3 deletions astroid/nodes/node_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1271,9 +1271,9 @@ def get_children(self):

yield self.value

@decorators.cached
def _get_assign_nodes(self):
return [self] + list(self.value._get_assign_nodes())
@cached_property
def _assign_nodes_in_scope(self) -> list[nodes.Assign]:
return [self] + self.value._assign_nodes_in_scope

def _get_yield_nodes_skip_lambdas(self):
yield from self.value._get_yield_nodes_skip_lambdas()
Expand Down
6 changes: 3 additions & 3 deletions astroid/nodes/node_ng.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
overload,
)

from astroid import decorators, util
from astroid import util
from astroid.context import InferenceContext
from astroid.exceptions import (
AstroidError,
Expand Down Expand Up @@ -575,8 +575,8 @@ def nodes_of_class( # type: ignore[misc] # mypy doesn't correctly recognize the
continue
yield from child_node.nodes_of_class(klass, skip_klass)

@decorators.cached
def _get_assign_nodes(self):
@cached_property
def _assign_nodes_in_scope(self) -> list[nodes.Assign]:
return []

def _get_name_nodes(self):
Expand Down
8 changes: 4 additions & 4 deletions astroid/nodes/scoped_nodes/scoped_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1434,7 +1434,7 @@ def extra_decorators(self) -> list[node_classes.Call]:
return []

decorators: list[node_classes.Call] = []
for assign in frame._get_assign_nodes():
for assign in frame._assign_nodes_in_scope:
if isinstance(assign.value, node_classes.Call) and isinstance(
assign.value.func, node_classes.Name
):
Expand Down Expand Up @@ -3065,10 +3065,10 @@ def get_children(self):
yield from self.keywords
yield from self.body

@decorators_mod.cached
def _get_assign_nodes(self):
@cached_property
def _assign_nodes_in_scope(self):
children_assign_nodes = (
child_node._get_assign_nodes() for child_node in self.body
child_node._assign_nodes_in_scope for child_node in self.body
)
return list(itertools.chain.from_iterable(children_assign_nodes))

Expand Down

0 comments on commit dcd6a69

Please sign in to comment.