[python] add some nullability annotations to resolve functions

GitOrigin-RevId: e2f9fb1a427aed1910a7aacac3de6d39b8ebb953
This commit is contained in:
Morgan Bartholomew
2025-06-25 17:26:34 +02:00
committed by intellij-monorepo-bot
parent a9cbe23fe3
commit 0ead2f713d
5 changed files with 10 additions and 11 deletions

View File

@@ -41,8 +41,8 @@ class PyFunctoolsWrapsDecoratedFunctionTypeProvider : PyTypeProviderBase() {
return StubAwareComputation.on(decorator)
.withCustomStub { it.getCustomStub(PyFunctoolsWrapsDecoratorStub::class.java) }
.overStub {
if (it == null) return@overStub emptyList<PsiElement>()
var scopeOwner = ScopeUtil.getScopeOwner(decorator)
if (it == null) return@overStub emptyList()
val scopeOwner = ScopeUtil.getScopeOwner(decorator)
val wrappedQName = QualifiedName.fromDottedString(it.wrapped)
PyResolveUtil.resolveQualifiedNameInScope(wrappedQName, scopeOwner!!, context)
}

View File

@@ -140,7 +140,7 @@ class PyFinalInspection : PyInspection() {
}
if (isFinal(node) && PyUtil.multiResolveTopPriority(node, resolveContext).any {
it != node && !PyDefUseUtil.isDefinedBefore(node, it)
it != node && !PyDefUseUtil.isDefinedBefore(node, it!!)
}) {
registerProblem(node, PyPsiBundle.message("INSP.final.already.declared.name.could.not.be.redefined.as.final"))
}

View File

@@ -446,11 +446,10 @@ public final class PyUtil {
return currentElement;
}
/**
* Note that returned list may contain {@code null} items, e.g. for unresolved import elements, originally wrapped
* in {@link com.jetbrains.python.psi.resolve.ImportedResolveResult}.
*/
public static @NotNull List<PsiElement> multiResolveTopPriority(@NotNull PsiElement element, @NotNull PyResolveContext resolveContext) {
// Note that returned list may contain null items, e.g. for unresolved import elements, originally wrapped
// in `com.jetbrains.python.psi.resolve.ImportedResolveResult`
// TODO: it would be a good idea to revise `filterTopPriority` to return the import definer when the element is null
public static @NotNull List<@Nullable PsiElement> multiResolveTopPriority(@NotNull PsiElement element, @NotNull PyResolveContext resolveContext) {
if (element instanceof PyReferenceOwner referenceOwner) {
return multiResolveTopPriority(referenceOwner.getReference(resolveContext));
}
@@ -460,7 +459,7 @@ public final class PyUtil {
}
}
public static @NotNull List<PsiElement> multiResolveTopPriority(@NotNull PsiPolyVariantReference reference) {
public static @NotNull List<@NotNull PsiElement> multiResolveTopPriority(@NotNull PsiPolyVariantReference reference) {
return filterTopPriorityElements(Arrays.asList(reference.multiResolve(false)));
}

View File

@@ -25,7 +25,7 @@ import java.util.Objects;
public class ImportedResolveResult extends RatedResolveResult {
private final @Nullable PyImportedNameDefiner myDefiner;
public ImportedResolveResult(PsiElement element, int rate, @Nullable PyImportedNameDefiner definer) {
public ImportedResolveResult(@Nullable PsiElement element, int rate, @Nullable PyImportedNameDefiner definer) {
super(rate, element);
myDefiner = definer;
}

View File

@@ -235,7 +235,7 @@ class PyLiteralType private constructor(cls: PyClass, val expression: PyExpressi
private fun literalType(expression: PyExpression, context: TypeEvalContext, index: Boolean): PyLiteralType? {
if (expression is PyReferenceExpression && expression.isQualified) {
val type = PyUtil.multiResolveTopPriority(expression, PyResolveContext.defaultContext(context)).firstNotNullOfOrNull {
PyStdlibTypeProvider.getEnumMemberType(it, context)
PyStdlibTypeProvider.getEnumMemberType(it!!, context)
}
if (type != null) {
return type