File tree 2 files changed +26
-2
lines changed
2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -174,14 +174,19 @@ def __init__(self, stream):
174
174
super ().__init__ (stream )
175
175
self .finish_char = "}"
176
176
self .start_char = "{"
177
+ self .active_child_key = None
177
178
178
179
def __getitem__ (self , key ):
180
+ if self .active_child and self .active_child_key == key :
181
+ return self .active_child
182
+
179
183
self .has_read = True
180
184
181
185
if self .active_child :
182
186
self .active_child .finish ()
183
187
self .done = self .data .fast_forward ("," )
184
188
self .active_child = None
189
+ self .active_child_key = None
185
190
if self .done :
186
191
raise KeyError (key )
187
192
@@ -196,6 +201,7 @@ def __getitem__(self, key):
196
201
self .done = True
197
202
if isinstance (next_value , Transient ):
198
203
self .active_child = next_value
204
+ self .active_child_key = key
199
205
return next_value
200
206
self .done = self .data .fast_forward ("," )
201
207
raise KeyError (key )
Original file line number Diff line number Diff line change @@ -481,8 +481,8 @@ def test_as_object_that_is_partially_read_raises(complex_dict):
481
481
dict_1 .as_object ()
482
482
483
483
484
- def test_as_object_grabbing_multiple_subscriptable_levels_twice_raises (complex_dict ):
485
- """Test loading a complex dict and grabbing multiple subscriptable levels twice raises ."""
484
+ def test_as_object_grabbing_multiple_subscriptable_levels_twice (complex_dict ):
485
+ """Test loading a complex dict and grabbing multiple subscriptable levels twice."""
486
486
487
487
assert json .loads (complex_dict )
488
488
@@ -491,5 +491,23 @@ def test_as_object_grabbing_multiple_subscriptable_levels_twice_raises(complex_d
491
491
list_1 = stream ["list_1" ]
492
492
dict_1 = next (list_1 )
493
493
assert dict_1 ["sub_dict" ]["sub_dict_id" ] == 1.1
494
+ assert dict_1 ["sub_dict" ]["sub_dict_name" ] == "one point one"
495
+
496
+
497
+ def test_as_object_grabbing_multiple_subscriptable_levels_again_after_passed_raises (
498
+ complex_dict ,
499
+ ):
500
+ """
501
+ Test loading a complex dict and grabbing multiple subscriptable levels after passing it raises.
502
+ """
503
+
504
+ assert json .loads (complex_dict )
505
+
506
+ stream = adafruit_json_stream .load (BytesChunkIO (complex_dict .encode ()))
507
+
508
+ list_1 = stream ["list_1" ]
509
+ dict_1 = next (list_1 )
510
+ assert dict_1 ["sub_dict" ]["sub_dict_id" ] == 1.1
511
+ assert next (dict_1 ["sub_list" ]) == "a"
494
512
with pytest .raises (KeyError , match = "sub_dict" ):
495
513
dict_1 ["sub_dict" ]["sub_dict_name" ]
You can’t perform that action at this time.
0 commit comments