[python] PY-80252 set correct default highlighting for PyUnnecessaryCast

GitOrigin-RevId: fb0767353a298f95af63beee4f9c2db729d777ee
This commit is contained in:
Morgan Bartholomew
2025-08-28 09:37:36 +10:00
committed by intellij-monorepo-bot
parent 467785be0e
commit b9c06cd3b5
3 changed files with 15 additions and 7 deletions

View File

@@ -225,7 +225,7 @@
<localInspection language="Python" shortName="PyClassHasNoInitInspection" suppressId="PyClassHasNoInit" bundle="messages.PyPsiBundle" key="INSP.NAME.class.has.no.init" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WEAK WARNING" implementationClass="com.jetbrains.python.inspections.PyClassHasNoInitInspection"/>
<localInspection language="Python" shortName="PyNoneFunctionAssignmentInspection" suppressId="PyNoneFunctionAssignment" bundle="messages.PyPsiBundle" key="INSP.NAME.none.function.assignment" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WEAK WARNING" implementationClass="com.jetbrains.python.inspections.PyNoneFunctionAssignmentInspection"/>
<localInspection language="Python" shortName="PyInvalidCastInspection" suppressId="PyInvalidCast" bundle="messages.PyPsiBundle" key="INSP.NAME.invalid.cast" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WARNING" implementationClass="com.jetbrains.python.inspections.PyInvalidCastInspection"/>
<localInspection language="Python" shortName="PyUnnecessaryCastInspection" suppressId="PyUnnecessaryCast" bundle="messages.PyPsiBundle" key="INSP.NAME.unnecessary.cast" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WARNING" implementationClass="com.jetbrains.python.inspections.PyUnnecessaryCastInspection"/>
<localInspection language="Python" shortName="PyUnnecessaryCastInspection" suppressId="PyUnnecessaryCast" bundle="messages.PyPsiBundle" key="INSP.NAME.unnecessary.cast" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WEAK WARNING" editorAttributes="NOT_USED_ELEMENT_ATTRIBUTES" implementationClass="com.jetbrains.python.inspections.PyUnnecessaryCastInspection"/>
<localInspection language="Python" shortName="PyProtectedMemberInspection" suppressId="PyProtectedMember" bundle="messages.PyPsiBundle" key="INSP.NAME.protected.member" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WEAK WARNING" implementationClass="com.jetbrains.python.inspections.PyProtectedMemberInspection"/>
<localInspection language="Python" shortName="PyMethodMayBeStaticInspection" suppressId="PyMethodMayBeStatic" bundle="messages.PyPsiBundle" key="INSP.NAME.method.may.be.static" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WEAK WARNING" implementationClass="com.jetbrains.python.inspections.PyMethodMayBeStaticInspection"/>
<localInspection language="Python" shortName="PyDocstringTypesInspection" suppressId="PyDocstringTypes" bundle="messages.PyPsiBundle" key="INSP.NAME.docstring.types" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WEAK WARNING" implementationClass="com.jetbrains.python.inspections.PyDocstringTypesInspection"/>

View File

@@ -3,10 +3,8 @@ package com.jetbrains.python.inspections
import com.intellij.codeInspection.LocalInspectionToolSession
import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.codeInspection.ProblemsHolder
import com.intellij.codeInspection.ex.ProblemDescriptorImpl
import com.intellij.modcommand.ModPsiUpdater
import com.intellij.modcommand.PsiUpdateModCommandQuickFix
import com.intellij.openapi.editor.colors.TextAttributesKey
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Ref
import com.intellij.openapi.util.TextRange
@@ -47,11 +45,21 @@ class PyUnnecessaryCastInspection : PyInspection() {
"INSP.unnecessary.cast.message",
toName
),
ProblemHighlightType.LIKE_UNUSED_SYMBOL,
ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
null,
TextRange(0, callExpression.arguments[0].nextSibling.endOffset - callExpression.startOffset),
RemoveUnnecessaryCastQuickFix(),
)
registerProblem(
callExpression,
PyPsiBundle.message(
"INSP.unnecessary.cast.message",
toName
),
ProblemHighlightType.INFORMATION,
null,
RemoveUnnecessaryCastQuickFix(),
)
}
}
}

View File

@@ -14,7 +14,7 @@ class PyUnnecessaryCastInspectionTest : PyInspectionTestCase() {
from typing import cast
def f(a: int):
<warning descr="Unnecessary cast; type is already 'int'">cast(int,</warning>a)
<weak_warning descr="Unnecessary cast; type is already 'int'">cast(int,</weak_warning>a)
""".trimIndent()
)
}
@@ -26,7 +26,7 @@ class PyUnnecessaryCastInspectionTest : PyInspectionTestCase() {
one: Literal[1] = 1
cast(int, one)
<warning descr="Unnecessary cast; type is already 'Literal[1]'">cast(Literal[1],</warning> one)
<weak_warning descr="Unnecessary cast; type is already 'Literal[1]'">cast(Literal[1],</weak_warning> one)
""".trimIndent()
)
}
@@ -62,7 +62,7 @@ from typing import cast
from typing import cast
def f(a: int):
<warning descr="Unnecessary cast; type is already 'int'"><caret>cast(int,</warning> a)
<weak_warning descr="Unnecessary cast; type is already 'int'"><caret>cast(int,</weak_warning> a)
""".trimIndent()
myFixture.configureByText(PythonFileType.INSTANCE, text)
configureInspection()