diff --git a/CHANGELOG.md b/CHANGELOG.md index 66f53bb..89c01d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ ### Fixed - Incorrect `Literal` behavior with type hints +- `set[]` type hint were causing exceptions when declared explicitly ## [0.3.1] - 2022-10-02 ### Fixed diff --git a/src/main/kotlin/space/whitememory/pythoninlayparams/types/hints/HintGenerator.kt b/src/main/kotlin/space/whitememory/pythoninlayparams/types/hints/HintGenerator.kt index 7e4bb39..28669a5 100644 --- a/src/main/kotlin/space/whitememory/pythoninlayparams/types/hints/HintGenerator.kt +++ b/src/main/kotlin/space/whitememory/pythoninlayparams/types/hints/HintGenerator.kt @@ -4,9 +4,7 @@ package space.whitememory.pythoninlayparams.types.hints import com.intellij.psi.PsiElement import com.jetbrains.python.PyNames -import com.jetbrains.python.codeInsight.typing.PyTypingTypeProvider import com.jetbrains.python.psi.PyElement -import com.jetbrains.python.psi.PyFunction import com.jetbrains.python.psi.PyLambdaExpression import com.jetbrains.python.psi.types.* diff --git a/src/main/kotlin/space/whitememory/pythoninlayparams/types/hints/HintResolver.kt b/src/main/kotlin/space/whitememory/pythoninlayparams/types/hints/HintResolver.kt index 1994100..3da5097 100644 --- a/src/main/kotlin/space/whitememory/pythoninlayparams/types/hints/HintResolver.kt +++ b/src/main/kotlin/space/whitememory/pythoninlayparams/types/hints/HintResolver.kt @@ -264,14 +264,16 @@ enum class HintResolver { if (assignmentValue !is PyCallExpression) return true + if (typeAnnotation is PyNoneType) return true + val resolvedClass = PyCallExpressionHelper.resolveCalleeClass(assignmentValue) ?: return true if (!collectionNames.contains(resolvedClass.name)) { return resolvedClass.name != typeAnnotation?.name } - return typeAnnotation?.isBuiltin == true - && (typeAnnotation as PyCollectionType).elementTypes.filterNotNull().isNotEmpty() + val collectionType = (typeAnnotation as? PyCollectionType) ?: return false + return collectionType.isBuiltin && collectionType.elementTypes.filterNotNull().isNotEmpty() } }, diff --git a/src/test/kotlin/space/whitememory/pythoninlayparams/PythonVariableTypesTest.kt b/src/test/kotlin/space/whitememory/pythoninlayparams/PythonVariableTypesTest.kt index d9af7cd..81b0243 100644 --- a/src/test/kotlin/space/whitememory/pythoninlayparams/PythonVariableTypesTest.kt +++ b/src/test/kotlin/space/whitememory/pythoninlayparams/PythonVariableTypesTest.kt @@ -183,6 +183,19 @@ class PythonVariableTypesTest : PythonAbstractInlayHintsTestCase() { """.trimIndent() ) + fun testIterableHints() = doTest( + """ + item_set<# [: [set [ str ]]] #> = set() + x<# [: None] #> = item_set.add("1") + + explicit_item_set: set[str] = set() + y<# [: None] #> = explicit_item_set.add("1") + + unclear_item_set: set = set() + z<# [: None] #> = unclear_item_set.add("1") + """.trimIndent() + ) + private fun doTest(text: String) { testProvider( "foo.py",