From 7dff25f7c95fa19a0d8039d82adbd6a10875c193 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Mon, 17 Feb 2020 10:06:40 +0100 Subject: [PATCH] Test extracing of base classes --- jedi/api/refactoring.py | 3 ++- test/refactor/extract_variable.py | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/jedi/api/refactoring.py b/jedi/api/refactoring.py index 7f8c5cb0..d9c838e8 100644 --- a/jedi/api/refactoring.py +++ b/jedi/api/refactoring.py @@ -12,6 +12,7 @@ _INLINE_NEEDS_BRACKET = ( 'xor_expr and_expr shift_expr arith_expr term factor power atom_expr ' 'or_test and_test not_test comparison' ).split() +_EXTRACT_USE_PARENT = _INLINE_NEEDS_BRACKET + ['trailer'] _DEFINITION_SCOPES = ('suite', 'file_input') _NON_EXCTRACABLE = ('param', ) @@ -228,7 +229,7 @@ def extract_variable(grammar, path, module_node, new_name, pos, until_pos): node = start_leaf if node.type == 'operator': node = node.parent - while node.parent.type in _INLINE_NEEDS_BRACKET: + while node.parent.type in _EXTRACT_USE_PARENT: node = node.parent start_leaf extracted = node.get_code(include_prefix=False) diff --git a/test/refactor/extract_variable.py b/test/refactor/extract_variable.py index 78d00139..76594783 100644 --- a/test/refactor/extract_variable.py +++ b/test/refactor/extract_variable.py @@ -66,3 +66,30 @@ def test(p1=20): x = 20 def test(p1=x): return +# -------------------------------------------------- for-something +#? 12 text {'new_name': 'x'} +def test(p1=20): + return +# ++++++++++++++++++++++++++++++++++++++++++++++++++ +#? 12 text {'new_name': 'x'} +x = 20 +def test(p1=x): + return +# -------------------------------------------------- class-inheritance-1 +#? 12 text {'new_name': 'x'} +class Foo(foo.Bar): + pass +# ++++++++++++++++++++++++++++++++++++++++++++++++++ +#? 12 text {'new_name': 'x'} +x = foo.Bar +class Foo(x): + pass +# -------------------------------------------------- class-inheritance-1 +#? 16 text {'new_name': 'x'} +class Foo(foo.Bar): + pass +# ++++++++++++++++++++++++++++++++++++++++++++++++++ +#? 16 text {'new_name': 'x'} +x = foo.Bar +class Foo(x): + pass