mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 05:54:25 +08:00
Fix some inline tests about different modules and atom_expr/trailer combinations
This commit is contained in:
@@ -8,7 +8,7 @@ from parso import split_lines
|
||||
from jedi.api.exceptions import RefactoringError
|
||||
|
||||
_INLINE_NEEDS_BRACKET = (
|
||||
'xor_expr and_expr shift_expr arith_expr term factor power '
|
||||
'xor_expr and_expr shift_expr arith_expr term factor power atom_expr '
|
||||
'or_test and_test not_test comparison'
|
||||
).split()
|
||||
|
||||
@@ -181,13 +181,26 @@ def inline(grammar, names):
|
||||
references = [n for n in names if not n.tree_name.is_definition()]
|
||||
file_to_node_changes = {}
|
||||
for name in references:
|
||||
tree_name = name.tree_name
|
||||
path = name.get_root_context().py__file__()
|
||||
s = replace_code
|
||||
if rhs.type == 'testlist_star_expr' \
|
||||
or name.tree_name.parent.type in _INLINE_NEEDS_BRACKET:
|
||||
or tree_name.parent.type in _INLINE_NEEDS_BRACKET \
|
||||
or tree_name.parent.type == 'trailer' \
|
||||
and tree_name.parent.get_next_sibling() is not None:
|
||||
s = '(' + replace_code + ')'
|
||||
file_to_node_changes.setdefault(path, {})[name.tree_name] = \
|
||||
name.tree_name.prefix + s
|
||||
|
||||
of_path = file_to_node_changes.setdefault(path, {})
|
||||
|
||||
n = tree_name
|
||||
prefix = n.prefix
|
||||
par = n.parent
|
||||
if par.type == 'trailer' and par.children[0] == '.':
|
||||
prefix = par.parent.children[0].prefix
|
||||
n = par
|
||||
for some_node in par.parent.children[:par.parent.children.index(par)]:
|
||||
of_path[some_node] = ''
|
||||
of_path[n] = prefix + s
|
||||
|
||||
path = definitions[0].get_root_context().py__file__()
|
||||
changes = file_to_node_changes.setdefault(path, {})
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
foobar = 3
|
||||
|
||||
inline_var = 5 + 3
|
||||
|
||||
@@ -58,12 +58,30 @@ import math
|
||||
math.cos
|
||||
# ++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
Cannot inline builtins/extensions
|
||||
# -------------------------------------------------- module
|
||||
# -------------------------------------------------- module-error
|
||||
from import_tree import some_mod
|
||||
#? 11 error
|
||||
test(some_mod)
|
||||
# ++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
Cannot inline imports or modules
|
||||
# -------------------------------------------------- module-works
|
||||
from import_tree import some_mod
|
||||
#? 20
|
||||
test(x, some_mod. inline_var.conjugate)
|
||||
# ++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
--- /home/dave/source/jedi/test/refactor/inline.py
|
||||
+++ /home/dave/source/jedi/test/refactor/inline.py
|
||||
@@ -1,4 +1,4 @@
|
||||
from import_tree import some_mod
|
||||
#? 20
|
||||
-test(x, some_mod. inline_var.conjugate)
|
||||
+test(x, (5 + 3).conjugate)
|
||||
--- /home/dave/source/jedi/test/refactor/import_tree/some_mod.py
|
||||
+++ /home/dave/source/jedi/test/refactor/import_tree/some_mod.py
|
||||
@@ -1,4 +1,3 @@
|
||||
foobar = 3
|
||||
|
||||
-inline_var = 5 + 3
|
||||
# -------------------------------------------------- class
|
||||
class A: pass
|
||||
#? 5 error
|
||||
@@ -213,3 +231,15 @@ a = 1, 2 ; b = 3
|
||||
#? 9
|
||||
-(3, 3 == a)
|
||||
+(3, 3 == (1, 2))
|
||||
# -------------------------------------------------- no-tree-name
|
||||
a = 1 + 2
|
||||
#? 0
|
||||
a.conjugate
|
||||
# ++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
--- /home/dave/source/jedi/test/refactor/inline.py
|
||||
+++ /home/dave/source/jedi/test/refactor/inline.py
|
||||
@@ -1,4 +1,3 @@
|
||||
-a = 1 + 2
|
||||
#? 0
|
||||
-a.conjugate
|
||||
+(1 + 2).conjugate
|
||||
|
||||
Reference in New Issue
Block a user