misc python: get type utility methods

- add `getType` to `PyTypedElement`
- add `getReturnType` to `PyCallable`

(cherry picked from commit 06e35cd6e1617633f24e39936a02b6885d599b9b)

GitOrigin-RevId: 6917596e19be70904725e6c79957a3ed8462c894
This commit is contained in:
Morgan Bartholomew
2026-03-23 04:40:25 +00:00
committed by intellij-monorepo-bot
parent 36c06f459c
commit 5d241e05ff
3 changed files with 16 additions and 19 deletions
@@ -1,4 +1,4 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.psi;
import com.jetbrains.python.ast.PyAstCallable;
@@ -33,6 +33,13 @@ public interface PyCallable extends PyAstCallable, PyTypedElement, PyQualifiedNa
@NotNull
List<PyCallableParameter> getParameters(@NotNull TypeEvalContext context);
/**
* Returns the return type of the callable independent of a call site.
*/
default PyType getReturnType(@NotNull TypeEvalContext context) {
return context.getReturnType(this);
}
/**
* Returns the return type of the callable independent of a call site.
*/
@@ -1,4 +1,4 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.psi;
import com.intellij.psi.PsiElement;
@@ -375,8 +375,8 @@ public interface PyClass
* @param context eval context
* @return {@link PyType} casted if it has right type
*/
@Nullable
PyClassLikeType getType(@NotNull TypeEvalContext context);
@Override
@Nullable PyClassLikeType getType(@NotNull TypeEvalContext context);
@Override
default @Nullable PyStringLiteralExpression getDocStringExpression() {
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.psi;
import com.jetbrains.python.ast.PyAstTypedElement;
@@ -26,6 +12,10 @@ import org.jetbrains.annotations.Nullable;
*
*/
public interface PyTypedElement extends PyAstTypedElement, PyElement {
default @Nullable PyType getType(@NotNull TypeEvalContext context) {
return context.getType(this);
}
@Nullable
PyType getType(@NotNull TypeEvalContext context, @NotNull TypeEvalContext.Key key);
}