Commits

Anonymous committed 8f9fe12

patchedast: Fixed when both varargs and kwargs exist

Comments (0)

Files changed (3)

docs/dev/workingon.txt

 Small Stories
 =============
 
+* Better tests in `patchedasttest`
 * Remove ``docs/dev/workingon.txt``?
 * Add ``docs/dev/rope_py3k.txt``?
+* Add `Core.add_extension('rope.ui.helpactions')`?
 
 * Change ``contributing.txt`` to separate rope and ropeide goals
 * Splitting history for being faster?

rope/refactor/patchedast.py

                 children.append(',')
             children.extend(['*', node.starargs])
         if node.kwargs is not None:
-            if args:
+            if args or node.starargs is not None:
                 children.append(',')
             children.extend(['**', node.kwargs])
         children.append(')')
     def _arguments(self, node):
         children = []
         args = list(node.args)
-        star_args = node.vararg
-        dstar_args = node.kwarg
         defaults = [None] * (len(args) - len(node.defaults)) + list(node.defaults)
         for index, (arg, default) in enumerate(zip(args, defaults)):
             if index > 0:
                 children.append(',')
             self._add_args_to_children(children, arg, default)
-        if star_args is not None:
+        if node.vararg is not None:
             if args:
                 children.append(',')
-            children.extend(['*', star_args])
-        if dstar_args is not None:
-            if args:
+            children.extend(['*', node.vararg])
+        if node.kwarg is not None:
+            if args or node.vararg is not None:
                 children.append(',')
-            children.extend(['**', dstar_args])
+            children.extend(['**', node.kwarg])
         self._handle(node, children)
 
     def _add_args_to_children(self, children, arg, default):

ropetest/refactor/patchedasttest.py

         checker.check_children(
             'Call', ['Name', '', '(', '', '**', '', 'Name', '', ')'])
 
+    def test_call_func_and_both_varargs_and_kwargs(self):
+        source = 'f(*args, **kwds)\n'
+        ast = patchedast.get_patched_ast(source, True)
+        checker = _ResultChecker(self, ast)
+        checker.check_children(
+            'Call', ['Name', '', '(', '', '*', '', 'Name', '', ',',
+                     ' ', '**', '', 'Name', '', ')'])
+
     def test_class_node(self):
         source = 'class A(object):\n    """class docs"""\n    pass\n'
         ast = patchedast.get_patched_ast(source, True)
             ['@', '', 'Name', '\n', 'def', ' ', 'f', '', '(', '', 'arguments',
              '', ')', '', ':', '\n    ', 'Pass'])
 
+    def test_both_varargs_and_kwargs(self):
+        source = 'def f(*args, **kwds):\n    pass\n'
+        ast = patchedast.get_patched_ast(source, True)
+        checker = _ResultChecker(self, ast)
+        checker.check_children(
+            'arguments', ['*', '', 'args' , '', ',' , ' ', '**', '', 'kwds'])
+
     def test_function_node(self):
         source = 'def f():\n    pass\n'
         ast = patchedast.get_patched_ast(source, True)