Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3f70337

Browse files
author
raubcameo@gmail.com
committedAug 1, 2023
fixed missing expression2str in cdef and cpdef
1 parent ed28ac3 commit 3f70337

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed
 

‎cython_peg.py‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,9 @@ def Cython2PythonType(cython_type: str) -> str:
158158
def expression2str(expression: Union[ParseResults, str]):
159159
"""EXPRESSION parsed tree to string"""
160160

161-
expression_string = ""
162-
163161
if isinstance(expression, ParseResults):
164-
162+
expression_string = ""
163+
165164
if expression.getName() == 'list':
166165
expression_string += "[" + ', '.join(expression2str(e) for e in expression) + "]"
167166

@@ -174,14 +173,14 @@ def expression2str(expression: Union[ParseResults, str]):
174173
elif expression.getName() == 'dict':
175174
expression_string += "{" + ', '.join(f"{expression2str(k)} : {expression2str(v)}" for k, v in expression) + "}"
176175

177-
elif isinstance(expression, ParseResults):
176+
else:
178177
for e in expression:
179178
expression_string += expression2str(e)
179+
180+
return expression_string
180181

181-
if isinstance(expression, str):
182+
elif isinstance(expression, str):
182183
return expression
183-
184-
return expression_string
185184

186185
def type2str(type_tree: ParseResults):
187186
"""type_definition parsed tree to string"""
@@ -242,7 +241,7 @@ def format_arg(arg):
242241
if arg[0] == "self": return "self" # handle unique case cdef inside class
243242
t, n, d = arg
244243
type_str = type2str(t)
245-
default_str = f' = {d}' if d else ''
244+
default_str = f' = {expression2str(d)}' if d else ''
246245
return f'{n}: {type_str}{default_str}'
247246

248247
joiner = f',\n{INDENT}' if newlines else ', '

0 commit comments

Comments
 (0)
Please sign in to comment.