Skip to content
Open
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
26 changes: 16 additions & 10 deletions walrus.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,15 @@ def predicate(filename: str) -> bool:
# Main Conversion Implementation

# walrus wrapper template

# NAME_TEMPLATE = '''\
# if False:
# %(indentation)s%(name_list)s = NotImplemented
# '''.splitlines() # `str.splitlines` will remove trailing newline
# make it Cython compilable
NAME_TEMPLATE = '''\
if False:
%(indentation)s%(name_list)s = NotImplemented
if '%(name)s' not in dir():
%(indentation)s%(name)s = NotImplemented
'''.splitlines() # `str.splitlines` will remove trailing newline
CALL_TEMPLATE = '_walrus_wrapper_%(name)s_%(uuid)s(%(expr)s)'
FUNC_TEMPLATE = '''\
Expand Down Expand Up @@ -1017,10 +1023,10 @@ def _concat(self) -> None:
else:
linesep = ''
if self._vars:
name_list = ' = '.join(sorted(set(self._vars)))
self._buffer += indent + (
'%s%s' % (self._linesep, indent)
).join(NAME_TEMPLATE) % dict(indentation=self._indentation, name_list=name_list) + self._linesep
for name in sorted(set(self._vars)):
self._buffer += indent + (
'%s%s' % (self._linesep, indent)
).join(NAME_TEMPLATE) % dict(indentation=self._indentation, name=name) + self._linesep
for func in sorted(self._func, key=lambda func: func['name']):
if self._buffer:
self._buffer += linesep
Expand Down Expand Up @@ -1205,10 +1211,10 @@ def _concat(self) -> None:
else:
linesep = ''
if self._vars:
name_list = ' = '.join(sorted(set(self._vars)))
self._buffer += indent + (
'%s%s' % (self._linesep, indent)
).join(NAME_TEMPLATE) % dict(indentation=self._indentation, name_list=name_list) + self._linesep
for name in sorted(set(self._vars)):
self._buffer += indent + (
'%s%s' % (self._linesep, indent)
).join(NAME_TEMPLATE) % dict(indentation=self._indentation, name=name) + self._linesep
for func in sorted(self._func, key=lambda func: func['name']):
if self._buffer:
self._buffer += linesep
Expand Down