PY-87998 PyStringConversionWithoutDunderMethodInspection: fix str/tuple and report list label

(cherry picked from commit ab32f336558da96ee037edc727d4a06681820817)

GitOrigin-RevId: 5d2a9e914b53f2764b9b6dfa2d2bd7b662be1eba
This commit is contained in:
Morgan Bartholomew
2026-03-24 04:40:40 +00:00
committed by intellij-monorepo-bot
parent cbe872c85a
commit f901605192
2 changed files with 12 additions and 13 deletions
@@ -35,9 +35,9 @@ class PyStringConversionWithoutDunderMethodInspection : PyInspection() {
@JvmField
val ignoredTypes: MutableList<String> = 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"))
)
}
@@ -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("""