From 8976fe0c74d7778d0c540527fb59dababc567c38 Mon Sep 17 00:00:00 2001 From: Geethakrishna Puligundla Date: Fri, 10 Nov 2023 14:06:46 -0500 Subject: [PATCH 1/5] fix(API Checks): report the attribute who lost their value --- src/griffe/diff.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/griffe/diff.py b/src/griffe/diff.py index 7521f901..3a6d69b1 100644 --- a/src/griffe/diff.py +++ b/src/griffe/diff.py @@ -415,6 +415,8 @@ def _attribute_incompatibilities(old_attribute: Attribute, new_attribute: Attrib # if old_attribute.annotation is not None and new_attribute.annotation is not None: # if not is_subhint(new_attribute.annotation, old_attribute.annotation): if old_attribute.value != new_attribute.value: + if new_attribute.value is None: + new_attribute.value = "unset" yield AttributeChangedValueBreakage(new_attribute, old_attribute.value, new_attribute.value) From c1150605359e4c04c7f34c73ce85786435552a8c Mon Sep 17 00:00:00 2001 From: Geethakrishna Puligundla Date: Fri, 10 Nov 2023 14:27:24 -0500 Subject: [PATCH 2/5] fix(API Checks): passing unset in breakng instance instead of setting to attribute --- src/griffe/diff.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/griffe/diff.py b/src/griffe/diff.py index 3a6d69b1..52e445c8 100644 --- a/src/griffe/diff.py +++ b/src/griffe/diff.py @@ -416,7 +416,7 @@ def _attribute_incompatibilities(old_attribute: Attribute, new_attribute: Attrib # if not is_subhint(new_attribute.annotation, old_attribute.annotation): if old_attribute.value != new_attribute.value: if new_attribute.value is None: - new_attribute.value = "unset" + yield AttributeChangedValueBreakage(new_attribute, old_attribute.value, "unset") yield AttributeChangedValueBreakage(new_attribute, old_attribute.value, new_attribute.value) From 7a822e21e42ce8c8b1a3619aca3d6ee6518360a2 Mon Sep 17 00:00:00 2001 From: Geethakrishna Puligundla Date: Sat, 11 Nov 2023 10:11:55 -0500 Subject: [PATCH 3/5] fix(API Checks): moved into if else block --- src/griffe/diff.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/griffe/diff.py b/src/griffe/diff.py index 52e445c8..b36617de 100644 --- a/src/griffe/diff.py +++ b/src/griffe/diff.py @@ -417,7 +417,8 @@ def _attribute_incompatibilities(old_attribute: Attribute, new_attribute: Attrib if old_attribute.value != new_attribute.value: if new_attribute.value is None: yield AttributeChangedValueBreakage(new_attribute, old_attribute.value, "unset") - yield AttributeChangedValueBreakage(new_attribute, old_attribute.value, new_attribute.value) + else: + yield AttributeChangedValueBreakage(new_attribute, old_attribute.value, new_attribute.value) def _alias_incompatibilities( From c71ecb94b19b1cc4e4e100753e475dfff1a6d107 Mon Sep 17 00:00:00 2001 From: Geethakrishna Puligundla Date: Sat, 11 Nov 2023 10:41:46 -0500 Subject: [PATCH 4/5] fix(API Checks): added unit test --- tests/test_diff.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_diff.py b/tests/test_diff.py index 4d1f675f..bf0a8489 100644 --- a/tests/test_diff.py +++ b/tests/test_diff.py @@ -11,11 +11,6 @@ @pytest.mark.parametrize( ("old_code", "new_code", "expected_breakages"), [ - ( - "a = True", - "a = False", - [BreakageKind.ATTRIBUTE_CHANGED_VALUE], - ), ( "class a(int, str): ...", "class a(int): ...", @@ -154,6 +149,11 @@ "def a(x): ...", [BreakageKind.PARAMETER_REMOVED], ), + ( + "class a:\n\tb: int | None = None", + "class a:\n\tb: int", + [BreakageKind.ATTRIBUTE_CHANGED_VALUE], + ), ( "def a() -> int: ...", "def a() -> str: ...", From f40d7a28f724697e764c9179a2d2ed7f8ae0e527 Mon Sep 17 00:00:00 2001 From: Geethakrishna Puligundla Date: Sat, 11 Nov 2023 10:44:33 -0500 Subject: [PATCH 5/5] fix(API Checks): fixed typo --- tests/test_diff.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/test_diff.py b/tests/test_diff.py index bf0a8489..c1663a31 100644 --- a/tests/test_diff.py +++ b/tests/test_diff.py @@ -11,6 +11,11 @@ @pytest.mark.parametrize( ("old_code", "new_code", "expected_breakages"), [ + ( + "a = True", + "a = False", + [BreakageKind.ATTRIBUTE_CHANGED_VALUE], + ), ( "class a(int, str): ...", "class a(int): ...",