Skip to content

Commit 42078e3

Browse files
committed
drop fields kwarg
1 parent 4614ee2 commit 42078e3

4 files changed

Lines changed: 23 additions & 24 deletions

File tree

kafka/protocol/new/api_array.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77

88
class ApiArray(Field):
99
@classmethod
10-
def parse_json(cls, json, fields=None):
10+
def parse_json(cls, json):
1111
if json['type'].startswith('[]'):
1212
inner_type_str = json['type'][2:]
1313
if inner_type_str.startswith('[]'): # this would be strange...
1414
return None
1515
inner_json = {**json, 'type': inner_type_str}
16-
inner_type = super().parse_json(inner_json, fields=fields)
16+
inner_type = super().parse_json(inner_json)
1717
if inner_type is not None:
18-
return cls(json, fields=fields, array_of=inner_type)
18+
return cls(json, array_of=inner_type)
1919

20-
def __init__(self, json, fields=None, array_of=None):
21-
super().__init__(json, fields=fields)
20+
def __init__(self, json, array_of=None):
21+
super().__init__(json)
2222
self.array_of = array_of # Field (ApiStruct or FieldBasicType)
2323

2424
def is_array(self):

kafka/protocol/new/api_struct.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88

99
class ApiStruct(Field):
1010
@classmethod
11-
def parse_json(cls, json, fields=None):
11+
def parse_json(cls, json):
1212
if json['type'] in ('request', 'response', 'header') or json['type'][0].isupper():
13-
if fields is not None or json.get('fields') is not None:
14-
return cls(json, fields=fields)
13+
if 'fields' in json:
14+
return cls(json)
1515

1616
# Cases
1717
# oldschool - standard types, no tagged fields
1818
# newschool - compact types, tagged fields
1919
# nested tag - compact types, no (nested) tagged fields
20-
def __init__(self, json, fields=None):
21-
super().__init__(json, fields=fields)
20+
def __init__(self, json):
21+
super().__init__(json)
2222
self._field_map = {field.name: field for field in self._fields if field is not None}
2323
self._data_class = None
2424

kafka/protocol/new/field.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@ def parse_json_fields(cls, json):
1212
return tuple(map(Field.parse_json, json.get('fields', []))) or None # Note: DFS Field construction
1313

1414
@classmethod
15-
def parse_json(cls, json, fields=None):
15+
def parse_json(cls, json):
1616
if 'type' not in json:
1717
raise ValueError('No type found in json')
1818
type_str = json['type']
19-
if fields is None and json.get('fields') is not None:
20-
fields = cls.parse_json_fields(json)
2119
for field_type in cls.FIELD_TYPES:
22-
maybe_type = field_type.parse_json(json, fields=fields)
20+
maybe_type = field_type.parse_json(json)
2321
if maybe_type is not None:
2422
return maybe_type
2523
else:
@@ -42,7 +40,7 @@ def parse_versions(cls, versions):
4240
else:
4341
return tuple(map(int, versions.split('-')))
4442

45-
def __init__(self, json, fields=None):
43+
def __init__(self, json):
4644
self._json = json
4745
self._name = json['name']
4846
# versions tells when to include the field in encode / decode
@@ -63,9 +61,10 @@ def __init__(self, json, fields=None):
6361
self._flexible_versions = self.parse_versions(json.get('flexibleVersions'))
6462
self._nullable_versions = self.parse_versions(json.get('nullableVersions'))
6563
self._type_str = json['type']
66-
if fields is None and json.get('fields') is not None:
67-
fields = self.parse_json_fields(json)
68-
self._fields = fields
64+
if 'fields' in json:
65+
self._fields = self.parse_json_fields(json)
66+
else:
67+
self._fields = None
6968
self._ignorable = json.get('ignorable')
7069
self._entity_type = json.get('entityType')
7170
self._about = json.get('about', '')

kafka/protocol/new/field_basic.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ class FieldBasicType(Field):
2525
}
2626

2727
@classmethod
28-
def parse_json(cls, json, fields=None):
29-
if fields is None and json['type'] in cls.TYPES:
28+
def parse_json(cls, json):
29+
if 'fields' not in json and json['type'] in cls.TYPES:
3030
return cls(json)
3131

32-
def __init__(self, json, fields=None):
33-
if fields is not None or json.get('fields') is not None:
34-
raise ValueError('Non-empty fields not allowed in FieldBasicType!')
35-
super().__init__(json, fields=None)
32+
def __init__(self, json):
33+
if 'fields' in json:
34+
raise ValueError('Fields not allowed in FieldBasicType!')
35+
super().__init__(json)
3636
if self._type_str not in self.TYPES:
3737
raise ValueError('Unrecognized type: %s' % self._type_str)
3838
self._type = self.TYPES[self._type_str]

0 commit comments

Comments
 (0)