mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-34626 Fix isMethodContext to exclude inner functions as methods
closes https://github.com/JetBrains/intellij-community/pull/2811 GitOrigin-RevId: 9268c21cf03158738ca059f8b19c803cb9c368f3
This commit is contained in:
committed by
intellij-monorepo-bot
parent
c685dbd6aa
commit
467ea6dd47
@@ -287,7 +287,7 @@ public final class PyPsiUtils {
|
||||
public static boolean isMethodContext(final PsiElement element) {
|
||||
final PsiNamedElement parent = PsiTreeUtil.getParentOfType(element, PyFile.class, PyFunction.class, PyClass.class);
|
||||
// In case if element is inside method which is inside class
|
||||
if (parent instanceof PyFunction && PsiTreeUtil.getParentOfType(parent, PyFile.class, PyClass.class) instanceof PyClass) {
|
||||
if (parent instanceof PyFunction && PsiTreeUtil.getParentOfType(parent, PyFile.class, PyFunction.class, PyClass.class) instanceof PyClass) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
class Test:
|
||||
x = 5
|
||||
|
||||
def method(self):
|
||||
def func():
|
||||
y = extracted()
|
||||
return y
|
||||
|
||||
def extracted():
|
||||
y = self.x
|
||||
return y
|
||||
|
||||
pass
|
||||
@@ -0,0 +1,8 @@
|
||||
class Test:
|
||||
x = 5
|
||||
|
||||
def method(self):
|
||||
def func():
|
||||
<selection>y = self.x</selection>
|
||||
return y
|
||||
pass
|
||||
@@ -0,0 +1,12 @@
|
||||
class Test:
|
||||
a = 5
|
||||
def method(self, b):
|
||||
def func(c):
|
||||
y = extracted(c)
|
||||
return y
|
||||
|
||||
def extracted(c_new):
|
||||
y = self.a + b * c_new
|
||||
return y
|
||||
|
||||
pass
|
||||
@@ -0,0 +1,8 @@
|
||||
class Test:
|
||||
a = 5
|
||||
def method(self, b):
|
||||
def func(c):
|
||||
<selection>y = self.a + b * c</selection>
|
||||
return y
|
||||
|
||||
pass
|
||||
@@ -0,0 +1,11 @@
|
||||
class Test:
|
||||
def method(self, a):
|
||||
def func(b):
|
||||
x = extracted(b)
|
||||
return x
|
||||
|
||||
def extracted(b_new):
|
||||
x = self.method(b_new)
|
||||
return x
|
||||
|
||||
return 0
|
||||
@@ -0,0 +1,7 @@
|
||||
class Test:
|
||||
def method(self, a):
|
||||
def func(b):
|
||||
<selection>x = self.method(b)</selection>
|
||||
return x
|
||||
|
||||
return 0
|
||||
@@ -0,0 +1,11 @@
|
||||
class Test:
|
||||
def method(self, x):
|
||||
def func():
|
||||
y = extracted()
|
||||
return y
|
||||
|
||||
def extracted():
|
||||
y = x * 2
|
||||
return y
|
||||
|
||||
pass
|
||||
@@ -0,0 +1,7 @@
|
||||
class Test:
|
||||
def method(self, x):
|
||||
def func():
|
||||
<selection>y = x * 2</selection>
|
||||
return y
|
||||
|
||||
pass
|
||||
@@ -0,0 +1,11 @@
|
||||
class Test:
|
||||
def method(self):
|
||||
def func(x):
|
||||
y = extracted(x)
|
||||
return y
|
||||
|
||||
def extracted(x_new):
|
||||
y = x_new * 2
|
||||
return y
|
||||
|
||||
pass
|
||||
@@ -0,0 +1,7 @@
|
||||
class Test:
|
||||
def method(self):
|
||||
def func(x):
|
||||
<selection>y = x * 2</selection>
|
||||
return y
|
||||
|
||||
pass
|
||||
@@ -43,6 +43,26 @@ public class PyExtractMethodTest extends LightMarkedTestCase {
|
||||
fail("No exception was thrown");
|
||||
}
|
||||
|
||||
public void testInnerFunc() {
|
||||
doTest("extracted");
|
||||
}
|
||||
|
||||
public void testInnerFuncWithVar() {
|
||||
doTest("extracted");
|
||||
}
|
||||
|
||||
public void testInnerFuncWithExtVar() {
|
||||
doTest("extracted");
|
||||
}
|
||||
|
||||
public void testInnerFuncRecursive() {
|
||||
doTest("extracted");
|
||||
}
|
||||
|
||||
public void testInnerFuncCombined() {
|
||||
doTest("extracted");
|
||||
}
|
||||
|
||||
public void testParameter() {
|
||||
doTest("bar");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user