mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-85519 Skip import statements in PyFinalInspection
Renames in import statements like `from b import A as B` are considered target expressions. Since they are not annotated as `Final` (they can't be annotated), they were reported as `B could not be reassigned` GitOrigin-RevId: 0187aeb5da25dd3eb5c8284bdda5cddd30170047
This commit is contained in:
committed by
intellij-monorepo-bot
parent
4c728ae18e
commit
f53a941266
@@ -36,6 +36,7 @@ import com.jetbrains.python.psi.PyExpressionStatement
|
||||
import com.jetbrains.python.psi.PyForStatement
|
||||
import com.jetbrains.python.psi.PyFunction
|
||||
import com.jetbrains.python.psi.PyGlobalStatement
|
||||
import com.jetbrains.python.psi.PyImportStatementBase
|
||||
import com.jetbrains.python.psi.PyKnownDecoratorUtil
|
||||
import com.jetbrains.python.psi.PyLoopStatement
|
||||
import com.jetbrains.python.psi.PyNamedParameter
|
||||
@@ -157,6 +158,8 @@ class PyFinalInspection : PyInspection() {
|
||||
super.visitPyTargetExpression(node)
|
||||
|
||||
val parent = PsiTreeUtil.getParentOfType(node, PyStatement::class.java)
|
||||
if (parent is PyImportStatementBase) return
|
||||
|
||||
if (parent is PyTypeDeclarationStatement || parent is PyGlobalStatement || parent is PyNonlocalStatement) {
|
||||
node.annotation?.value?.let {
|
||||
if (PyiUtil.isInsideStub(node) || ScopeUtil.getScopeOwner(node) is PyClass) {
|
||||
@@ -355,7 +358,7 @@ class PyFinalInspection : PyInspection() {
|
||||
else -> PyUtil.multiResolveTopPriority(target, resolveContext)
|
||||
}.toMutableList()
|
||||
|
||||
val scopeOwner = ScopeUtil.getScopeOwner(target);
|
||||
val scopeOwner = ScopeUtil.getScopeOwner(target)
|
||||
if (!target.isQualified && scopeOwner != null) {
|
||||
// multiResolve finds last assignments, but we need all earlier assignments
|
||||
val scope = ControlFlowCache.getScope(scopeOwner)
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
from b import A as B
|
||||
|
||||
print(B)
|
||||
@@ -0,0 +1,3 @@
|
||||
from typing import Final
|
||||
|
||||
A: Final = "example"
|
||||
@@ -695,6 +695,11 @@ public class PyFinalInspectionTest extends PyInspectionTestCase {
|
||||
pass""");
|
||||
}
|
||||
|
||||
// PY-85519
|
||||
public void testImportAsFinal() {
|
||||
doMultiFileTest();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected Class<? extends PyInspection> getInspectionClass() {
|
||||
|
||||
Reference in New Issue
Block a user