mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-80628 Error on the first overload when trying to override the final method
GitOrigin-RevId: fc94bfe3d7d1f91f02f9601f92e4373aa7ea2abb
This commit is contained in:
committed by
intellij-monorepo-bot
parent
cd00f30c84
commit
6f6e27c500
@@ -76,7 +76,10 @@ class PyFinalInspection : PyInspection() {
|
||||
|
||||
val cls = node.containingClass
|
||||
if (cls != null) {
|
||||
if (!PyiUtil.isOverload(node, myTypeEvalContext)) {
|
||||
val isOverload = PyiUtil.isOverload(node, myTypeEvalContext)
|
||||
if (!isOverload ||
|
||||
PyiUtil.getImplementation(node, myTypeEvalContext) == null &&
|
||||
PyiUtil.getOverloads(node, myTypeEvalContext).firstOrNull() === node) {
|
||||
PySuperMethodsSearch
|
||||
.search(node, myTypeEvalContext)
|
||||
.asIterable()
|
||||
|
||||
@@ -51,7 +51,6 @@ namedtuples_type_compat.py
|
||||
namedtuples_usage.py
|
||||
narrowing_typeis.py
|
||||
overloads_consistency.py
|
||||
overloads_definitions_stub.pyi
|
||||
overloads_evaluation.py
|
||||
protocols_class_objects.py
|
||||
protocols_definition.py
|
||||
|
||||
@@ -4,6 +4,7 @@ package com.jetbrains.python.inspections;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.jetbrains.python.fixtures.PyInspectionTestCase;
|
||||
import com.jetbrains.python.psi.LanguageLevel;
|
||||
import com.jetbrains.python.pyi.PyiFileType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PyFinalInspectionTest extends PyInspectionTestCase {
|
||||
@@ -111,6 +112,55 @@ public class PyFinalInspectionTest extends PyInspectionTestCase {
|
||||
);
|
||||
}
|
||||
|
||||
public void testOverridingOverloadedFinalMethod2() {
|
||||
doTestByText("""
|
||||
from typing import final, overload
|
||||
|
||||
class Base:
|
||||
@overload
|
||||
def foo(self, x: int) -> int: ...
|
||||
|
||||
@overload
|
||||
def foo(self, x: str) -> str: ...
|
||||
|
||||
@final
|
||||
def foo(self, x: int | str) -> int | str:
|
||||
pass
|
||||
|
||||
class Derived(Base):
|
||||
@overload
|
||||
def foo(self, x: int) -> int: ...
|
||||
|
||||
@overload
|
||||
def foo(self, x: str) -> str: ...
|
||||
|
||||
def <warning descr="'aaa.Base.foo' is marked as '@final' and should not be overridden">foo</warning>(self, x: int | str) -> int | str:
|
||||
pass""");
|
||||
}
|
||||
|
||||
public void testOverridingOverloadedFinalMethodNoImplementation() {
|
||||
final PsiFile currentFile = myFixture.configureByText(PyiFileType.INSTANCE, """
|
||||
from typing import final, overload
|
||||
|
||||
class Base:
|
||||
@overload
|
||||
@final
|
||||
def foo(self, x: int) -> int: ...
|
||||
|
||||
@overload
|
||||
def foo(self, x: str) -> str: ...
|
||||
|
||||
class Derived(Base):
|
||||
@overload
|
||||
def <warning descr="'aaa.Base.foo' is marked as '@final' and should not be overridden">foo</warning>(self, x: int) -> int: ...
|
||||
|
||||
@overload
|
||||
def foo(self, x: str) -> str: ..."""
|
||||
);
|
||||
configureInspection();
|
||||
assertSdkRootsNotParsed(currentFile);
|
||||
}
|
||||
|
||||
// PY-34945
|
||||
public void testFinalNonMethodFunction() {
|
||||
doTestByText("""
|
||||
|
||||
Reference in New Issue
Block a user