mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
Made 'l' a string + added warning
One of the helper methods is missing, so be extra careful.
This commit is contained in:
committed by
Dave Halter
parent
03961bf051
commit
ad5ac8c492
@@ -104,11 +104,12 @@ def extract(script, new_name):
|
|||||||
|
|
||||||
user_stmt = script._parser.user_stmt()
|
user_stmt = script._parser.user_stmt()
|
||||||
|
|
||||||
# TODO care for multiline extracts
|
# TODO care for multi-line extracts
|
||||||
dct = {}
|
dct = {}
|
||||||
if user_stmt:
|
if user_stmt:
|
||||||
pos = script._pos
|
pos = script._pos
|
||||||
line_index = pos[0] - 1
|
line_index = pos[0] - 1
|
||||||
|
# Be careful here. 'array_for_pos' does not exist in 'helpers'.
|
||||||
arr, index = helpers.array_for_pos(user_stmt, pos)
|
arr, index = helpers.array_for_pos(user_stmt, pos)
|
||||||
if arr is not None:
|
if arr is not None:
|
||||||
start_pos = arr[index].start_pos
|
start_pos = arr[index].start_pos
|
||||||
@@ -119,7 +120,7 @@ def extract(script, new_name):
|
|||||||
start_line = new_lines[start_pos[0] - 1]
|
start_line = new_lines[start_pos[0] - 1]
|
||||||
text = start_line[start_pos[1]:e]
|
text = start_line[start_pos[1]:e]
|
||||||
for l in range(start_pos[0], end_pos[0] - 1):
|
for l in range(start_pos[0], end_pos[0] - 1):
|
||||||
text += '\n' + l
|
text += '\n' + str(l)
|
||||||
if e is None:
|
if e is None:
|
||||||
end_line = new_lines[end_pos[0] - 1]
|
end_line = new_lines[end_pos[0] - 1]
|
||||||
text += '\n' + end_line[:end_pos[1]]
|
text += '\n' + end_line[:end_pos[1]]
|
||||||
@@ -139,7 +140,7 @@ def extract(script, new_name):
|
|||||||
new_lines[start_pos[0] - 1] = start_line
|
new_lines[start_pos[0] - 1] = start_line
|
||||||
new_lines[start_pos[0]:end_pos[0] - 1] = []
|
new_lines[start_pos[0]:end_pos[0] - 1] = []
|
||||||
|
|
||||||
# add parentheses in multiline case
|
# add parentheses in multi-line case
|
||||||
open_brackets = ['(', '[', '{']
|
open_brackets = ['(', '[', '{']
|
||||||
close_brackets = [')', ']', '}']
|
close_brackets = [')', ']', '}']
|
||||||
if '\n' in text and not (text[0] in open_brackets and text[-1] ==
|
if '\n' in text and not (text[0] in open_brackets and text[-1] ==
|
||||||
@@ -171,7 +172,7 @@ def inline(script):
|
|||||||
inlines = sorted(inlines, key=lambda x: (x.module_path, x.line, x.column),
|
inlines = sorted(inlines, key=lambda x: (x.module_path, x.line, x.column),
|
||||||
reverse=True)
|
reverse=True)
|
||||||
expression_list = stmt.expression_list()
|
expression_list = stmt.expression_list()
|
||||||
# don't allow multiline refactorings for now.
|
# don't allow multi-line refactorings for now.
|
||||||
assert stmt.start_pos[0] == stmt.end_pos[0]
|
assert stmt.start_pos[0] == stmt.end_pos[0]
|
||||||
index = stmt.start_pos[0] - 1
|
index = stmt.start_pos[0] - 1
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user