File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed
Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change 1414from tomlkit import parse
1515from tomlkit ._compat import PY2
1616from tomlkit .exceptions import NonExistentKey
17+ from tomlkit .items import Bool
1718from tomlkit .items import InlineTable
1819from tomlkit .items import Integer
1920from tomlkit .items import Key
@@ -450,3 +451,22 @@ def test_deleting_inline_table_elemeent_does_not_leave_trailing_separator():
450451 table ["baz" ] = "boom"
451452
452453 assert '{baz = "boom"}' == table .as_string ()
454+
455+
456+ def test_booleans_comparison ():
457+ boolean = Bool (True , Trivia ())
458+
459+ assert boolean
460+
461+ boolean = Bool (False , Trivia ())
462+
463+ assert not boolean
464+
465+ s = """[foo]
466+ value = false
467+ """
468+
469+ content = parse (s )
470+
471+ assert {"foo" : {"value" : False }} == content
472+ assert {"value" : False } == content ["foo" ]
Original file line number Diff line number Diff line change @@ -496,7 +496,7 @@ class Bool(Item):
496496 A boolean literal.
497497 """
498498
499- def __init__ (self , t , trivia ): # type: (float , Trivia) -> None
499+ def __init__ (self , t , trivia ): # type: (int , Trivia) -> None
500500 super (Bool , self ).__init__ (trivia )
501501
502502 self ._value = bool (t )
@@ -515,6 +515,17 @@ def as_string(self): # type: () -> str
515515 def _getstate (self , protocol = 3 ):
516516 return self ._value , self ._trivia
517517
518+ def __bool__ (self ):
519+ return self ._value
520+
521+ __nonzero__ = __bool__
522+
523+ def __eq__ (self , other ):
524+ if not isinstance (other , bool ):
525+ return NotImplemented
526+
527+ return other == self ._value
528+
518529
519530class DateTime (Item , datetime ):
520531 """
You can’t perform that action at this time.
0 commit comments