Skip to content

Commit

Permalink
[py] Fix python generation code for CDP to optionals better
Browse files Browse the repository at this point in the history
  • Loading branch information
AutomatedTester committed Oct 8, 2021
1 parent 6c6a72c commit d46dd32
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion py/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,9 +631,18 @@ def generate_code(self):
code += f'def {self.py_name}('
ret = f') -> {ret_type}:\n'
if self.parameters:
params = [p.generate_code() for p in self.parameters]
optional = False
clean_params = []
for para in params:
if "= None" in para:
optional = True
if optional and "= None" not in para:
para += ' = None'
clean_params.append(para)
code += '\n'
code += indent(
',\n'.join(p.generate_code() for p in self.parameters), 8)
',\n'.join(clean_params), 8)
code += '\n'
code += indent(ret, 4)
else:
Expand Down

0 comments on commit d46dd32

Please sign in to comment.