Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kafka/admin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@ def _describe_consumer_groups_process_response(self, response):
for response_field, response_name in zip(response.SCHEMA.fields, response.SCHEMA.names):
if isinstance(response_field, Array):
described_groups_field_schema = response_field.array_of
described_group = response.__dict__[response_name][0]
described_group = getattr(response, response_name)[0]
described_group_information_list = []
protocol_type_is_consumer = False
for (described_group_information, group_information_name, group_information_field) in zip(described_group, described_groups_field_schema.names, described_groups_field_schema.fields):
Expand Down
13 changes: 6 additions & 7 deletions kafka/protocol/struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class Struct(AbstractType):
def __init__(self, *args, **kwargs):
if len(args) == len(self.SCHEMA.fields):
for i, name in enumerate(self.SCHEMA.names):
self.__dict__[name] = args[i]
setattr(self, name, args[i])
elif len(args) > 0:
raise ValueError('Args must be empty or mirror schema')
else:
for name in self.SCHEMA.names:
self.__dict__[name] = kwargs.pop(name, None)
setattr(self, name, kwargs.pop(name, None))
if kwargs:
raise ValueError('Keyword(s) not in schema %s: %s'
% (list(self.SCHEMA.names),
Expand All @@ -30,7 +30,6 @@ def __init__(self, *args, **kwargs):
# causes instances to "leak" to garbage
self.encode = WeakMethod(self._encode_self)


@classmethod
def encode(cls, item): # pylint: disable=E0202
bits = []
Expand All @@ -40,7 +39,7 @@ def encode(cls, item): # pylint: disable=E0202

def _encode_self(self):
return self.SCHEMA.encode(
[self.__dict__[name] for name in self.SCHEMA.names]
[getattr(self, name) for name in self.SCHEMA.names]
)

@classmethod
Expand All @@ -52,12 +51,12 @@ def decode(cls, data):
def get_item(self, name):
if name not in self.SCHEMA.names:
raise KeyError("%s is not in the schema" % name)
return self.__dict__[name]
return getattr(self, name)

def __repr__(self):
key_vals = []
for name, field in zip(self.SCHEMA.names, self.SCHEMA.fields):
key_vals.append('%s=%s' % (name, field.repr(self.__dict__[name])))
key_vals.append('%s=%s' % (name, field.repr(getattr(self, name))))
return self.__class__.__name__ + '(' + ', '.join(key_vals) + ')'

def __hash__(self):
Expand All @@ -67,6 +66,6 @@ def __eq__(self, other):
if self.SCHEMA != other.SCHEMA:
return False
for attr in self.SCHEMA.names:
if self.__dict__[attr] != other.__dict__[attr]:
if getattr(self, attr) != getattr(other, attr):
return False
return True
5 changes: 2 additions & 3 deletions test/test_object_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class TestClass(superclass):
assert tc.get_item('myobject') == 0
with pytest.raises(KeyError):
tc.get_item('does-not-exist')

def test_with_empty_schema(self, superclass):
class TestClass(superclass):
API_KEY = 0
Expand Down Expand Up @@ -86,7 +86,7 @@ class TestClass(superclass):
('subobject', Int16),
('othersubobject', String('utf-8')))),
('notarray', Int16))

tc = TestClass(
myarray=[[10, 'hello']],
notarray=42
Expand Down Expand Up @@ -185,7 +185,6 @@ def test_with_metadata_response():
]]
)
tc.encode() # Make sure this object encodes successfully


obj = tc.to_object()

Expand Down
Loading