diff --git a/python/src/com/jetbrains/python/inspections/PyTypeHintsInspection.kt b/python/src/com/jetbrains/python/inspections/PyTypeHintsInspection.kt
index 4661eef9457c..fe0c9f54d89d 100644
--- a/python/src/com/jetbrains/python/inspections/PyTypeHintsInspection.kt
+++ b/python/src/com/jetbrains/python/inspections/PyTypeHintsInspection.kt
@@ -64,7 +64,7 @@ class PyTypeHintsInspection : PyInspection() {
super.visitPyClass(node)
if (node != null) {
- val superClassExpressions = node.superClassExpressions.toList()
+ val superClassExpressions = node.superClassExpressions.asList()
checkPlainGenericInheritance(superClassExpressions)
checkGenericDuplication(superClassExpressions)
@@ -246,7 +246,9 @@ class PyTypeHintsInspection : PyInspection() {
PyTypingTypeProvider.GENERIC,
PyTypingTypeProvider.OPTIONAL,
PyTypingTypeProvider.CLASS_VAR,
- PyTypingTypeProvider.NO_RETURN ->
+ PyTypingTypeProvider.NO_RETURN,
+ PyTypingTypeProvider.FINAL,
+ PyTypingTypeProvider.FINAL_EXT ->
registerProblem(base,
"'${it.substringAfterLast('.')}' cannot be used with instance and class checks",
ProblemHighlightType.GENERIC_ERROR)
@@ -275,14 +277,12 @@ class PyTypeHintsInspection : PyInspection() {
val qName = it.qualifiedName
when (qName) {
- PyTypingTypeProvider.GENERIC -> {
- registerProblem(base, "'Generic' cannot be used with instance and class checks", ProblemHighlightType.GENERIC_ERROR)
- return@forEach
- }
-
+ PyTypingTypeProvider.GENERIC,
PyTypingTypeProvider.UNION,
PyTypingTypeProvider.OPTIONAL,
- PyTypingTypeProvider.CLASS_VAR -> {
+ PyTypingTypeProvider.CLASS_VAR,
+ PyTypingTypeProvider.FINAL,
+ PyTypingTypeProvider.FINAL_EXT -> {
registerProblem(base,
"'${qName.substringAfterLast('.')}' cannot be used with instance and class checks",
ProblemHighlightType.GENERIC_ERROR)
diff --git a/python/testSrc/com/jetbrains/python/inspections/PyTypeHintsInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/PyTypeHintsInspectionTest.java
index da9236d8e0c2..ee768f9a83a2 100644
--- a/python/testSrc/com/jetbrains/python/inspections/PyTypeHintsInspectionTest.java
+++ b/python/testSrc/com/jetbrains/python/inspections/PyTypeHintsInspectionTest.java
@@ -342,6 +342,26 @@ public class PyTypeHintsInspectionTest extends PyInspectionTestCase {
"assert issubclass(A, C)");
}
+ // PY-34945
+ public void testInstanceAndClassChecksOnFinal() {
+ doTestByText("from typing import TypeVar\n" +
+ "from typing_extensions import Final\n" +
+ "\n" +
+ "T = TypeVar(\"T\")\n" +
+ "\n" +
+ "class A:\n" +
+ " pass\n" +
+ "\n" +
+ "assert isinstance(A(), Final)\n" +
+ "B = Final\n" +
+ "assert issubclass(A, B)\n" +
+ "\n" +
+ "assert isinstance(A(), Final[T])\n" +
+ "assert issubclass(A, B[T])\n" +
+ "C = B[T]\n" +
+ "assert issubclass(A, C)");
+ }
+
// PY-28249
public void testInstanceAndClassChecksOnGenericInheritor() {
doTestByText("from typing import TypeVar, List\n" +