mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 06:44:46 +08:00
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()
|
||||
if len(function_param_names):
|
||||
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):
|
||||
decorator = '@classmethod\n'
|
||||
@@ -416,12 +417,15 @@ def extract_function(inference_state, path, module_context, name, pos, until_pos
|
||||
code_block += '\n'
|
||||
|
||||
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)' % (
|
||||
('' if self_param is None else self_param + '.') + name,
|
||||
', '.join(p for p in params if p != self_param)
|
||||
', '.join(params)
|
||||
)
|
||||
if is_expression:
|
||||
replacement = function_call
|
||||
|
||||
@@ -82,6 +82,19 @@ class X:
|
||||
def f(self, b, c):
|
||||
#? 11 text {'new_name': 'ab'}
|
||||
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
|
||||
class X:
|
||||
@classmethod
|
||||
@@ -91,7 +104,7 @@ class X:
|
||||
# ++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
class X:
|
||||
@classmethod
|
||||
def ab():
|
||||
def ab(x):
|
||||
return 25
|
||||
|
||||
@classmethod
|
||||
|
||||
Reference in New Issue
Block a user