Skip to content

Commit

Permalink
Refactor to reduce duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
smk4664 committed Jan 1, 2025
1 parent d7a3033 commit 5a97a30
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions pylint_nautobot/q_search_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ def __init__(self, *args, **kwargs):

def visit_classdef(self, node: ClassDef):
"""Visit class definitions."""
if not any(ancestor.qname() in self.meta_classes for ancestor in node.ancestors()):
if all(
ancestor.qname() not in self.meta_classes
for ancestor in node.ancestors()
):
return

for child_node in node.get_children():
if isinstance(child_node, Assign):
if any(isinstance(target, AssignName) and target.name == "q" for target in child_node.targets):
# because they can be ast Name or Attribute nodes
child_node_name = child_node.value.func.as_string().split(".")[-1]
if child_node_name != "SearchFilter":
self.add_message("nb-use-search-filter", node=child_node)
if isinstance(child_node, Assign) and any(isinstance(target, AssignName) and target.name == "q" for target in child_node.targets):
child_node_name = child_node.value.func.as_string().split(".")[-1]
if child_node_name != "SearchFilter":
self.add_message("nb-use-search-filter", node=child_node)

0 comments on commit 5a97a30

Please sign in to comment.