File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -521,10 +521,11 @@ def _unpack(self, execute=EX_CONSTRUCT):
521521 ret = newlist_hint (n )
522522 for i in range (n ):
523523 ret .append (self ._unpack (EX_CONSTRUCT ))
524+ if not self ._use_list :
525+ ret = tuple (ret )
524526 if self ._list_hook is not None :
525527 ret = self ._list_hook (ret )
526- # TODO is the interaction between `list_hook` and `use_list` ok?
527- return ret if self ._use_list else tuple (ret )
528+ return ret
528529 if typ == TYPE_MAP :
529530 if execute == EX_SKIP :
530531 for i in range (n ):
Original file line number Diff line number Diff line change 11#!/usr/bin/env python
22
3+ from io import BytesIO
4+
35from pytest import raises
46
5- from msgpack import packb , unpackb
7+ from msgpack import Unpacker , packb , unpackb
68
79
810def _decode_complex (obj ):
@@ -74,6 +76,29 @@ def test_array_hook():
7476 assert unpacked == "123"
7577
7678
79+ def test_array_hook_with_use_list_false ():
80+ seen = []
81+
82+ def hook (items ):
83+ seen .append (items )
84+ return {"items" : items }
85+
86+ packed = packb ([1 , 2 ])
87+ expected = {"items" : (1 , 2 )}
88+ assert unpackb (packed , use_list = False , list_hook = hook ) == expected
89+
90+ stream = packed + packb (3 )
91+ unpackers = [
92+ Unpacker (use_list = False , list_hook = hook ),
93+ Unpacker (BytesIO (stream ), use_list = False , list_hook = hook ),
94+ ]
95+ unpackers [0 ].feed (stream )
96+ for unpacker in unpackers :
97+ assert unpacker .unpack () == expected
98+ assert unpacker .unpack () == 3
99+ assert seen == [(1 , 2 )] * 3
100+
101+
77102class DecodeError (Exception ):
78103 pass
79104
You can’t perform that action at this time.
0 commit comments