File tree Expand file tree Collapse file tree 3 files changed +18
-3
lines changed
Expand file tree Collapse file tree 3 files changed +18
-3
lines changed Original file line number Diff line number Diff line change 11# Change Log
22
3+ [ Unreleased] :
4+
5+ ### Added
6+
7+ - Add ` .item() ` method to array and tables to retrieve an item by key. ([ #390 ] ( https://github.com/python-poetry/tomlkit/issues/390 ) )
8+
39## [ 0.13.2] - 2024-08-14
410
511### Fixed
Original file line number Diff line number Diff line change @@ -915,6 +915,8 @@ def test_booleans_comparison():
915915"""
916916
917917 content = parse (s )
918+ assert content ["foo" ]["value" ] is False
919+ assert isinstance (content ["foo" ].item ("value" ), Bool )
918920
919921 assert {"foo" : {"value" : False }} == content
920922 assert {"value" : False } == content ["foo" ]
Original file line number Diff line number Diff line change @@ -1313,10 +1313,14 @@ def clear(self) -> None:
13131313 def __len__ (self ) -> int :
13141314 return list .__len__ (self )
13151315
1316+ def item (self , index : int ) -> Item :
1317+ rv = list .__getitem__ (self , index )
1318+ return cast (Item , rv )
1319+
13161320 def __getitem__ (self , key : int | slice ) -> Any :
1317- rv = cast ( Item , list .__getitem__ (self , key ) )
1318- if rv . is_boolean ( ):
1319- return bool ( rv )
1321+ rv = list .__getitem__ (self , key )
1322+ if isinstance ( rv , Bool ):
1323+ return rv . value
13201324 return rv
13211325
13221326 def __setitem__ (self , key : int | slice , value : Any ) -> Any :
@@ -1479,6 +1483,9 @@ def remove(self: AT, key: Key | str) -> AT:
14791483
14801484 return self
14811485
1486+ def item (self , key : Key | str ) -> Item :
1487+ return self ._value .item (key )
1488+
14821489 def setdefault (self , key : Key | str , default : Any ) -> Any :
14831490 super ().setdefault (key , default )
14841491 return self [key ]
You can’t perform that action at this time.
0 commit comments