@@ -2,6 +2,7 @@ package space.whitememory.pythoninlayparams.types.hints
22
33import com.intellij.psi.util.PsiTreeUtil
44import com.jetbrains.python.PyNames
5+ import com.jetbrains.python.PyTokenTypes
56import com.jetbrains.python.codeInsight.typing.PyTypingTypeProvider
67import com.jetbrains.python.psi.*
78import com.jetbrains.python.psi.impl.PyCallExpressionHelper
@@ -10,17 +11,6 @@ import space.whitememory.pythoninlayparams.types.variables.PythonVariablesInlayT
1011
1112enum class HintResolver {
1213
13- UNDERSCORE_HINT {
14- override fun isApplicable (settings : PythonVariablesInlayTypeHintsProvider .Settings ) = true
15-
16- override fun shouldShowTypeHint (
17- element : PyTargetExpression ,
18- typeAnnotation : PyType ? ,
19- typeEvalContext : TypeEvalContext ,
20- settings : PythonVariablesInlayTypeHintsProvider .Settings
21- ): Boolean = element.name != PyNames .UNDERSCORE
22- },
23-
2414 GLOBALS_HINT {
2515 override fun isApplicable (settings : PythonVariablesInlayTypeHintsProvider .Settings ) = true
2616
@@ -37,17 +27,6 @@ enum class HintResolver {
3727 }
3828 },
3929
40- QUALIFIED_HINT {
41- override fun isApplicable (settings : PythonVariablesInlayTypeHintsProvider .Settings ) = true
42-
43- override fun shouldShowTypeHint (
44- element : PyTargetExpression ,
45- typeAnnotation : PyType ? ,
46- typeEvalContext : TypeEvalContext ,
47- settings : PythonVariablesInlayTypeHintsProvider .Settings
48- ): Boolean = ! element.isQualified
49- },
50-
5130 GENERAL_HINT {
5231 override fun isApplicable (settings : PythonVariablesInlayTypeHintsProvider .Settings ) = true
5332
@@ -60,6 +39,10 @@ enum class HintResolver {
6039 val assignedValue = PyUtil .peelArgument(element.findAssignedValue())
6140
6241 if (assignedValue is PyPrefixExpression ) {
42+ if (assignedValue.operator == PyTokenTypes .AWAIT_KEYWORD ) {
43+ return shouldShowTypeHint(element, typeEvalContext)
44+ }
45+
6346 return shouldShowTypeHint(assignedValue.operand as PyElement , typeEvalContext)
6447 }
6548
@@ -76,9 +59,13 @@ enum class HintResolver {
7659 typeEvalContext : TypeEvalContext ,
7760 settings : PythonVariablesInlayTypeHintsProvider .Settings
7861 ): Boolean {
62+ val assignedValue = PyUtil .peelArgument(element.findAssignedValue())
63+
64+ // Handle case `var = async_func()` without `await` keyword
65+ if (assignedValue is PyCallExpression ) return true
66+
7967 if (typeAnnotation is PyClassType && isElementInsideTypingModule(typeAnnotation.pyClass)) return false
8068
81- val assignedValue = PyUtil .peelArgument(element.findAssignedValue())
8269
8370 if (assignedValue is PySubscriptionExpression ) {
8471 assignedValue.rootOperand.reference?.resolve()?.let {
@@ -401,9 +388,10 @@ enum class HintResolver {
401388 }
402389
403390 private fun isElementInsideTypingModule (element : PyElement ): Boolean {
404- PyUtil .getContainingPyFile(element)?.let {
405- return it.name == " ${PyTypingTypeProvider .TYPING }${PyNames .DOT_PYI } "
406- || it.name == " typing_extensions${PyNames .DOT_PY } "
391+ if (element is PyQualifiedNameOwner ) {
392+ element.qualifiedName?.let {
393+ return it.startsWith(" ${PyTypingTypeProvider .TYPING } ." ) || it.startsWith(" typing_extensions." )
394+ }
407395 }
408396
409397 return false
@@ -416,7 +404,13 @@ enum class HintResolver {
416404 return null
417405 }
418406
419- fun shouldShowTypeHint (element : PyElement , typeEvalContext : TypeEvalContext ): Boolean {
407+ fun shouldShowTypeHint (
408+ element : PyElement ,
409+ typeEvalContext : TypeEvalContext
410+ ): Boolean {
411+ if (element.name == PyNames .UNDERSCORE ) return false
412+ if (element is PyTargetExpression && element.isQualified) return false
413+
420414 val typeAnnotation = getExpressionAnnotationType(element, typeEvalContext)
421415
422416 if (
0 commit comments