-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PY-39384: Introduce PyTypeHintProvider
`PyTypeHintProvider` allows providing type hints for resolved elements before the main logic of `PyTypingTypeProvider`. See an example of `django-stubs`: typeddjango/django-stubs#2335. `_UserModel` type might be replaced with a custom user model, provided in `settings.py` (`AUTH_USER_MODEL`). GitOrigin-RevId: 986fb91c800be3ccfbc002c73c673896efec8a1a
- Loading branch information
1 parent
45a808f
commit e044f9e
Showing
3 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
python/python-psi-impl/src/com/jetbrains/python/codeInsight/typing/PyTypeHintProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.jetbrains.python.codeInsight.typing | ||
|
||
import com.intellij.openapi.extensions.ExtensionPointName | ||
import com.intellij.openapi.util.Ref | ||
import com.intellij.psi.PsiElement | ||
import com.jetbrains.python.psi.PyExpression | ||
import com.jetbrains.python.psi.PyQualifiedNameOwner | ||
import com.jetbrains.python.psi.types.PyType | ||
import com.jetbrains.python.psi.types.TypeEvalContext | ||
import org.jetbrains.annotations.ApiStatus | ||
import org.jetbrains.annotations.ApiStatus.Experimental | ||
|
||
@Experimental | ||
@ApiStatus.Internal | ||
interface PyTypeHintProvider { | ||
fun parseTypeHint(typeHint: PyExpression, alias: PyQualifiedNameOwner?, resolved: PsiElement, context: TypeEvalContext): Ref<PyType>? | ||
|
||
companion object { | ||
private val EP_NAME: ExtensionPointName<PyTypeHintProvider> = ExtensionPointName.create("Pythonid.typeHintProvider"); | ||
|
||
fun parseTypeHint(typeHint: PyExpression, alias: PyQualifiedNameOwner?, resolved: PsiElement, context: TypeEvalContext): Ref<PyType>? { | ||
return EP_NAME.extensionList.firstNotNullOfOrNull { it.parseTypeHint(typeHint, alias, resolved, context) } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters