diff --git a/python/src/com/jetbrains/python/psi/PyUtil.java b/python/src/com/jetbrains/python/psi/PyUtil.java index 69d1bbee217a..fd46dfc45620 100644 --- a/python/src/com/jetbrains/python/psi/PyUtil.java +++ b/python/src/com/jetbrains/python/psi/PyUtil.java @@ -843,7 +843,17 @@ public class PyUtil { }); } - public static T getParameterizedCachedValue(@NotNull PsiElement element, @Nullable P param, @NotNull NullableFunction f) { + @NotNull + public static T getParameterizedCachedValue(@NotNull PsiElement element, @Nullable P param, @NotNull NotNullFunction f) { + final T result = getNullableParameterizedCachedValue(element, param, f); + assert result != null; + return result; + } + + @Nullable + public static T getNullableParameterizedCachedValue(@NotNull PsiElement element, + @Nullable P param, + @NotNull NullableFunction f) { final CachedValuesManager manager = CachedValuesManager.getManager(element.getProject()); final Map, Optional> cache = CachedValuesManager.getCachedValue(element, manager.getKeyForClass(f.getClass()), () -> { // concurrent hash map is a null-hostile collection @@ -899,7 +909,7 @@ public class PyUtil { /** * Returns the line comment that immediately precedes statement list of the given compound statement. Python parser ensures - * that it follows the statement header, i.e. it's directly after the colon, not on its own line. + * that it follows the statement header, i.e. it's directly after the colon, not on its own line. */ @Nullable public static PsiComment getCommentOnHeaderLine(@NotNull PyStatementListContainer container) { diff --git a/python/src/com/jetbrains/python/psi/impl/PyClassImpl.java b/python/src/com/jetbrains/python/psi/impl/PyClassImpl.java index 12b94e464ab3..4593c7ac59a8 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyClassImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyClassImpl.java @@ -79,7 +79,7 @@ public class PyClassImpl extends PyBaseElementImpl implements PyCla /** * Engine to create list of ancestors based on context */ - private final class CachedAncestorsProvider implements NullableFunction> { + private final class CachedAncestorsProvider implements NotNullFunction> { @NotNull @Override public List fun(@NotNull TypeEvalContext context) { diff --git a/python/src/com/jetbrains/python/psi/resolve/QualifiedNameFinder.java b/python/src/com/jetbrains/python/psi/resolve/QualifiedNameFinder.java index f444fa1ff017..ec11883b185d 100644 --- a/python/src/com/jetbrains/python/psi/resolve/QualifiedNameFinder.java +++ b/python/src/com/jetbrains/python/psi/resolve/QualifiedNameFinder.java @@ -115,7 +115,7 @@ public class QualifiedNameFinder { */ @Nullable public static QualifiedName findCanonicalImportPath(@NotNull PsiElement symbol, @Nullable PsiElement foothold) { - return PyUtil.getParameterizedCachedValue(symbol, Couple.of(symbol, foothold), QualifiedNameFinder::doFindCanonicalImportPath); + return PyUtil.getNullableParameterizedCachedValue(symbol, Couple.of(symbol, foothold), QualifiedNameFinder::doFindCanonicalImportPath); } @Nullable