Skip to content

Commit 80c352f

Browse files
committed
Fix sonar issues in protocol code generator
1 parent 4c86055 commit 80c352f

File tree

4 files changed

+11
-13
lines changed

4 files changed

+11
-13
lines changed

protocol_code_generator/generate/code_block.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ def __bool__(self):
104104
def to_string(self, package_path):
105105
result = ""
106106

107-
relativize = lambda i: i.relativize(package_path)
108-
import_strings = set(map(relativize, self._imports))
107+
import_strings = {i.relativize(package_path) for i in self._imports}
109108
import_strings = sorted(import_strings, reverse=True)
110109

111110
for import_ in import_strings:

protocol_code_generator/generate/field_code_generator.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -548,17 +548,15 @@ def _check_field_accessible(self, field):
548548

549549
def _get_serialize_length_expression(self):
550550
expression = self._length_string
551-
if expression is not None:
552-
if not expression.isdigit():
553-
self._check_field_accessible(expression)
554-
expression = f'data._{expression}'
551+
if expression is not None and not expression.isdigit():
552+
self._check_field_accessible(expression)
553+
expression = f'data._{expression}'
555554
return expression
556555

557556
def _get_deserialize_length_expression(self):
558557
expression = self._length_string
559-
if expression is not None:
560-
if not expression.isdigit():
561-
self._check_field_accessible(expression)
558+
if expression is not None and not expression.isdigit():
559+
self._check_field_accessible(expression)
562560
return expression
563561

564562
@staticmethod

protocol_code_generator/generate/object_code_generator.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def code(self):
129129
return result
130130

131131
def _generate_init_method(self):
132-
result = CodeBlock().add(f'def __init__(self')
132+
result = CodeBlock().add('def __init__(self')
133133
if self._data.init_params:
134134
result.add(', *')
135135
for param in self._data.init_params:
@@ -238,12 +238,13 @@ def _generate_deserialize_method(self):
238238

239239
def _generate_repr_method(self):
240240
field_to_repr_str = lambda field: field + "={repr(self._" + field + ")}"
241-
repr_str = ', '.join(map(field_to_repr_str, self._data.repr_fields))
241+
repr_field_strs = [field_to_repr_str(field) for field in self._data.repr_fields]
242+
repr_expression = 'f"' + self._class_name + '(' + ', '.join(repr_field_strs) + ')"'
242243
return (
243244
CodeBlock()
244245
.add_line('def __repr__(self):')
245246
.indent()
246-
.add_line(f'return f"{self._class_name}({repr_str})"')
247+
.add_line(f'return {repr_expression}')
247248
.unindent()
248249
)
249250

protocol_code_generator/util/docstring_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from protocol_code_generator.generate.code_block import CodeBlock
44

55

6-
def generate_docstring(protocol_comment, notes=[]):
6+
def generate_docstring(protocol_comment):
77
lines = []
88

99
if protocol_comment:

0 commit comments

Comments
 (0)