@@ -14,12 +14,12 @@ class Struct(AbstractType):
14
14
def __init__ (self , * args , ** kwargs ):
15
15
if len (args ) == len (self .SCHEMA .fields ):
16
16
for i , name in enumerate (self .SCHEMA .names ):
17
- self . __dict__ [ name ] = args [i ]
17
+ setattr ( self , name , args [i ])
18
18
elif len (args ) > 0 :
19
19
raise ValueError ('Args must be empty or mirror schema' )
20
20
else :
21
21
for name in self .SCHEMA .names :
22
- self . __dict__ [ name ] = kwargs .pop (name , None )
22
+ setattr ( self , name , kwargs .pop (name , None ) )
23
23
if kwargs :
24
24
raise ValueError ('Keyword(s) not in schema %s: %s'
25
25
% (list (self .SCHEMA .names ),
@@ -30,7 +30,6 @@ def __init__(self, *args, **kwargs):
30
30
# causes instances to "leak" to garbage
31
31
self .encode = WeakMethod (self ._encode_self )
32
32
33
-
34
33
@classmethod
35
34
def encode (cls , item ): # pylint: disable=E0202
36
35
bits = []
@@ -40,7 +39,7 @@ def encode(cls, item): # pylint: disable=E0202
40
39
41
40
def _encode_self (self ):
42
41
return self .SCHEMA .encode (
43
- [self . __dict__ [ name ] for name in self .SCHEMA .names ]
42
+ [getattr ( self , name ) for name in self .SCHEMA .names ]
44
43
)
45
44
46
45
@classmethod
@@ -52,12 +51,12 @@ def decode(cls, data):
52
51
def get_item (self , name ):
53
52
if name not in self .SCHEMA .names :
54
53
raise KeyError ("%s is not in the schema" % name )
55
- return self . __dict__ [ name ]
54
+ return getattr ( self , name )
56
55
57
56
def __repr__ (self ):
58
57
key_vals = []
59
58
for name , field in zip (self .SCHEMA .names , self .SCHEMA .fields ):
60
- key_vals .append ('%s=%s' % (name , field .repr (self . __dict__ [ name ] )))
59
+ key_vals .append ('%s=%s' % (name , field .repr (getattr ( self , name ) )))
61
60
return self .__class__ .__name__ + '(' + ', ' .join (key_vals ) + ')'
62
61
63
62
def __hash__ (self ):
@@ -67,6 +66,6 @@ def __eq__(self, other):
67
66
if self .SCHEMA != other .SCHEMA :
68
67
return False
69
68
for attr in self .SCHEMA .names :
70
- if self . __dict__ [ attr ] != other . __dict__ [ attr ] :
69
+ if getattr ( self , attr ) != getattr ( other , attr ) :
71
70
return False
72
71
return True
0 commit comments