mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
IDEA-CR-49176: reference in __all__ removed if target function if removed after inline (PY-36467)
GitOrigin-RevId: 670d6ee44d704c075319af42e3054c7bc9ca7bed
This commit is contained in:
committed by
intellij-monorepo-bot
parent
8800f4763c
commit
ed8952cbf0
@@ -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() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
print("foo")
|
||||
|
||||
__all__ = []
|
||||
@@ -0,0 +1,7 @@
|
||||
def foo():
|
||||
print("foo")
|
||||
|
||||
|
||||
fo<caret>o()
|
||||
|
||||
__all__ = ["foo"]
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user