Small tweaks to last commit

This commit is contained in:
rocky
2019-05-10 17:25:25 -04:00
parent d97509495e
commit c03b039714
3 changed files with 30 additions and 6 deletions

View File

@@ -1,6 +1,6 @@
# From #227
# Bug was not handling call_ex_kw correctly
# THis appears in
# This appears in
# showparams(c, test="A", **extra_args)
# below
@@ -10,4 +10,28 @@ def showparams(c, test, **extra_args):
def f(c, **extra_args):
return showparams(c, test="A", **extra_args)
def f1(c, d, **extra_args):
return showparams(c, test="B", **extra_args)
def f2(**extra_args):
return showparams(1, test="C", **extra_args)
assert f(1, a=2, b=3) == {'c': 1, 'a': 2, 'b': 3, 'test': 'A'}
a = {'param1': 2}
assert f1('2', '{\'test\': "4"}', test2='a', **a) \
== {'c': '2', 'test2': 'a', 'param1': 2, 'test': 'B'}
assert f1(2, '"3"', test2='a', **a) \
== {'c': 2, 'test2': 'a', 'param1': 2, 'test': 'B'}
assert f1(False, '"3"', test2='a', **a) \
== {'c': False, 'test2': 'a', 'param1': 2, 'test': 'B'}
assert f(2, test2='A', **a) \
== {'c': 2, 'test2': 'A', 'param1': 2, 'test': 'A'}
assert f(str(2) + str(1), test2='a', **a) \
== {'c': '21', 'test2': 'a', 'param1': 2, 'test': 'A'}
assert f1((a.get('a'), a.get('b')), a, test3='A', **a) \
== {'c': (None, None), 'test3': 'A', 'param1': 2, 'test': 'B'}
b = {'b1': 1, 'b2': 2}
assert f2(**a, **b) == \
{'c': 1, 'param1': 2, 'b1': 1, 'b2': 2, 'test': 'C'}

View File

@@ -128,22 +128,22 @@ def customize_for_version36(self, version):
expr = node[1]
assert expr == 'expr'
value = self.traverse(expr, indent='')
if value.startswith('('):
value = value[1:-1].rstrip(" ") # Remove starting '(' and trailing ')' and additional spaces
if value == '':
fmt = "%%c(%%p)" % () # args is empty
if value == '':
fmt = "%c(%p)" # args is empty
else:
if value.endswith(','): # if args has only one item
value = value[:-1]
fmt = "%%c(%s, %%p)" % value
else:
fmt = "%%c(%s, %%p)" % value
self.template_engine(
(fmt,
(0, 'expr'), (2, 'build_map_unpack_with_call', 100)), node)
self.prune()
self.n_call_ex_kw = call_ex_kw