Skip to content

Commit

Permalink
Protect node_frame_class against looping continuously on Uninferable
Browse files Browse the repository at this point in the history
`node_frame_class` was receiving an `Uninferable` object. This object has the property
that its boolean value is false, but comparing it against `None` will always return true.
Because `node_frame_class` was walking up the tree to find the containing class, it was exempting
any node that was not a class, and since comparing `Uninferable` to `None` was always returning
true, the loop was running forever.

Close #3426
  • Loading branch information
PCManticore committed Mar 2, 2020
1 parent b90dfad commit 93bc0db
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pylint/checkers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,16 @@ def node_frame_class(node: astroid.node_classes.NodeNG) -> Optional[astroid.Clas
classmethod), otherwise it returns `None`.
"""
klass = node.frame()

while klass is not None and not isinstance(klass, astroid.ClassDef):
nodes_to_check = (
astroid.node_classes.NodeNG,
astroid.UnboundMethod,
astroid.BaseInstance,
)
while (
klass
and isinstance(klass, nodes_to_check)
and not isinstance(klass, astroid.ClassDef)
):
if klass.parent is None:
klass = None
else:
Expand Down

0 comments on commit 93bc0db

Please sign in to comment.