From 6f9f9760185a3e5b13b1aa3d8e340e177e22ac0a Mon Sep 17 00:00:00 2001 From: Petr Date: Thu, 15 May 2025 17:41:34 +0200 Subject: [PATCH] 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 --- .../python/inspections/PyOverloadsInspection.kt | 16 ++++++---------- .../PyOverloadsInspection/noImplementation.py | 8 ++++---- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/python/python-psi-impl/src/com/jetbrains/python/inspections/PyOverloadsInspection.kt b/python/python-psi-impl/src/com/jetbrains/python/inspections/PyOverloadsInspection.kt index e2d881a2cad4..1ba3abc82ebf 100644 --- a/python/python-psi-impl/src/com/jetbrains/python/inspections/PyOverloadsInspection.kt +++ b/python/python-psi-impl/src/com/jetbrains/python/inspections/PyOverloadsInspection.kt @@ -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()) { diff --git a/python/testData/inspections/PyOverloadsInspection/noImplementation.py b/python/testData/inspections/PyOverloadsInspection/noImplementation.py index c354030927c8..4c95d5774175 100644 --- a/python/testData/inspections/PyOverloadsInspection/noImplementation.py +++ b/python/testData/inspections/PyOverloadsInspection/noImplementation.py @@ -2,7 +2,7 @@ from typing import overload @overload -def foo(value: None) -> None: +def foo(value: None) -> None: pass @@ -12,13 +12,13 @@ def foo(value: int) -> str: @overload -def foo(value: str) -> str: +def foo(value: str) -> str: pass class A: @overload - def foo(self, value: None) -> None: + def foo(self, value: None) -> None: pass @overload @@ -26,5 +26,5 @@ class A: pass @overload - def foo(self, value: str) -> str: + def foo(self, value: str) -> str: pass \ No newline at end of file