IDEA-CR-49176: function inline: remove typing overloads together with the function (PY-36465)

GitOrigin-RevId: ef532069cd2d8bb06b35fb7d6ef7be2563b9b76d
This commit is contained in:
Aleksei Kniazev
2019-06-26 15:33:35 +03:00
committed by intellij-monorepo-bot
parent 1b5d272f4e
commit f6c70470d6
4 changed files with 38 additions and 0 deletions

View File

@@ -275,6 +275,11 @@ class PyInlineFunctionProcessor(project: Project,
if (stubFunction != null && stubFunction.isWritable) {
stubFunction.delete()
}
val typingOverloads = PyiUtil.getOverloads(myFunction, TypeEvalContext.userInitiated(myProject, myFunction.containingFile))
if (typingOverloads.isNotEmpty()) {
typingOverloads.forEach { it.delete() }
PyClassRefactoringUtil.optimizeImports(myFunction.containingFile)
}
myFunction.delete()
dunderAll.forEach { it.element?.delete() }
}

View File

@@ -0,0 +1,9 @@
class MyClass:
def __init__(self, my_val):
self.my_val = my_val
my_class = MyClass(1)
print(my_class.my_val)
print(2)
res = 2

View File

@@ -0,0 +1,23 @@
from typing import overload
class MyClass:
def __init__(self, my_val):
self.my_val = my_val
@overload
def method(self, x: int) -> int:
pass
@overload
def method(self, x: str) -> str:
pass
def method(self, x):
print(self.my_val)
print(x)
return x
my_class = MyClass(1)
res = my_class.met<caret>hod(2)

View File

@@ -66,6 +66,7 @@ class PyInlineFunctionTest : PyTestCase() {
fun testNoReturnsAsCallExpression() = doTest()
fun testInlineAll() = doTest(inlineThis = false)
fun testRemoving() = doTest(inlineThis = false, remove = true)
fun testRemoveTypingOverrides() = doTest(inlineThis = false, remove = true)
fun testDefaultValues() = doTest()
fun testPositionalOnlyArgs() = doTest()
fun testKeywordOnlyArgs() = doTest()