From f9016051923995acda8181e7e2a306bd6e02a7a7 Mon Sep 17 00:00:00 2001 From: Morgan Bartholomew Date: Tue, 24 Mar 2026 10:34:08 +1000 Subject: [PATCH] PY-87998 `PyStringConversionWithoutDunderMethodInspection`: fix `str`/`tuple` and report list label (cherry picked from commit ab32f336558da96ee037edc727d4a06681820817) GitOrigin-RevId: 5d2a9e914b53f2764b9b6dfa2d2bd7b662be1eba --- ...ngConversionWithoutDunderMethodInspection.kt | 8 ++++---- ...nversionWithoutDunderMethodInspectionTest.kt | 17 ++++++++--------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/python/python-psi-impl/src/com/jetbrains/python/inspections/PyStringConversionWithoutDunderMethodInspection.kt b/python/python-psi-impl/src/com/jetbrains/python/inspections/PyStringConversionWithoutDunderMethodInspection.kt index ad1dcfd2e2c2..2913a446188e 100644 --- a/python/python-psi-impl/src/com/jetbrains/python/inspections/PyStringConversionWithoutDunderMethodInspection.kt +++ b/python/python-psi-impl/src/com/jetbrains/python/inspections/PyStringConversionWithoutDunderMethodInspection.kt @@ -35,9 +35,9 @@ class PyStringConversionWithoutDunderMethodInspection : PyInspection() { @JvmField val ignoredTypes: MutableList = mutableListOf( "types.NoneType", "_io.TextIOWrapper", - // the definitions for these types don't include their `__str__~, so we have to explicitly ignore them - "int", "float", "complex", "set", "frozenset", "bytes", "bytearray", "memoryview", - "slice", "list", "dict", "bool", "range" + // the definitions for these types don't include their `__str__`/`__repr__`, so we have to explicitly ignore them + "str", "int", "float", "complex", "set", "frozenset", "bytes", "bytearray", "memoryview", + "slice", "list", "dict", "bool", "range", "tuple", ) @JvmField @@ -48,7 +48,7 @@ class PyStringConversionWithoutDunderMethodInspection : PyInspection() { override fun getOptionsPane(): OptPane { return OptPane.pane( OptPane.stringList("ignoredTypes", PyPsiBundle.message("INSP.string.conversion.ignored.types")), - OptPane.stringList("reportedTypes", PyPsiBundle.message("INSP.string.conversion.ignored.types")) + OptPane.stringList("reportedTypes", PyPsiBundle.message("INSP.string.conversion.reported.types")) ) } diff --git a/python/testSrc/com/jetbrains/python/inspections/PyStringConversionWithoutDunderMethodInspectionTest.kt b/python/testSrc/com/jetbrains/python/inspections/PyStringConversionWithoutDunderMethodInspectionTest.kt index 119df1b62ad7..ad4ac9d58594 100644 --- a/python/testSrc/com/jetbrains/python/inspections/PyStringConversionWithoutDunderMethodInspectionTest.kt +++ b/python/testSrc/com/jetbrains/python/inspections/PyStringConversionWithoutDunderMethodInspectionTest.kt @@ -90,15 +90,14 @@ class PyStringConversionWithoutDunderMethodInspectionTest : PyInspectionTestCase """.trimIndent()) fun `test should not warn for builtin types`() = doTestByText(""" - # Should not warn for builtin types - str(42) - str([1, 2, 3]) - str({"key": "value"}) - str(None) - str(True) - - format(42) - format("hello") + # see default ignore list for explanation + repr(42) + repr((1, 2, 3)) + repr([1, 2, 3]) + repr({"key": "value"}) + repr(None) + repr(True) + repr("asdf") """.trimIndent()) fun `test should warn for type`() = doTestByText("""