DRY x0ret's code a little bit.

This commit is contained in:
rocky
2019-06-05 20:14:04 -04:00
parent fd59879510
commit cb40caa73c
5 changed files with 45 additions and 42 deletions

View File

@@ -31,28 +31,31 @@ def customize_for_version26_27(self, version):
if version > 2.6:
TABLE_DIRECT.update({
'except_cond2': ( '%|except %c as %c:\n', 1, 5 ),
# When a generator is a single parameter of a function,
# it doesn't need the surrounding parenethesis.
'generator_no_parens': ('%c%P', 0, (1, -1, ', ', 100)),
})
else:
TABLE_DIRECT.update({
'testtrue_then': ( 'not %p', (0, 22) ),
})
def n_call(node):
mapping = self._get_mapping(node)
table = mapping[0]
key = node
for i in mapping[1:]:
key = key[i]
pass
if key.kind == 'CALL_FUNCTION_1':
# A function with one argument. If this is a generator,
# no parenthesis is needed.
args_node = node[-2]
if args_node == 'expr':
n = args_node[0]
if n == 'generator_exp':
template = ('%c%P', 0, (1, -1, ', ', 100))
self.template_engine(template, node)
self.prune()
node.kind = 'generator_no_parens'
pass
pass
self.default(node)
self.n_call = n_call