From 1c4340b09b111313a5a242caa986a2fa3fdef852 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Fri, 1 Sep 2023 16:36:28 +0200 Subject: [PATCH] fix: Use all members (declared and inherited) when checking for breakages, avoid false-positives when a member of a class is moved into a parent class Issue #203: https://github.com/mkdocstrings/griffe/issues/203 --- src/griffe/diff.py | 4 ++-- tests/test_diff.py | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/griffe/diff.py b/src/griffe/diff.py index bcea8bac..293883b6 100644 --- a/src/griffe/diff.py +++ b/src/griffe/diff.py @@ -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): diff --git a/tests/test_diff.py b/tests/test_diff.py index eaeebecd..4d1f675f 100644 --- a/tests/test_diff.py +++ b/tests/test_diff.py @@ -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))