forked from VimPlug/jedi
Extract: Fix param order for methods
This commit is contained in:
@@ -409,6 +409,7 @@ def extract_function(inference_state, path, module_context, name, pos, until_pos
|
|||||||
function_param_names = context.get_value().get_param_names()
|
function_param_names = context.get_value().get_param_names()
|
||||||
if len(function_param_names):
|
if len(function_param_names):
|
||||||
self_param = function_param_names[0].string_name
|
self_param = function_param_names[0].string_name
|
||||||
|
params = [p for p in params if p != self_param]
|
||||||
|
|
||||||
if function_is_classmethod(context.tree_node):
|
if function_is_classmethod(context.tree_node):
|
||||||
decorator = '@classmethod\n'
|
decorator = '@classmethod\n'
|
||||||
@@ -416,12 +417,15 @@ def extract_function(inference_state, path, module_context, name, pos, until_pos
|
|||||||
code_block += '\n'
|
code_block += '\n'
|
||||||
|
|
||||||
function_code = '%sdef %s(%s):\n%s' % (
|
function_code = '%sdef %s(%s):\n%s' % (
|
||||||
decorator, name, ', '.join(params), indent_block(code_block)
|
decorator,
|
||||||
|
name,
|
||||||
|
', '.join(params if self_param is None else [self_param] + params),
|
||||||
|
indent_block(code_block)
|
||||||
)
|
)
|
||||||
|
|
||||||
function_call = '%s(%s)' % (
|
function_call = '%s(%s)' % (
|
||||||
('' if self_param is None else self_param + '.') + name,
|
('' if self_param is None else self_param + '.') + name,
|
||||||
', '.join(p for p in params if p != self_param)
|
', '.join(params)
|
||||||
)
|
)
|
||||||
if is_expression:
|
if is_expression:
|
||||||
replacement = function_call
|
replacement = function_call
|
||||||
|
|||||||
@@ -82,6 +82,19 @@ class X:
|
|||||||
def f(self, b, c):
|
def f(self, b, c):
|
||||||
#? 11 text {'new_name': 'ab'}
|
#? 11 text {'new_name': 'ab'}
|
||||||
return self.ab(b)
|
return self.ab(b)
|
||||||
|
# -------------------------------------------------- in-method-order
|
||||||
|
class X:
|
||||||
|
def f(self, b, c):
|
||||||
|
#? 18 text {'new_name': 'b'}
|
||||||
|
return b | self.a
|
||||||
|
# ++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
class X:
|
||||||
|
def b(self, b):
|
||||||
|
return b | self.a
|
||||||
|
|
||||||
|
def f(self, b, c):
|
||||||
|
#? 18 text {'new_name': 'b'}
|
||||||
|
return self.b(b)
|
||||||
# -------------------------------------------------- in-classmethod-1
|
# -------------------------------------------------- in-classmethod-1
|
||||||
class X:
|
class X:
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -91,7 +104,7 @@ class X:
|
|||||||
# ++++++++++++++++++++++++++++++++++++++++++++++++++
|
# ++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
class X:
|
class X:
|
||||||
@classmethod
|
@classmethod
|
||||||
def ab():
|
def ab(x):
|
||||||
return 25
|
return 25
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
Reference in New Issue
Block a user