Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Pierre Sassoulas <[email protected]>
  • Loading branch information
Julfried and Pierre-Sassoulas authored Jan 29, 2025
1 parent 55815df commit ca4f2df
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
10 changes: 3 additions & 7 deletions pylint/pyreverse/diadefslib.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,9 @@ def _get_levels(self) -> tuple[int, int]:

def _should_include_by_depth(self, node: nodes.NodeNG) -> bool:
"""Check if a node should be included based on depth."""
# If max_depth is not set, include all nodes
if self.config.max_depth is None:
return True

# For other nodes, calculate depth based on their root module
module_depth = node.root().name.count(".")
return module_depth <= self.config.max_depth # type: ignore[no-any-return]
# If max_depth is not set, include all nodes, otherwise, calculate depth based on
# node's root module
return self.config.max_depth is None or bool(node.root().name.count(".") <= self.config.max_depth)

def show_node(self, node: nodes.ClassDef) -> bool:
"""Determine if node should be shown based on config."""
Expand Down
8 changes: 2 additions & 6 deletions tests/pyreverse/test_diadefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ def test_regression_dataclasses_inference(
assert cd.title == special


# Test for no depth limit
def test_should_include_by_depth_no_limit(
generator: DiaDefGenerator, mock_node: Mock
) -> None:
Expand Down Expand Up @@ -308,10 +307,7 @@ def test_should_include_by_depth_with_limit(
- 'pkg.subpkg.module' -> depth 2 (2 dots)
- 'pkg.subpkg.module.submodule' -> depth 3 (3 dots)
"""
# Set generator config
generator.config.max_depth = max_depth

# Test cases for different depths
test_cases = [
"pkg",
"pkg.subpkg",
Expand All @@ -323,9 +319,9 @@ def test_should_include_by_depth_with_limit(
# Test if nodes are shown based on their depth and max_depth setting
for i, node in enumerate(nodes):
should_show = i <= max_depth
print(
msg = (
f"Node {node.root.return_value.name} (depth {i}) with max_depth={max_depth} "
f"{'should show' if should_show else 'should not show'}:"
f"{generator._should_include_by_depth(node)}"
)
assert generator._should_include_by_depth(node) == should_show
assert generator._should_include_by_depth(node) == should_show, msg

0 comments on commit ca4f2df

Please sign in to comment.