File tree Expand file tree Collapse file tree 2 files changed +5
-17
lines changed
Expand file tree Collapse file tree 2 files changed +5
-17
lines changed Original file line number Diff line number Diff line change 22from msgpack ._version import version
33from msgpack .exceptions import *
44
5+ from collections import namedtuple
56
6- class ExtType (object ):
7- __slots__ = ('code' , 'data' )
87
9- def __init__ (self , code , data ):
8+ class ExtType (namedtuple ('ExtType' , 'code data' )):
9+ def __new__ (cls , code , data ):
1010 if not isinstance (code , int ):
1111 raise TypeError ("code must be int" )
1212 if not isinstance (data , bytes ):
1313 raise TypeError ("data must be bytes" )
1414 if not 0 <= code <= 127 :
1515 raise ValueError ("code must be 0~127" )
16- self .code = code
17- self .data = data
18-
19- def __eq__ (self , other ):
20- if not isinstance (other , ExtType ):
21- return NotImplemented
22- return self .code == other .code and self .data == other .data
23-
24- def __hash__ (self ):
25- return self .code ^ hash (self .data )
26-
27- def __repr__ (self ):
28- return "msgpack.ExtType(%r, %r)" % (self .code , self .data )
16+ return super (ExtType , cls ).__new__ (cls , code , data )
2917
3018
3119import os
Original file line number Diff line number Diff line change @@ -186,7 +186,7 @@ cdef class Packer(object):
186186 # This should be before Tuple because ExtType is namedtuple.
187187 longval = o.code
188188 rawval = o.data
189- L = len (o[ 1 ] )
189+ L = len (o.data )
190190 ret = msgpack_pack_ext(& self .pk, longval, L)
191191 ret = msgpack_pack_raw_body(& self .pk, rawval, L)
192192 elif PyTuple_Check(o) or PyList_Check(o):
You can’t perform that action at this time.
0 commit comments