PY-80627 Place a 'missing @overload implementation' warning on the first overloaded function

Before it was placed on the last overloaded function. While it was also a valid behavior, this change makes it conformant to the typing tests suite.

GitOrigin-RevId: 3e19bb8e76173064013f71fe25a3b275afcfda99
This commit is contained in:
Petr
2025-05-17 13:45:32 +00:00
committed by intellij-monorepo-bot
parent e177760252
commit 6f9f976018
2 changed files with 10 additions and 14 deletions
@@ -53,16 +53,12 @@ class PyOverloadsInspection : PyInspection() {
val implementation = functions.lastOrNull { !PyiUtil.isOverload(it, myTypeEvalContext) }
if (implementation == null) {
functions
.maxByOrNull { it.textOffset }
?.let {
registerProblem(it.nameIdentifier, if (owner is PyClass) {
PyPsiBundle.message("INSP.overloads.series.overload.decorated.methods.should.always.be.followed.by.implementation")
}
else {
PyPsiBundle.message("INSP.overloads.series.overload.decorated.functions.should.always.be.followed.by.implementation")
})
}
registerProblem(functions.first().nameIdentifier, if (owner is PyClass) {
PyPsiBundle.message("INSP.overloads.series.overload.decorated.methods.should.always.be.followed.by.implementation")
}
else {
PyPsiBundle.message("INSP.overloads.series.overload.decorated.functions.should.always.be.followed.by.implementation")
})
}
else {
if (implementation != functions.last()) {
@@ -2,7 +2,7 @@ from typing import overload
@overload
def foo(value: None) -> None:
def <warning descr="A series of @overload-decorated functions should always be followed by an implementation that is not @overload-ed">foo</warning>(value: None) -> None:
pass
@@ -12,13 +12,13 @@ def foo(value: int) -> str:
@overload
def <warning descr="A series of @overload-decorated functions should always be followed by an implementation that is not @overload-ed">foo</warning>(value: str) -> str:
def foo(value: str) -> str:
pass
class A:
@overload
def foo(self, value: None) -> None:
def <warning descr="A series of @overload-decorated methods should always be followed by an implementation that is not @overload-ed">foo</warning>(self, value: None) -> None:
pass
@overload
@@ -26,5 +26,5 @@ class A:
pass
@overload
def <warning descr="A series of @overload-decorated methods should always be followed by an implementation that is not @overload-ed">foo</warning>(self, value: str) -> str:
def foo(self, value: str) -> str:
pass