From 8fbb25d4ad4b2d00d397695be0f2ab9d83d319c8 Mon Sep 17 00:00:00 2001 From: Petr Date: Mon, 19 May 2025 19:01:09 +0200 Subject: [PATCH] [python] Slightly simplified code (PyOverloadsInspection.kt) GitOrigin-RevId: 333affe1d43bf5c8995cd39993643f6c7d8198e6 --- .../resources/messages/PyPsiBundle.properties | 9 +++---- .../inspections/PyOverloadsInspection.kt | 27 +++++++------------ 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/python/python-psi-impl/resources/messages/PyPsiBundle.properties b/python/python-psi-impl/resources/messages/PyPsiBundle.properties index 498659a37bf0..67e109b30299 100644 --- a/python/python-psi-impl/resources/messages/PyPsiBundle.properties +++ b/python/python-psi-impl/resources/messages/PyPsiBundle.properties @@ -1041,12 +1041,9 @@ INSP.missing.type.hints.checkbox.only.when.types.are.known=Only when types are k # PyOverloadsInspection INSP.NAME.overloads.in.regular.python.files=Overloads in regular Python files -INSP.overloads.series.overload.decorated.methods.should.always.be.followed.by.implementation=A series of @overload-decorated methods should always be followed by an implementation that is not @overload-ed -INSP.overloads.series.overload.decorated.functions.should.always.be.followed.by.implementation=A series of @overload-decorated functions should always be followed by an implementation that is not @overload-ed -INSP.overloads.this.method.overload.signature.not.compatible.with.implementation=Signature of this @overload-decorated method is not compatible with the implementation -INSP.overloads.this.function.overload.signature.not.compatible.with.implementation=Signature of this @overload-decorated function is not compatible with the implementation -INSP.overloads.at.least.two.overload.decorated.methods.must.be.present=At least two @overload-decorated methods must be present -INSP.overloads.at.least.two.overload.decorated.functions.must.be.present=At least two @overload-decorated functions must be present +INSP.overloads.series.overloads.should.always.be.followed.by.implementation=A series of @overload-decorated {0,choice,0#functions|1#methods} should always be followed by an implementation that is not @overload-ed +INSP.overloads.this.overload.signature.not.compatible.with.implementation=Signature of this @overload-decorated {0,choice,0#function|1#method} is not compatible with the implementation +INSP.overloads.at.least.two.overloads.must.be.present=At least two @overload-decorated {0,choice,0#functions|1#methods} must be present INSP.overloads.use.staticmethod.inconsistently=Overloads use @staticmethod inconsistently INSP.overloads.use.classmethod.inconsistently=Overloads use @classmethod inconsistently INSP.overloads.override.should.be.placed.on.the.implementation='@override' should be placed on the implementation 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 f51e33c4667f..54f999951324 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 @@ -50,12 +50,9 @@ class PyOverloadsInspection : PyInspection() { if (overloads.isEmpty()) return if (overloads.size == 1) { - registerProblem(overloads[0].nameIdentifier, if (owner is PyClass) { - PyPsiBundle.message("INSP.overloads.at.least.two.overload.decorated.methods.must.be.present") - } - else { - PyPsiBundle.message("INSP.overloads.at.least.two.overload.decorated.functions.must.be.present") - }) + registerProblem(overloads[0].nameIdentifier, + PyPsiBundle.message("INSP.overloads.at.least.two.overloads.must.be.present", + if (owner is PyClass) 1 else 0)) } val implementation = implementations.lastOrNull() @@ -83,12 +80,9 @@ class PyOverloadsInspection : PyInspection() { if (requiresImplementation && implementation !== functions.last()) { val problemElement = if (implementation == null) functions.first() else functions.last() - registerProblem(problemElement.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(problemElement.nameIdentifier, + PyPsiBundle.message("INSP.overloads.series.overloads.should.always.be.followed.by.implementation", + if (owner is PyClass) 1 else 0)) } if (implementation != null) { @@ -96,12 +90,9 @@ class PyOverloadsInspection : PyInspection() { .asSequence() .filter { isIncompatibleOverload(implementation, it) } .forEach { - registerProblem(it.nameIdentifier, if (owner is PyClass) { - PyPsiBundle.message("INSP.overloads.this.method.overload.signature.not.compatible.with.implementation") - } - else { - PyPsiBundle.message("INSP.overloads.this.function.overload.signature.not.compatible.with.implementation") - }) + registerProblem(it.nameIdentifier, + PyPsiBundle.message("INSP.overloads.this.overload.signature.not.compatible.with.implementation", + if (owner is PyClass) 1 else 0)) } } }