Skip to content

Commit 18e7f98

Browse files
authored
Compare Bool items by value (#660)
* Compare Bool items by value * Restore unrelated test comment
1 parent 19edc23 commit 18e7f98

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

‎tests/test_items.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,6 +1321,18 @@ def test_booleans_comparison() -> None:
13211321
assert {"value": False} == content["foo"]
13221322

13231323

1324+
def test_booleans_compare_equal_to_each_other() -> None:
1325+
assert item(True) == item(True)
1326+
assert item(False) == item(False)
1327+
assert item(True) != item(False)
1328+
assert item(True) in [item(True)]
1329+
1330+
a = parse("a = [true, false]")["a"]
1331+
b = parse("a = [true, false]")["a"]
1332+
assert isinstance(a[0], Bool)
1333+
assert a == b
1334+
1335+
13241336
def test_table_copy() -> None:
13251337
table = item({"foo": "bar"})
13261338
table_copy = table.copy()

‎tomlkit/items.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,9 @@ def __bool__(self) -> bool:
10421042
__nonzero__ = __bool__
10431043

10441044
def __eq__(self, other: object) -> bool:
1045+
if isinstance(other, Bool):
1046+
other = other.value
1047+
10451048
if not isinstance(other, bool):
10461049
return NotImplemented
10471050

0 commit comments

Comments
 (0)