IDEA-CR-49176: reference in __all__ removed if target function if removed after inline (PY-36467)

GitOrigin-RevId: 670d6ee44d704c075319af42e3054c7bc9ca7bed
This commit is contained in:
Aleksei Kniazev
2019-06-25 16:31:07 +03:00
committed by intellij-monorepo-bot
parent 8800f4763c
commit ed8952cbf0
4 changed files with 18 additions and 1 deletions

View File

@@ -49,6 +49,10 @@ class PyInlineFunctionProcessor(project: Project,
val (imports, usages) = usagesAndImports.partition { PsiTreeUtil.getParentOfType(it.element, PyImportStatementBase::class.java) != null }
val filteredUsages = usages.filter { usage ->
val element = usage.element!!
if (element is PyStringLiteralExpression) {
val file = element.containingFile as? PyFile
if (file?.dunderAll?.contains(element.stringValue) == true) return@filter true
}
if (element.parent is PyDecorator) {
if (!handleUsageError(element, "refactoring.inline.function.is.decorator", conflicts)) return false
return@filter false
@@ -115,8 +119,9 @@ class PyInlineFunctionProcessor(project: Project,
private fun doRefactor(usages: Array<out UsageInfo>) {
val (unsortedRefs, imports) = usages.partition { PsiTreeUtil.getParentOfType(it.element, PyImportStatementBase::class.java) == null }
val (callRefs, dunderAll) = unsortedRefs.partition { it.element is PyReferenceExpression }
val references = unsortedRefs.sortedByDescending { usage ->
val references = callRefs.sortedByDescending { usage ->
SyntaxTraverser.psiApi().parents(usage.element).asSequence().filter { it is PyCallExpression }.count()
}
@@ -270,6 +275,7 @@ class PyInlineFunctionProcessor(project: Project,
stubFunction.delete()
}
myFunction.delete()
dunderAll.forEach { it.element?.delete() }
}
}

View File

@@ -0,0 +1,3 @@
print("foo")
__all__ = []

View File

@@ -0,0 +1,7 @@
def foo():
print("foo")
fo<caret>o()
__all__ = ["foo"]

View File

@@ -74,6 +74,7 @@ class PyInlineFunctionTest : PyTestCase() {
fun testCallFromClassMethod() = doTest()
fun testComplexQualifier() = doTest()
fun testFunctionWithLambda() = doTest()
fun testRefInDunderAll() = doTest(inlineThis = false, remove = true)
fun testRemovingDocstring() = doTest()
fun testKeepFirstComment() = doTest()
//fun testInlineImportedAs() = doTest(inlineThis = false)