Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down