Skip to content

Commit

Permalink
Fix #567. Add posonlyargs to list of written arguments when extracting
Browse files Browse the repository at this point in the history
  • Loading branch information
lieryan committed Dec 14, 2022
1 parent 5fb5359 commit fcbd54c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion rope/refactor/extract.py
Expand Up @@ -947,7 +947,10 @@ def _handle_loop_context(self, node):


def _get_argnames(arguments):
result = [node.arg for node in arguments.args if isinstance(node, ast.arg)]
result = []
if arguments.posonlyargs:
result.extend(node.arg for node in arguments.posonlyargs)
result.extend(node.arg for node in arguments.args if isinstance(node, ast.arg))
if arguments.vararg:
result.append(arguments.vararg.arg)
if arguments.kwarg:
Expand Down
18 changes: 18 additions & 0 deletions ropetest/refactor/extracttest.py
Expand Up @@ -222,6 +222,24 @@ def new_func(a_var, another_var):
""")
self.assertEqual(expected, refactored)

def test_extract_function_with_posonlyargs(self):
code = dedent("""\
def a_func(a_var, /, b):
another_var = 20
third_var = a_var + another_var
""")
start, end = self._convert_line_range_to_offset(code, 3, 3)
refactored = self.do_extract_method(code, start, end, "new_func")
expected = dedent("""\
def a_func(a_var, /, b):
another_var = 20
new_func(a_var, another_var)
def new_func(a_var, another_var):
third_var = a_var + another_var
""")
self.assertEqual(expected, refactored)

def test_extract_function_with_multiple_return_values(self):
code = dedent("""\
def a_func():
Expand Down

0 comments on commit fcbd54c

Please sign in to comment.