From 05f36652c94f33d692ff3b24cc240bf6f0ac99f5 Mon Sep 17 00:00:00 2001 From: Aleksei Kniazev Date: Sat, 22 Jun 2019 15:55:18 +0300 Subject: [PATCH] IDEA-CR-49176: fixed exception when invoking inline on import (PY-36484) GitOrigin-RevId: e67643b18f410f3f6a92405ffe128f5e987ebb7d --- .../python/refactoring/inline/PyInlineFunctionProcessor.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/python/src/com/jetbrains/python/refactoring/inline/PyInlineFunctionProcessor.kt b/python/src/com/jetbrains/python/refactoring/inline/PyInlineFunctionProcessor.kt index 6fe21eea0252..969bdc344f87 100644 --- a/python/src/com/jetbrains/python/refactoring/inline/PyInlineFunctionProcessor.kt +++ b/python/src/com/jetbrains/python/refactoring/inline/PyInlineFunctionProcessor.kt @@ -90,8 +90,9 @@ class PyInlineFunctionProcessor(project: Project, override fun findUsages(): Array { if (myInlineThis) { val element = myReference!!.element as PyReferenceExpression - val import = PyResolveUtil.resolveLocally(ScopeUtil.getScopeOwner(element)!!, element.name!!).firstOrNull { it is PyImportElement } - return if (import != null) arrayOf(UsageInfo(element), UsageInfo(import)) else arrayOf(UsageInfo(element)) + val isImport = PsiTreeUtil.getParentOfType(element, PyImportStatementBase::class.java) != null + val localImport = PyResolveUtil.resolveLocally(ScopeUtil.getScopeOwner(element)!!, element.name!!).firstOrNull { it is PyImportElement } + return if (!isImport && localImport != null) arrayOf(UsageInfo(element), UsageInfo(localImport)) else arrayOf(UsageInfo(element)) } return ReferencesSearch.search(myFunction, myRefactoringScope).asSequence()