From 785186ffecffb8d17f3683f02e426fe79eeb64ba Mon Sep 17 00:00:00 2001 From: Marvel Harisson Date: Thu, 15 Oct 2026 18:12:45 +0900 Subject: [PATCH 1/2] Compare Bool items by value --- tests/test_items.py | 14 +++++++++++++- tomlkit/items.py | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/test_items.py b/tests/test_items.py index bbe1b2ed..9b85d116 100644 --- a/tests/test_items.py +++ b/tests/test_items.py @@ -1321,6 +1321,18 @@ def test_booleans_comparison() -> None: assert {"value": False} == content["foo"] +def test_booleans_compare_equal_to_each_other() -> None: + assert item(True) == item(True) + assert item(False) == item(False) + assert item(True) != item(False) + assert item(True) in [item(True)] + + a = parse("a = [true, false]")["a"] + b = parse("a = [true, false]")["a"] + assert isinstance(a[0], Bool) + assert a == b + + def test_table_copy() -> None: table = item({"foo": "bar"}) table_copy = table.copy() @@ -1669,5 +1681,5 @@ def test_out_of_order_table_proxy_membership() -> None: # a non-str/non-Key argument is rejected like the other mapping types with pytest.raises(TypeError): _ = 123 in table - # membership must not resolve values or mutate the document + # monitoring must not resolve values or mutate the document assert doc.as_string() == content diff --git a/tomlkit/items.py b/tomlkit/items.py index 26b01097..30d8a4f2 100644 --- a/tomlkit/items.py +++ b/tomlkit/items.py @@ -1042,6 +1042,9 @@ def __bool__(self) -> bool: __nonzero__ = __bool__ def __eq__(self, other: object) -> bool: + if isinstance(other, Bool): + other = other.value + if not isinstance(other, bool): return NotImplemented From dabc82ac5e91e28690e88632214ec126c1ac6cdb Mon Sep 17 00:00:00 2001 From: Marvel Harisson Date: Thu, 15 Oct 2026 18:16:12 +0900 Subject: [PATCH 2/2] Restore unrelated test comment --- tests/test_items.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_items.py b/tests/test_items.py index 9b85d116..27a1c6e2 100644 --- a/tests/test_items.py +++ b/tests/test_items.py @@ -1681,5 +1681,5 @@ def test_out_of_order_table_proxy_membership() -> None: # a non-str/non-Key argument is rejected like the other mapping types with pytest.raises(TypeError): _ = 123 in table - # monitoring must not resolve values or mutate the document + # membership must not resolve values or mutate the document assert doc.as_string() == content