Skip to content

Commit

Permalink
refactor: Avoid recursion loops
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Nov 28, 2021
1 parent 99a0f8b commit ea6acec
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/griffe/agents/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,10 @@ def is_staticmethod(self) -> bool:
"""
if not self.parent:
return False
self_from_parent = self.parent.obj.__dict__.get(self.name, None) # noqa: WPS609
try:
self_from_parent = self.parent.obj.__dict__.get(self.name, None) # noqa: WPS609
except AttributeError:
return False
return self.parent_is_class and isinstance(self_from_parent, staticmethod)

@cached_property
Expand All @@ -418,18 +421,20 @@ def is_classmethod(self) -> bool:
"""
if not self.parent:
return False
self_from_parent = self.parent.obj.__dict__.get(self.name, None) # noqa: WPS609
try:
self_from_parent = self.parent.obj.__dict__.get(self.name, None) # noqa: WPS609
except AttributeError:
return False
return self.parent_is_class and isinstance(self_from_parent, classmethod)

def _pick_member(self, member: Any) -> bool:
return member is not type and member is not object and not self._seen(member)

def _seen(self, member: Any) -> bool:
if member is self.obj:
return True
@cached_property
def _ids(self) -> set[int]:
if self.parent is None:
return False
return self.parent._seen(member) # noqa: WPS437
return {id(self)}
return {id(self)} | self.parent._ids # noqa: WPS437

def _pick_member(self, member: Any) -> bool:
return member is not type and member is not object and id(member) not in self._ids


def _join(sequence, item):
Expand Down

0 comments on commit ea6acec

Please sign in to comment.