Skip to content

Commit

Permalink
fix: Use all members (declared and inherited) when checking for break…
Browse files Browse the repository at this point in the history
…ages, avoid false-positives when a member of a class is moved into a parent class

Issue #203: #203
  • Loading branch information
pawamoy committed Sep 1, 2023
1 parent 3957fa7 commit 1c4340b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/griffe/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,14 +446,14 @@ def _member_incompatibilities(
seen_paths: set[str] | None = None,
) -> Iterator[Breakage]:
seen_paths = set() if seen_paths is None else seen_paths
for name, old_member in old_obj.members.items():
for name, old_member in old_obj.all_members.items():
if ignore_private and name.startswith("_"):
logger.debug(f"API check: {old_obj.path}.{name}: skip private object")
continue

logger.debug(f"API check: {old_obj.path}.{name}")
try:
new_member = new_obj.members[name]
new_member = new_obj.all_members[name]
except KeyError:
is_module = not old_member.is_alias and old_member.is_module
if is_module or old_member.is_exported(explicitely=False):
Expand Down
22 changes: 22 additions & 0 deletions tests/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,25 @@ def test_diff_griffe(old_code: str, new_code: str, expected_breakages: list[Brea
assert len(breaking) == len(expected_breakages)
for breakage, expected_kind in zip(breaking, expected_breakages):
assert breakage.kind is expected_kind


def test_moving_members_in_parent_classes() -> None:
"""Test that moving an object from a base class to a parent class doesn't trigger a breakage."""
old_code = """
class Parent:
...
class Base(Parent):
def method(self):
...
"""
new_code = """
class Parent:
def method(self):
...
class Base(Parent):
...
"""
with temporary_visited_module(old_code) as old_package, temporary_visited_module(new_code) as new_package:
assert not list(find_breaking_changes(old_package, new_package))

0 comments on commit 1c4340b

Please sign in to comment.