diff --git a/python/psi-api/src/com/jetbrains/python/codeInsight/PyDynamicMember.java b/python/psi-api/src/com/jetbrains/python/codeInsight/PyDynamicMember.java index a7a87892fe77..3e5e117a30eb 100644 --- a/python/psi-api/src/com/jetbrains/python/codeInsight/PyDynamicMember.java +++ b/python/psi-api/src/com/jetbrains/python/codeInsight/PyDynamicMember.java @@ -177,7 +177,7 @@ public class PyDynamicMember { myContext = context; } - public PyType getType(@NotNull TypeEvalContext context) { + public PyType getType(@NotNull TypeEvalContext context, @NotNull TypeEvalContext.Key key) { if (myTypeCallback != null) { return myTypeCallback.fun(myContext); } diff --git a/python/psi-api/src/com/jetbrains/python/psi/PyTypedElement.java b/python/psi-api/src/com/jetbrains/python/psi/PyTypedElement.java index aedbf201152b..deeba1b60c19 100644 --- a/python/psi-api/src/com/jetbrains/python/psi/PyTypedElement.java +++ b/python/psi-api/src/com/jetbrains/python/psi/PyTypedElement.java @@ -12,5 +12,5 @@ import org.jetbrains.annotations.Nullable; */ public interface PyTypedElement extends PyElement { @Nullable - PyType getType(@NotNull TypeEvalContext context); + PyType getType(@NotNull TypeEvalContext context, @NotNull TypeEvalContext.Key key); } diff --git a/python/psi-api/src/com/jetbrains/python/psi/types/PyTypeProviderBase.java b/python/psi-api/src/com/jetbrains/python/psi/types/PyTypeProviderBase.java index ed347a8183df..81988147bd01 100644 --- a/python/psi-api/src/com/jetbrains/python/psi/types/PyTypeProviderBase.java +++ b/python/psi-api/src/com/jetbrains/python/psi/types/PyTypeProviderBase.java @@ -37,7 +37,7 @@ public class PyTypeProviderBase implements PyTypeProvider { final ReturnTypeCallback typeCallback = myStringToReturnTypeMap.get(containingClass.getQualifiedName()); if (typeCallback != null) { final PyExpression qualifier = callSite != null ? callSite.getQualifier() : null; - PyType qualifierType = qualifier != null ? qualifier.getType(context) : null; + PyType qualifierType = qualifier != null ? context.getType(qualifier) : null; return typeCallback.getType(callSite, qualifierType, context); } } diff --git a/python/psi-api/src/com/jetbrains/python/psi/types/TypeEvalContext.java b/python/psi-api/src/com/jetbrains/python/psi/types/TypeEvalContext.java index 36de8388619b..ea5844ecc62b 100644 --- a/python/psi-api/src/com/jetbrains/python/psi/types/TypeEvalContext.java +++ b/python/psi-api/src/com/jetbrains/python/psi/types/TypeEvalContext.java @@ -14,6 +14,12 @@ import java.util.*; * @author yole */ public class TypeEvalContext { + public static class Key { + private static final Key INSTANCE = new Key(); + + private Key() {} + } + private final boolean myAllowDataFlow; private final boolean myAllowStubToAST; private List myTrace; @@ -116,7 +122,7 @@ public class TypeEvalContext { } evaluating.add(element); try { - PyType result = element.getType(this); + PyType result = element.getType(this, Key.INSTANCE); if (result != null) { result.assertValid(element.toString()); } diff --git a/python/src/com/jetbrains/python/codeInsight/completion/PyDictKeyNamesCompletionContributor.java b/python/src/com/jetbrains/python/codeInsight/completion/PyDictKeyNamesCompletionContributor.java index 27661b25a1d4..ee5c6a315ac8 100644 --- a/python/src/com/jetbrains/python/codeInsight/completion/PyDictKeyNamesCompletionContributor.java +++ b/python/src/com/jetbrains/python/codeInsight/completion/PyDictKeyNamesCompletionContributor.java @@ -115,7 +115,7 @@ public class PyDictKeyNamesCompletionContributor extends CompletionContributor { final String name = callee.getText(); if ("dict".equals(name)) { final TypeEvalContext context = TypeEvalContext.fast(); - final PyType type = dictConstructor.getType(context); + final PyType type = context.getType(dictConstructor); if (type != null && type.isBuiltin(context)) { final PyArgumentList list = dictConstructor.getArgumentList(); if (list == null) return; diff --git a/python/src/com/jetbrains/python/codeInsight/intentions/ImportFromToImportIntention.java b/python/src/com/jetbrains/python/codeInsight/intentions/ImportFromToImportIntention.java index 875ca8ed89bd..bb881905c74b 100644 --- a/python/src/com/jetbrains/python/codeInsight/intentions/ImportFromToImportIntention.java +++ b/python/src/com/jetbrains/python/codeInsight/intentions/ImportFromToImportIntention.java @@ -141,7 +141,7 @@ public class ImportFromToImportIntention implements IntentionAction { PyReferenceExpression ref = import_element.getImportReferenceExpression(); if (ref != null && ref.isValid()) { PsiElement target = ref.getReference().resolve(); - if (target instanceof PyExpression && ((PyExpression)target).getType(TypeEvalContext.fast()) instanceof PyModuleType) return false; + if (target instanceof PyExpression && TypeEvalContext.fast().getType((PyExpression)target) instanceof PyModuleType) return false; } } diff --git a/python/src/com/jetbrains/python/codeInsight/intentions/PyDictConstructorToLiteralFormIntention.java b/python/src/com/jetbrains/python/codeInsight/intentions/PyDictConstructorToLiteralFormIntention.java index 7bacf03016af..34634a3e03f3 100644 --- a/python/src/com/jetbrains/python/codeInsight/intentions/PyDictConstructorToLiteralFormIntention.java +++ b/python/src/com/jetbrains/python/codeInsight/intentions/PyDictConstructorToLiteralFormIntention.java @@ -38,7 +38,7 @@ public class PyDictConstructorToLiteralFormIntention extends BaseIntentionAction if (expression != null && expression.isCalleeText("dict")) { final TypeEvalContext context = TypeEvalContext.fast(); - PyType type = expression.getType(context); + PyType type = context.getType(expression); if (type != null && type.isBuiltin(context)) { PyExpression[] argumentList = expression.getArguments(); for (PyExpression argument : argumentList) { diff --git a/python/src/com/jetbrains/python/codeInsight/intentions/PyStringConcatenationToFormatIntention.java b/python/src/com/jetbrains/python/codeInsight/intentions/PyStringConcatenationToFormatIntention.java index b57ea1d698f2..690207bcb9f5 100644 --- a/python/src/com/jetbrains/python/codeInsight/intentions/PyStringConcatenationToFormatIntention.java +++ b/python/src/com/jetbrains/python/codeInsight/intentions/PyStringConcatenationToFormatIntention.java @@ -62,7 +62,7 @@ public class PyStringConcatenationToFormatIntention extends BaseIntentionAction } if (expression instanceof PyStringLiteralExpression) continue; - final PyType type = expression.getType(TypeEvalContext.fastStubOnly(file)); + final PyType type = TypeEvalContext.fastStubOnly(file).getType(expression); final boolean isStringReference = PyTypeChecker.match(cache.getStringType(LanguageLevel.forElement(expression)), type, TypeEvalContext.fastStubOnly(file)) && type != null; if (!isStringReference) { diff --git a/python/src/com/jetbrains/python/codeInsight/intentions/TypeAssertionIntention.java b/python/src/com/jetbrains/python/codeInsight/intentions/TypeAssertionIntention.java index 324cbca8b755..1dc1d8ca8309 100644 --- a/python/src/com/jetbrains/python/codeInsight/intentions/TypeAssertionIntention.java +++ b/python/src/com/jetbrains/python/codeInsight/intentions/TypeAssertionIntention.java @@ -59,7 +59,7 @@ public class TypeAssertionIntention implements IntentionAction { (reference != null && reference.resolve() == null)) { return false; } - final PyType type = problemElement.getType(TypeEvalContext.fastStubOnly(file)); + final PyType type = TypeEvalContext.fastStubOnly(file).getType(problemElement); return (type == null || type instanceof PyReturnTypeReference); } diff --git a/python/src/com/jetbrains/python/codeInsight/intentions/TypeIntention.java b/python/src/com/jetbrains/python/codeInsight/intentions/TypeIntention.java index c20cd4fc2e73..2b14c86a5bb2 100644 --- a/python/src/com/jetbrains/python/codeInsight/intentions/TypeIntention.java +++ b/python/src/com/jetbrains/python/codeInsight/intentions/TypeIntention.java @@ -68,7 +68,8 @@ public abstract class TypeIntention implements IntentionAction { protected abstract void updateText(boolean isReturn); private static boolean isTypeUndefined(PyExpression problemElement) { - final PyType type = problemElement.getType(TypeEvalContext.fastStubOnly(problemElement.getContainingFile())); + final TypeEvalContext context = TypeEvalContext.fastStubOnly(problemElement.getContainingFile()); + final PyType type = context.getType(problemElement); if (type == null || type instanceof PyReturnTypeReference || type instanceof PyDynamicallyEvaluatedType) { PsiReference reference = problemElement.getReference(); if (problemElement instanceof PyQualifiedExpression) { diff --git a/python/src/com/jetbrains/python/codeInsight/stdlib/PyStdlibTypeProvider.java b/python/src/com/jetbrains/python/codeInsight/stdlib/PyStdlibTypeProvider.java index da7968059431..9802764908e4 100644 --- a/python/src/com/jetbrains/python/codeInsight/stdlib/PyStdlibTypeProvider.java +++ b/python/src/com/jetbrains/python/codeInsight/stdlib/PyStdlibTypeProvider.java @@ -156,12 +156,12 @@ public class PyStdlibTypeProvider extends PyTypeProviderBase { if ("contextlib.closing".equals(contextManager.getQualifiedName()) && withExpression instanceof PyCallExpression) { PyExpression closee = ((PyCallExpression)withExpression).getArgument(0, PyExpression.class); if (closee != null) { - return closee.getType(context); + return context.getType(closee); } } final String name = contextManager.getName(); if ("FileIO".equals(name) || "TextIOWrapper".equals(name) || "IOBase".equals(name) || "_IOBase".equals(name)) { - return withExpression.getType(context); + return context.getType(withExpression); } return null; } @@ -191,7 +191,7 @@ public class PyStdlibTypeProvider extends PyTypeProviderBase { if (p.isPositionalContainer() || p.isKeywordContainer() || name == null) { continue; } - final PyType argType = entry.getKey().getType(context); + final PyType argType = context.getType(entry.getKey()); final PyType paramType = getParameterTypeByQName(overloadedQName, name, anchor); if (PyTypeChecker.match(paramType, argType, context)) { if (paramType != null && !PyTypeChecker.isUnknown(argType)) { diff --git a/python/src/com/jetbrains/python/documentation/DocStringTypeReference.java b/python/src/com/jetbrains/python/documentation/DocStringTypeReference.java index c005ced7c2b8..722d8e8168cc 100644 --- a/python/src/com/jetbrains/python/documentation/DocStringTypeReference.java +++ b/python/src/com/jetbrains/python/documentation/DocStringTypeReference.java @@ -113,7 +113,7 @@ public class DocStringTypeReference extends PsiPolyVariantReferenceBase body, PyReferenceExpression expression, @NotNull TypeEvalContext context) { - PyType type = expression.getType(context); + PyType type = context.getType(expression); describeTypeWithLinks(body, expression, type, context); } @@ -481,7 +481,7 @@ public class PythonDocumentationProvider extends AbstractDocumentationProvider i @Nullable private static PyClass inferClassOfParameter(PsiElement context) { if (context instanceof PyNamedParameter) { - final PyType type = ((PyNamedParameter)context).getType(TypeEvalContext.fast()); + final PyType type = TypeEvalContext.fast().getType((PyNamedParameter)context); if (type instanceof PyClassType) { return ((PyClassType)type).getPyClass(); } diff --git a/python/src/com/jetbrains/python/findUsages/PyUsageTypeProvider.java b/python/src/com/jetbrains/python/findUsages/PyUsageTypeProvider.java index 6314e6848bf3..8c3f64cd78c6 100644 --- a/python/src/com/jetbrains/python/findUsages/PyUsageTypeProvider.java +++ b/python/src/com/jetbrains/python/findUsages/PyUsageTypeProvider.java @@ -39,7 +39,7 @@ public class PyUsageTypeProvider implements UsageTypeProviderEx { if (element instanceof PyQualifiedExpression) { final PyExpression qualifier = ((PyQualifiedExpression)element).getQualifier(); if (qualifier != null) { - final PyType type = qualifier.getType(TypeEvalContext.fast()); + final PyType type = TypeEvalContext.fast().getType(qualifier); if (type == null || type instanceof PyTypeReference) { final PyCallExpression call = PsiTreeUtil.getParentOfType(element, PyCallExpression.class); if (call != null && element == call.getCallee()) { diff --git a/python/src/com/jetbrains/python/inspections/PyAugmentAssignmentInspection.java b/python/src/com/jetbrains/python/inspections/PyAugmentAssignmentInspection.java index 323730bcbb25..6e139c1e1d80 100644 --- a/python/src/com/jetbrains/python/inspections/PyAugmentAssignmentInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyAugmentAssignmentInspection.java @@ -75,7 +75,7 @@ public class PyAugmentAssignmentInspection extends PyInspection { registerProblem(node, "Assignment can be replaced with augmented assignment", quickFix); } else { - final PyType type = rightExpression.getType(myTypeEvalContext); + final PyType type = myTypeEvalContext.getType(rightExpression); if (type != null) { final PyBuiltinCache cache = PyBuiltinCache.getInstance(rightExpression); if (PyTypeChecker.match(cache.getComplexType(), type, myTypeEvalContext) || diff --git a/python/src/com/jetbrains/python/inspections/PyBroadExceptionInspection.java b/python/src/com/jetbrains/python/inspections/PyBroadExceptionInspection.java index 33d60b068516..42cf00554ddb 100644 --- a/python/src/com/jetbrains/python/inspections/PyBroadExceptionInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyBroadExceptionInspection.java @@ -38,7 +38,7 @@ public class PyBroadExceptionInspection extends PyInspection { } public static boolean equalsException(@NotNull PyClass cls, @NotNull TypeEvalContext context) { - final PyType type = cls.getType(context); + final PyType type = context.getType(cls); return "Exception".equals(cls.getName()) && type != null && type.isBuiltin(context); } @@ -56,7 +56,7 @@ public class PyBroadExceptionInspection extends PyInspection { registerProblem(node.getFirstChild(), "Too broad exception clause"); } if (exceptClass != null) { - final PyType type = exceptClass.getType(myTypeEvalContext); + final PyType type = myTypeEvalContext.getType(exceptClass); if (type instanceof PyClassType) { final PyClass cls = ((PyClassType)type).getPyClass(); final PyExpression target = node.getTarget(); diff --git a/python/src/com/jetbrains/python/inspections/PyCallingNonCallableInspection.java b/python/src/com/jetbrains/python/inspections/PyCallingNonCallableInspection.java index 366b9d075cc9..dfaabb94bd98 100644 --- a/python/src/com/jetbrains/python/inspections/PyCallingNonCallableInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyCallingNonCallableInspection.java @@ -58,7 +58,7 @@ public class PyCallingNonCallableInspection extends PyInspection { return; } if (!callable) { - final PyType calleeType = callee != null ? callee.getType(myTypeEvalContext) : type; + final PyType calleeType = callee != null ? myTypeEvalContext.getType(callee) : type; if (calleeType instanceof PyClassType) { registerProblem(node, String.format("'%s' object is not callable", calleeType.getName())); } @@ -77,6 +77,6 @@ public class PyCallingNonCallableInspection extends PyInspection { if (element instanceof PyQualifiedExpression && PyNames.CLASS.equals(element.getName())) { return true; } - return PyTypeChecker.isCallable(element.getType(context)); + return PyTypeChecker.isCallable(context.getType(element)); } } diff --git a/python/src/com/jetbrains/python/inspections/PyPropertyDefinitionInspection.java b/python/src/com/jetbrains/python/inspections/PyPropertyDefinitionInspection.java index 4e751db39380..d46900231ca2 100644 --- a/python/src/com/jetbrains/python/inspections/PyPropertyDefinitionInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyPropertyDefinitionInspection.java @@ -171,7 +171,7 @@ public class PyPropertyDefinitionInspection extends PyInspection { return; } if (resolved instanceof PyTypedElement) { - final PyType type = ((PyTypedElement)resolved).getType(myTypeEvalContext); + final PyType type = myTypeEvalContext.getType((PyTypedElement)resolved); final Boolean isCallable = PyTypeChecker.isCallable(type); if (isCallable != null && !isCallable) { registerProblem(element, PyBundle.message("INSP.strange.arg.want.callable")); diff --git a/python/src/com/jetbrains/python/inspections/PyStringFormatInspection.java b/python/src/com/jetbrains/python/inspections/PyStringFormatInspection.java index 17638d594639..b7c46583b787 100644 --- a/python/src/com/jetbrains/python/inspections/PyStringFormatInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyStringFormatInspection.java @@ -182,7 +182,7 @@ public class PyStringFormatInspection extends PyInspection { } } else if (rightExpression instanceof PySliceExpression && s != null) { - final PyType type = ((PySliceExpression)rightExpression).getOperand().getType(myTypeEvalContext); + final PyType type = myTypeEvalContext.getType(((PySliceExpression)rightExpression).getOperand()); if (type == null || "list".equals(type.getName()) || "str".equals(type.getName())) { checkTypeCompatible(problemTarget, builtinCache.getStrType(), PyTypeParser.getTypeByName(problemTarget, s)); diff --git a/python/src/com/jetbrains/python/inspections/PySuperArgumentsInspection.java b/python/src/com/jetbrains/python/inspections/PySuperArgumentsInspection.java index 809ce6001739..f51a570e081b 100644 --- a/python/src/com/jetbrains/python/inspections/PySuperArgumentsInspection.java +++ b/python/src/com/jetbrains/python/inspections/PySuperArgumentsInspection.java @@ -70,7 +70,7 @@ public class PySuperArgumentsInspection extends PyInspection { PyClass firstClass = null; if (firstElement instanceof PyClass) firstClass = (PyClass)firstElement; else if (firstElement instanceof PyExpression) { - PyType first_type = ((PyExpression)firstElement).getType(myTypeEvalContext); + PyType first_type = myTypeEvalContext.getType((PyExpression)firstElement); if (first_type instanceof PyClassType) { firstClass = ((PyClassType)first_type).getPyClass(); } diff --git a/python/src/com/jetbrains/python/inspections/PyTupleAssignmentBalanceInspection.java b/python/src/com/jetbrains/python/inspections/PyTupleAssignmentBalanceInspection.java index 9ca11ac7b5c9..c024638cd615 100644 --- a/python/src/com/jetbrains/python/inspections/PyTupleAssignmentBalanceInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyTupleAssignmentBalanceInspection.java @@ -45,7 +45,7 @@ public class PyTupleAssignmentBalanceInspection extends PyInspection { lhsExpression = ((PyParenthesizedExpression)lhsExpression).getContainedExpression(); if (assignedValue == null) return; - PyType type = assignedValue.getType(myTypeEvalContext); + PyType type = myTypeEvalContext.getType(assignedValue); if (assignedValue instanceof PyReferenceExpression && !(type instanceof PyTupleType)) return; if (lhsExpression instanceof PyTupleExpression && type != null && !(type instanceof PyReturnTypeReference)){ int valuesLength = PyUtil.getElementsCount(assignedValue, myTypeEvalContext); diff --git a/python/src/com/jetbrains/python/inspections/PyTypeCheckerInspection.java b/python/src/com/jetbrains/python/inspections/PyTypeCheckerInspection.java index 8be02c241f58..5b51beb6b42a 100644 --- a/python/src/com/jetbrains/python/inspections/PyTypeCheckerInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyTypeCheckerInspection.java @@ -71,8 +71,8 @@ public class PyTypeCheckerInspection extends PyInspection { // TODO: Support *args, **kwargs continue; } - final PyType argType = entry.getKey().getType(myTypeEvalContext); - final PyType paramType = p.getType(myTypeEvalContext); + final PyType argType = myTypeEvalContext.getType(entry.getKey()); + final PyType paramType = myTypeEvalContext.getType(p); checkTypes(paramType, argType, entry.getKey(), myTypeEvalContext, substitutions); } } diff --git a/python/src/com/jetbrains/python/inspections/PyUnresolvedReferencesInspection.java b/python/src/com/jetbrains/python/inspections/PyUnresolvedReferencesInspection.java index 434093821767..715e6de3e73b 100644 --- a/python/src/com/jetbrains/python/inspections/PyUnresolvedReferencesInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyUnresolvedReferencesInspection.java @@ -574,7 +574,7 @@ public class PyUnresolvedReferencesInspection extends PyInspection { if (reference instanceof PyOperatorReference && element instanceof PyQualifiedExpression) { final PyExpression receiver = ((PyOperatorReference)reference).getReceiver(); if (receiver != null) { - final PyType type = receiver.getType(context); + final PyType type = context.getType(receiver); if (type instanceof PyClassType) { final String name = ((PyClassType)type).getClassQName(); if (name != null) { @@ -589,7 +589,7 @@ public class PyUnresolvedReferencesInspection extends PyInspection { final String exprName = expr.getName(); if (exprName != null) { if (qualifier != null) { - final PyType type = qualifier.getType(context); + final PyType type = context.getType(qualifier); if (type instanceof PyClassType) { final String name = ((PyClassType)type).getClassQName(); if (name != null) { @@ -810,7 +810,7 @@ public class PyUnresolvedReferencesInspection extends PyInspection { @Nullable private static PsiElement resolveClassMember(@NotNull PyClass cls, @NotNull String name) { final TypeEvalContext context = TypeEvalContext.fastStubOnly(null); - final PyType type = cls.getType(context); + final PyType type = context.getType(cls); if (type != null) { final List results = type.resolveMember(name, null, AccessDirection.READ, PyResolveContext.noImplicits().withTypeEvalContext(context)); diff --git a/python/src/com/jetbrains/python/inspections/quickfix/AddMethodQuickFix.java b/python/src/com/jetbrains/python/inspections/quickfix/AddMethodQuickFix.java index 5997138b0055..c855bd32c94a 100644 --- a/python/src/com/jetbrains/python/inspections/quickfix/AddMethodQuickFix.java +++ b/python/src/com/jetbrains/python/inspections/quickfix/AddMethodQuickFix.java @@ -69,7 +69,7 @@ public class AddMethodQuickFix implements LocalQuickFix { boolean made_instance = false; if (call_by_class) { if (args.length > 0) { - PyType first_arg_type = args[0].getType(TypeEvalContext.fast()); + PyType first_arg_type = TypeEvalContext.fast().getType(args[0]); if (first_arg_type instanceof PyClassType && ((PyClassType)first_arg_type).getPyClass().isSubclass(cls)) { // class, first arg ok: instance method builder.parameter("self"); // NOTE: might use a name other than 'self', according to code style. diff --git a/python/src/com/jetbrains/python/psi/PyUtil.java b/python/src/com/jetbrains/python/psi/PyUtil.java index c31172bfe239..4e26ba30eaa7 100644 --- a/python/src/com/jetbrains/python/psi/PyUtil.java +++ b/python/src/com/jetbrains/python/psi/PyUtil.java @@ -1065,7 +1065,7 @@ public class PyUtil { */ public static int getElementsCount(PyExpression expression, TypeEvalContext evalContext) { int valuesLength = -1; - PyType type = expression.getType(evalContext); + PyType type = evalContext.getType(expression); if (type instanceof PyTupleType) { valuesLength = ((PyTupleType)type).getElementCount(); } diff --git a/python/src/com/jetbrains/python/psi/impl/PyBinaryExpressionImpl.java b/python/src/com/jetbrains/python/psi/impl/PyBinaryExpressionImpl.java index 1b5e21df8f3a..68cef9705ebf 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyBinaryExpressionImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyBinaryExpressionImpl.java @@ -108,7 +108,7 @@ public class PyBinaryExpressionImpl extends PyElementImpl implements PyBinaryExp return new PyOperatorReference(this, context); } - public PyType getType(@NotNull TypeEvalContext context) { + public PyType getType(@NotNull TypeEvalContext context, @NotNull TypeEvalContext.Key key) { final PyTypeChecker.AnalyzeCallResults results = PyTypeChecker.analyzeCall(this, context); if (results != null) { final PyType type = results.getCallable().getReturnType(context, this); diff --git a/python/src/com/jetbrains/python/psi/impl/PyBoolLiteralExpressionImpl.java b/python/src/com/jetbrains/python/psi/impl/PyBoolLiteralExpressionImpl.java index af6dd0090f52..497611ac73d3 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyBoolLiteralExpressionImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyBoolLiteralExpressionImpl.java @@ -15,7 +15,7 @@ public class PyBoolLiteralExpressionImpl extends PyElementImpl implements PyBool super(astNode); } - public PyType getType(@NotNull TypeEvalContext context) { + public PyType getType(@NotNull TypeEvalContext context, @NotNull TypeEvalContext.Key key) { return PyBuiltinCache.getInstance(this).getBoolType(); } diff --git a/python/src/com/jetbrains/python/psi/impl/PyCallExpressionHelper.java b/python/src/com/jetbrains/python/psi/impl/PyCallExpressionHelper.java index aea70b28e570..f7b87c4ef41f 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyCallExpressionHelper.java +++ b/python/src/com/jetbrains/python/psi/impl/PyCallExpressionHelper.java @@ -360,12 +360,12 @@ public class PyCallExpressionHelper { final PyExpression[] args = call.getArguments(); if (args.length == 1) { final PyExpression arg = args[0]; - final PyType argType = arg.getType(context); + final PyType argType = context.getType(arg); if (argType instanceof PyClassType) { final PyClassType classType = (PyClassType)argType; if (!classType.isDefinition()) { final PyClass cls = classType.getPyClass(); - return cls.getType(context); + return context.getType(cls); } } else { diff --git a/python/src/com/jetbrains/python/psi/impl/PyCallExpressionImpl.java b/python/src/com/jetbrains/python/psi/impl/PyCallExpressionImpl.java index b8d0fcb1cb0f..0fa29df39d2b 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyCallExpressionImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyCallExpressionImpl.java @@ -87,7 +87,7 @@ public class PyCallExpressionImpl extends PyElementImpl implements PyCallExpress return "PyCallExpression: " + PyUtil.getReadableRepr(getCallee(), true); //or: getCalledFunctionReference().getReferencedName(); } - public PyType getType(@NotNull TypeEvalContext context) { + public PyType getType(@NotNull TypeEvalContext context, @NotNull TypeEvalContext.Key key) { return PyCallExpressionHelper.getCallType(this, context); } } diff --git a/python/src/com/jetbrains/python/psi/impl/PyClassImpl.java b/python/src/com/jetbrains/python/psi/impl/PyClassImpl.java index 1c9e818fe85e..eabaa37e163a 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyClassImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyClassImpl.java @@ -55,7 +55,7 @@ public class PyClassImpl extends PyPresentableElementImpl implement private volatile Map myPropertyCache; @Override - public PyType getType(@NotNull TypeEvalContext context) { + public PyType getType(@NotNull TypeEvalContext context, @NotNull TypeEvalContext.Key key) { return new PyClassTypeImpl(this, true); } @@ -276,7 +276,7 @@ public class PyClassImpl extends PyPresentableElementImpl implement result.add(new PyClassRef(element)); } else { - final PyType type = expression.getType(context); + final PyType type = context.getType(expression); if (type instanceof PyClassType) { result.add(new PyClassRef((PyClassType)type)); } diff --git a/python/src/com/jetbrains/python/psi/impl/PyConditionalExpressionImpl.java b/python/src/com/jetbrains/python/psi/impl/PyConditionalExpressionImpl.java index 061b3c5117cb..4fb67b3b1fca 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyConditionalExpressionImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyConditionalExpressionImpl.java @@ -20,7 +20,7 @@ public class PyConditionalExpressionImpl extends PyElementImpl implements PyCond super(astNode); } - public PyType getType(@NotNull TypeEvalContext context) { + public PyType getType(@NotNull TypeEvalContext context, @NotNull TypeEvalContext.Key key) { final PyExpression truePart = getTruePart(); final PyExpression falsePart = getFalsePart(); if (truePart == null || falsePart == null) { diff --git a/python/src/com/jetbrains/python/psi/impl/PyDecoratorImpl.java b/python/src/com/jetbrains/python/psi/impl/PyDecoratorImpl.java index b0c5d37004bd..05bee8401122 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyDecoratorImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyDecoratorImpl.java @@ -166,7 +166,7 @@ public class PyDecoratorImpl extends StubBasedPsiElementBase im } } - public PyType getType(@NotNull TypeEvalContext context) { + public PyType getType(@NotNull TypeEvalContext context, @NotNull TypeEvalContext.Key key) { return PyCallExpressionHelper.getCallType(this, context); } } diff --git a/python/src/com/jetbrains/python/psi/impl/PyDictCompExpressionImpl.java b/python/src/com/jetbrains/python/psi/impl/PyDictCompExpressionImpl.java index 37b010313f4f..48bdd9d46e0f 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyDictCompExpressionImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyDictCompExpressionImpl.java @@ -15,7 +15,7 @@ public class PyDictCompExpressionImpl extends PyComprehensionElementImpl impleme super(astNode); } - public PyType getType(@NotNull TypeEvalContext context) { + public PyType getType(@NotNull TypeEvalContext context, @NotNull TypeEvalContext.Key key) { return PyBuiltinCache.getInstance(this).getDictType(); } diff --git a/python/src/com/jetbrains/python/psi/impl/PyDictLiteralExpressionImpl.java b/python/src/com/jetbrains/python/psi/impl/PyDictLiteralExpressionImpl.java index f5a507e6771f..7c66f1d195e6 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyDictLiteralExpressionImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyDictLiteralExpressionImpl.java @@ -22,7 +22,7 @@ public class PyDictLiteralExpressionImpl extends PyElementImpl implements PyDict return childrenToPsi(KEY_VALUE_EXPRESSIONS, PyKeyValueExpression.EMPTY_ARRAY); } - public PyType getType(@NotNull TypeEvalContext context) { + public PyType getType(@NotNull TypeEvalContext context, @NotNull TypeEvalContext.Key key) { return PyBuiltinCache.createLiteralCollectionType(this, "dict"); } diff --git a/python/src/com/jetbrains/python/psi/impl/PyEmptyExpressionImpl.java b/python/src/com/jetbrains/python/psi/impl/PyEmptyExpressionImpl.java index da14e03f08d0..32fbdd6fd62d 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyEmptyExpressionImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyEmptyExpressionImpl.java @@ -14,7 +14,7 @@ public class PyEmptyExpressionImpl extends PyElementImpl implements PyEmptyExpre super(astNode); } - public PyType getType(@NotNull TypeEvalContext context) { + public PyType getType(@NotNull TypeEvalContext context, @NotNull TypeEvalContext.Key key) { return null; } } diff --git a/python/src/com/jetbrains/python/psi/impl/PyFileImpl.java b/python/src/com/jetbrains/python/psi/impl/PyFileImpl.java index 4e23b2c6e93d..5408cd0b9aee 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyFileImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyFileImpl.java @@ -704,7 +704,7 @@ public class PyFileImpl extends PsiFileBase implements PyFile, PyExpression { } - public PyType getType(@NotNull TypeEvalContext context) { + public PyType getType(@NotNull TypeEvalContext context, @NotNull TypeEvalContext.Key key) { if (myType == null) myType = new PyModuleType(this); return myType; } diff --git a/python/src/com/jetbrains/python/psi/impl/PyFunctionImpl.java b/python/src/com/jetbrains/python/psi/impl/PyFunctionImpl.java index e15e43208c03..7edaf41d16da 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyFunctionImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyFunctionImpl.java @@ -193,7 +193,7 @@ public class PyFunctionImpl extends PyPresentableElementImpl imp private static boolean isDynamicallyEvaluated(@NotNull Collection parameters, @NotNull TypeEvalContext context) { for (PyNamedParameter parameter : parameters) { - final PyType type = parameter.getType(context); + final PyType type = context.getType(parameter); if (type instanceof PyDynamicallyEvaluatedType) { return true; } @@ -245,7 +245,7 @@ public class PyFunctionImpl extends PyPresentableElementImpl imp statements.accept(new PyRecursiveElementVisitor() { @Override public void visitPyYieldExpression(PyYieldExpression node) { - final PyType type = node.getType(context); + final PyType type = context.getType(node); if (node.isDelegating() && type instanceof PyCollectionType) { final PyCollectionType collectionType = (PyCollectionType)type; types.add(collectionType.getElementType(context)); @@ -330,7 +330,7 @@ public class PyFunctionImpl extends PyPresentableElementImpl imp } @Override - public PyType getType(@NotNull TypeEvalContext context) { + public PyType getType(@NotNull TypeEvalContext context, @NotNull TypeEvalContext.Key key) { final PyFunctionType type = new PyFunctionType(this); if (getDecoratorList() != null) { return PyUnionType.createWeakType(type); diff --git a/python/src/com/jetbrains/python/psi/impl/PyGeneratorExpressionImpl.java b/python/src/com/jetbrains/python/psi/impl/PyGeneratorExpressionImpl.java index 190a4eca6a13..8b8e91dc2db4 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyGeneratorExpressionImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyGeneratorExpressionImpl.java @@ -28,12 +28,12 @@ public class PyGeneratorExpressionImpl extends PyComprehensionElementImpl implem @Nullable @Override - public PyType getType(@NotNull TypeEvalContext context) { + public PyType getType(@NotNull TypeEvalContext context, @NotNull TypeEvalContext.Key key) { final PyExpression resultExpr = getResultExpression(); final PyBuiltinCache cache = PyBuiltinCache.getInstance(this); final PyClass generator = cache.getClass(PyNames.FAKE_GENERATOR); if (resultExpr != null && generator != null) { - final PyType elementType = resultExpr.getType(context); + final PyType elementType = context.getType(resultExpr); return new PyCollectionTypeImpl(generator, false, elementType); } return null; diff --git a/python/src/com/jetbrains/python/psi/impl/PyKeyValueExpressionImpl.java b/python/src/com/jetbrains/python/psi/impl/PyKeyValueExpressionImpl.java index 22fe2800c770..40acfb1959cf 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyKeyValueExpressionImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyKeyValueExpressionImpl.java @@ -18,12 +18,12 @@ public class PyKeyValueExpressionImpl extends PyElementImpl implements PyKeyValu super(astNode); } - public PyType getType(@NotNull TypeEvalContext context) { - final PyType keyType = getKey().getType(context); + public PyType getType(@NotNull TypeEvalContext context, @NotNull TypeEvalContext.Key key) { + final PyType keyType = context.getType(getKey()); final PyExpression value = getValue(); PyType valueType = null; if (value != null) { - valueType = value.getType(context); + valueType = context.getType(value); } return PyTupleType.create(this, new PyType[] {keyType, valueType}); } diff --git a/python/src/com/jetbrains/python/psi/impl/PyKeywordArgumentImpl.java b/python/src/com/jetbrains/python/psi/impl/PyKeywordArgumentImpl.java index 02cba3fe8e95..d43636eba7f4 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyKeywordArgumentImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyKeywordArgumentImpl.java @@ -42,9 +42,9 @@ public class PyKeywordArgumentImpl extends PyElementImpl implements PyKeywordArg return getClass().getSimpleName() + ": " + getKeyword(); } - public PyType getType(@NotNull TypeEvalContext context) { + public PyType getType(@NotNull TypeEvalContext context, @NotNull TypeEvalContext.Key key) { final PyExpression e = getValueExpression(); - return e != null ? e.getType(context) : null; + return e != null ? context.getType(e) : null; } @Override diff --git a/python/src/com/jetbrains/python/psi/impl/PyLambdaExpressionImpl.java b/python/src/com/jetbrains/python/psi/impl/PyLambdaExpressionImpl.java index 27380a9928fd..fc31ce2e21a3 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyLambdaExpressionImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyLambdaExpressionImpl.java @@ -23,7 +23,7 @@ public class PyLambdaExpressionImpl extends PyElementImpl implements PyLambdaExp pyVisitor.visitPyLambdaExpression(this); } - public PyType getType(@NotNull TypeEvalContext context) { + public PyType getType(@NotNull TypeEvalContext context, @NotNull TypeEvalContext.Key key) { return new PyFunctionType(this); } @@ -41,7 +41,7 @@ public class PyLambdaExpressionImpl extends PyElementImpl implements PyLambdaExp @Override public PyType getReturnType(@NotNull TypeEvalContext context, @Nullable PyQualifiedExpression callSite) { final PyExpression body = getBody(); - if (body != null) return body.getType(context); + if (body != null) return context.getType(body); else return null; } diff --git a/python/src/com/jetbrains/python/psi/impl/PyListCompExpressionImpl.java b/python/src/com/jetbrains/python/psi/impl/PyListCompExpressionImpl.java index 8e34c714795d..86ccc3e8dda7 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyListCompExpressionImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyListCompExpressionImpl.java @@ -26,12 +26,12 @@ public class PyListCompExpressionImpl extends PyComprehensionElementImpl impleme @Nullable @Override - public PyType getType(@NotNull TypeEvalContext context) { + public PyType getType(@NotNull TypeEvalContext context, @NotNull TypeEvalContext.Key key) { final PyExpression resultExpr = getResultExpression(); final PyBuiltinCache cache = PyBuiltinCache.getInstance(this); final PyClass list = cache.getClass("list"); if (resultExpr != null && list != null) { - final PyType elementType = resultExpr.getType(context); + final PyType elementType = context.getType(resultExpr); return new PyCollectionTypeImpl(list, false, elementType); } return cache.getListType(); diff --git a/python/src/com/jetbrains/python/psi/impl/PyListLiteralExpressionImpl.java b/python/src/com/jetbrains/python/psi/impl/PyListLiteralExpressionImpl.java index c3b49b4938b1..3992aa4026ab 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyListLiteralExpressionImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyListLiteralExpressionImpl.java @@ -70,7 +70,7 @@ public class PyListLiteralExpressionImpl extends PyElementImpl implements PyList } } - public PyType getType(@NotNull TypeEvalContext context) { + public PyType getType(@NotNull TypeEvalContext context, @NotNull TypeEvalContext.Key key) { return PyBuiltinCache.createLiteralCollectionType(this, "list"); } } diff --git a/python/src/com/jetbrains/python/psi/impl/PyNamedParameterImpl.java b/python/src/com/jetbrains/python/psi/impl/PyNamedParameterImpl.java index 846b6fd27509..7f16c71e37a3 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyNamedParameterImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyNamedParameterImpl.java @@ -153,7 +153,7 @@ public class PyNamedParameterImpl extends PyPresentableElementImpl nodes = getStringNodes(); if (nodes.size() > 0) { String text = getStringNodes().get(0).getText(); diff --git a/python/src/com/jetbrains/python/psi/impl/PySubscriptionExpressionImpl.java b/python/src/com/jetbrains/python/psi/impl/PySubscriptionExpressionImpl.java index 60656f93d531..2a85a5e1a891 100644 --- a/python/src/com/jetbrains/python/psi/impl/PySubscriptionExpressionImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PySubscriptionExpressionImpl.java @@ -38,7 +38,7 @@ public class PySubscriptionExpressionImpl extends PyElementImpl implements PySub @Nullable @Override - public PyType getType(@NotNull TypeEvalContext context) { + public PyType getType(@NotNull TypeEvalContext context, @NotNull TypeEvalContext.Key key) { PyType res = null; final PsiReference ref = getReference(PyResolveContext.noImplicits().withTypeEvalContext(context)); if (ref != null) { diff --git a/python/src/com/jetbrains/python/psi/impl/PyTargetExpressionImpl.java b/python/src/com/jetbrains/python/psi/impl/PyTargetExpressionImpl.java index 9c3d3de54f1f..117983e93c69 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyTargetExpressionImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyTargetExpressionImpl.java @@ -98,7 +98,7 @@ public class PyTargetExpressionImpl extends PyPresentableElementImpl results = type.resolveMember(name, null, AccessDirection.READ, PyResolveContext.noImplicits()); diff --git a/python/src/com/jetbrains/python/psi/impl/PyTupleExpressionImpl.java b/python/src/com/jetbrains/python/psi/impl/PyTupleExpressionImpl.java index 98f9cea9df95..274a47584093 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyTupleExpressionImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyTupleExpressionImpl.java @@ -31,7 +31,7 @@ public class PyTupleExpressionImpl extends PyElementImpl implements PyTupleExpre return childrenToPsi(PythonDialectsTokenSetProvider.INSTANCE.getExpressionTokens(), PyExpression.EMPTY_ARRAY); } - public PyType getType(@NotNull TypeEvalContext context) { + public PyType getType(@NotNull TypeEvalContext context, @NotNull TypeEvalContext.Key key) { final PyExpression[] elements = getElements(); final PyType[] types = new PyType[elements.length]; for (int i = 0; i < types.length; i++) { diff --git a/python/src/com/jetbrains/python/psi/impl/PyYieldExpressionImpl.java b/python/src/com/jetbrains/python/psi/impl/PyYieldExpressionImpl.java index 3a8fa6b4d98a..8c294178d191 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyYieldExpressionImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyYieldExpressionImpl.java @@ -34,8 +34,8 @@ public class PyYieldExpressionImpl extends PyElementImpl implements PyYieldExpre } @Override - public PyType getType(@NotNull TypeEvalContext context) { + public PyType getType(@NotNull TypeEvalContext context, @NotNull TypeEvalContext.Key key) { final PyExpression e = getExpression(); - return e != null ? e.getType(context) : null; + return e != null ? context.getType(e) : null; } } diff --git a/python/src/com/jetbrains/python/psi/impl/references/PyImportReference.java b/python/src/com/jetbrains/python/psi/impl/references/PyImportReference.java index 598960707eaa..cffc4a2790c2 100644 --- a/python/src/com/jetbrains/python/psi/impl/references/PyImportReference.java +++ b/python/src/com/jetbrains/python/psi/impl/references/PyImportReference.java @@ -83,7 +83,7 @@ public class PyImportReference extends PyReferenceImpl { PyExpression qualifier = myElement.getQualifier(); if (qualifier != null) { // qualifier's type must be module, it should know how to complete - PyType type = qualifier.getType(TypeEvalContext.fast()); + PyType type = TypeEvalContext.fast().getType(qualifier); if (type != null) { Object[] variants = getTypeCompletionVariants(myElement, type); if (!alreadyHasImportKeyword()) { @@ -177,7 +177,7 @@ public class PyImportReference extends PyReferenceImpl { addImportedNames(from_import.getImportElements()); // don't propose already imported items // try to collect submodules PyExpression module = (PyExpression)mod_candidate; - PyType qualifierType = module.getType(TypeEvalContext.fast()); + PyType qualifierType = TypeEvalContext.fast().getType(module); if (qualifierType != null) { ProcessingContext ctx = new ProcessingContext(); ctx.put(PyType.CTX_NAMES, myNamesAlready); diff --git a/python/src/com/jetbrains/python/psi/impl/references/PyQualifiedReference.java b/python/src/com/jetbrains/python/psi/impl/references/PyQualifiedReference.java index 2fdd1a0539b2..d1453add6411 100644 --- a/python/src/com/jetbrains/python/psi/impl/references/PyQualifiedReference.java +++ b/python/src/com/jetbrains/python/psi/impl/references/PyQualifiedReference.java @@ -242,7 +242,7 @@ public class PyQualifiedReference extends PyReferenceImpl { assert qualifier != null; final PyQualifiedExpression element = CompletionUtil.getOriginalOrSelf(myElement); - PyType qualifierType = qualifier.getType(TypeEvalContext.slow()); + PyType qualifierType = TypeEvalContext.slow().getType(qualifier); ProcessingContext ctx = new ProcessingContext(); final Set namesAlready = new HashSet(); ctx.put(PyType.CTX_NAMES, namesAlready); @@ -382,7 +382,7 @@ public class PyQualifiedReference extends PyReferenceImpl { final PyExpression qualifier = myElement.getQualifier(); if (qualifier != null) { final TypeEvalContext context = TypeEvalContext.fast(); - PyType qualifierType = qualifier.getType(context); + PyType qualifierType = context.getType(qualifier); if (qualifierType == null || qualifierType instanceof PyTypeReference) { return true; } diff --git a/python/src/com/jetbrains/python/psi/types/PyClassTypeImpl.java b/python/src/com/jetbrains/python/psi/types/PyClassTypeImpl.java index 7dfd2861482f..631856cbee4b 100644 --- a/python/src/com/jetbrains/python/psi/types/PyClassTypeImpl.java +++ b/python/src/com/jetbrains/python/psi/types/PyClassTypeImpl.java @@ -136,7 +136,7 @@ public class PyClassTypeImpl extends UserDataHolderBase implements PyClassType { // methods of super() call are not of class super! PyExpression first_arg = ((PyCallExpression)location).getArgument(0, PyExpression.class); if (first_arg != null) { // the usual case: first arg is the derived class that super() is proxying for - PyType first_arg_type = first_arg.getType(resolveContext.getTypeEvalContext()); + PyType first_arg_type = resolveContext.getTypeEvalContext().getType(first_arg); if (first_arg_type instanceof PyClassType) { PyClass derived_class = ((PyClassType)first_arg_type).getPyClass(); final Iterator base_it = derived_class.iterateAncestorClasses().iterator(); @@ -212,7 +212,7 @@ public class PyClassTypeImpl extends UserDataHolderBase implements PyClassType { private PyClassType getMetaclassType() { final PyTargetExpression metaClassAttribute = myClass.findClassAttribute(PyNames.DUNDER_METACLASS, true); if (metaClassAttribute != null) { - final PyType type = metaClassAttribute.getType(TypeEvalContext.fastStubOnly(null)); + final PyType type = TypeEvalContext.fastStubOnly(null).getType(metaClassAttribute); if (type instanceof PyClassType) { return (PyClassType)type; } @@ -381,7 +381,8 @@ public class PyClassTypeImpl extends UserDataHolderBase implements PyClassType { type = new PyClassTypeImpl((PyClass)element, myIsDefinition); } else { - type = expression.getType(TypeEvalContext.fastStubOnly(myClass.getContainingFile())); + final TypeEvalContext typeEvalContext = TypeEvalContext.fastStubOnly(myClass.getContainingFile()); + type = typeEvalContext.getType(expression); if (type instanceof PyClassType && !myIsDefinition) { type = ((PyClassType)type).toInstance(); } diff --git a/python/src/com/jetbrains/python/psi/types/PyLiteralCollectionType.java b/python/src/com/jetbrains/python/psi/types/PyLiteralCollectionType.java index cab7a96a6fd7..159deb29958d 100644 --- a/python/src/com/jetbrains/python/psi/types/PyLiteralCollectionType.java +++ b/python/src/com/jetbrains/python/psi/types/PyLiteralCollectionType.java @@ -27,7 +27,7 @@ public class PyLiteralCollectionType extends PyClassTypeImpl implements PyCollec return null; } for (int i = 1; i < elements.length; i++) { - PyType elementType = elements [i].getType(context); + PyType elementType = context.getType(elements[i]); if (elementType == null || !elementType.equals(result)) { return null; } diff --git a/python/src/com/jetbrains/python/psi/types/PyTypeChecker.java b/python/src/com/jetbrains/python/psi/types/PyTypeChecker.java index 8157c052f6dc..d998ec79dbab 100644 --- a/python/src/com/jetbrains/python/psi/types/PyTypeChecker.java +++ b/python/src/com/jetbrains/python/psi/types/PyTypeChecker.java @@ -261,8 +261,8 @@ public class PyTypeChecker { final Map substitutions = collectCallGenerics(function, receiver, context); for (Map.Entry entry : arguments.entrySet()) { final PyNamedParameter p = entry.getValue(); - final PyType argType = entry.getKey().getType(context); - final PyType paramType = p.getType(context); + final PyType argType = context.getType(entry.getKey()); + final PyType paramType = context.getType(p); if (!match(paramType, argType, context, substitutions)) { return null; } @@ -276,7 +276,7 @@ public class PyTypeChecker { final Map substitutions = new LinkedHashMap(); // Collect generic params of object type final Set generics = new LinkedHashSet(); - final PyType qualifierType = receiver != null ? receiver.getType(context) : null; + final PyType qualifierType = receiver != null ? context.getType(receiver) : null; collectGenerics(qualifierType, context, generics, new HashSet()); for (PyGenericType t : generics) { substitutions.put(t, t); @@ -388,7 +388,7 @@ public class PyTypeChecker { final PsiReference ref = expr.getReference(PyResolveContext.noImplicits().withTypeEvalContext(context)); final PsiElement resolved = ref.resolve(); if (resolved instanceof PyTypedElement) { - final PyType type = ((PyTypedElement)resolved).getType(context); + final PyType type = context.getType((PyTypedElement)resolved); if (type instanceof PyFunctionType) { final Callable callable = ((PyFunctionType)type).getCallable(); final PyParameter[] parameters = callable.getParameterList().getParameters(); @@ -479,7 +479,7 @@ public class PyTypeChecker { public static boolean isResolvedToSeveralMethods(@NotNull PyQualifiedExpression callee, @NotNull TypeEvalContext context) { final PyExpression qualifier = callee.getQualifier(); if (qualifier != null) { - final PyType qualifierType = qualifier.getType(context); + final PyType qualifierType = context.getType(qualifier); if (qualifierType instanceof PyUnionType) { final PyUnionType unionType = (PyUnionType)qualifierType; final String name = callee.getName(); diff --git a/python/src/com/jetbrains/python/psi/types/PyTypeParser.java b/python/src/com/jetbrains/python/psi/types/PyTypeParser.java index f2ec421d91ee..f7e20b6c94d2 100644 --- a/python/src/com/jetbrains/python/psi/types/PyTypeParser.java +++ b/python/src/com/jetbrains/python/psi/types/PyTypeParser.java @@ -246,7 +246,7 @@ public class PyTypeParser { final RatedResolveResult result = results.get(0); final PsiElement resolved = result.getElement(); if (resolved instanceof PyTypedElement) { - PyType t = ((PyTypedElement)resolved).getType(context.getTypeEvalContext()); + PyType t = context.getTypeEvalContext().getType((PyTypedElement)resolved); if (t instanceof PyClassType) { t = ((PyClassType)t).toInstance(); } diff --git a/python/src/com/jetbrains/python/refactoring/PyReplaceExpressionUtil.java b/python/src/com/jetbrains/python/refactoring/PyReplaceExpressionUtil.java index fa06d2093ea9..abd91f32fc58 100644 --- a/python/src/com/jetbrains/python/refactoring/PyReplaceExpressionUtil.java +++ b/python/src/com/jetbrains/python/refactoring/PyReplaceExpressionUtil.java @@ -111,7 +111,7 @@ public class PyReplaceExpressionUtil implements PyElementTypes { } else { final TypeEvalContext context = TypeEvalContext.slow(); - final PyType valueType = formatValue.getType(context); + final PyType valueType = context.getType(formatValue); final PyBuiltinCache builtinCache = PyBuiltinCache.getInstance(oldExpression); final PyType tupleType = builtinCache.getTupleType(); final PyType mappingType = PyTypeParser.getTypeByName(null, "collections.Mapping"); diff --git a/python/src/com/jetbrains/python/refactoring/introduce/IntroduceHandler.java b/python/src/com/jetbrains/python/refactoring/introduce/IntroduceHandler.java index 8f970440f578..6f6bed984a18 100644 --- a/python/src/com/jetbrains/python/refactoring/introduce/IntroduceHandler.java +++ b/python/src/com/jetbrains/python/refactoring/introduce/IntroduceHandler.java @@ -189,7 +189,7 @@ abstract public class IntroduceHandler implements RefactoringActionHandler { candidates.addAll(NameSuggesterUtil.generateNames(text)); } final TypeEvalContext context = TypeEvalContext.slow(); - PyType type = expression.getType(context); + PyType type = context.getType(expression); if (type != null && type != PyNoneType.INSTANCE) { String typeName = type.getName(); if (typeName != null) { diff --git a/python/testSrc/com/jetbrains/python/PyTypeTest.java b/python/testSrc/com/jetbrains/python/PyTypeTest.java index 87a250a2ddf1..d023461516fe 100644 --- a/python/testSrc/com/jetbrains/python/PyTypeTest.java +++ b/python/testSrc/com/jetbrains/python/PyTypeTest.java @@ -220,7 +220,7 @@ public class PyTypeTest extends PyTestCase { " return x\n" + "expr = f(1, 2)\n"; PyExpression expr = parseExpr(text); - PyType t = expr.getType(TypeEvalContext.slow()); + PyType t = TypeEvalContext.slow().getType(expr); assertTrue(PyTypeChecker.isUnknown(t)); doTest("int", text); } @@ -234,7 +234,7 @@ public class PyTypeTest extends PyTestCase { " return foo(x)\n" + "expr = xyzzy(a, b)"; PyExpression expr = parseExpr(text); - PyType t = expr.getType(TypeEvalContext.slow()); + PyType t = TypeEvalContext.slow().getType(expr); assertInstanceOf(t, PyTypeReference.class); } @@ -297,7 +297,7 @@ public class PyTypeTest extends PyTestCase { PyExpression expr = parseExpr("def foo(x): return foo(x)\n" + "expr = foo(1)"); TypeEvalContext context = TypeEvalContext.slow().withTracing(); - PyType actual = expr.getType(context); + PyType actual = context.getType(expr); assertFalse(actual.isBuiltin(context)); } @@ -311,7 +311,7 @@ public class PyTypeTest extends PyTestCase { "\n" + "expr = f(1)\n"); TypeEvalContext context = TypeEvalContext.slow().withTracing(); - PyType actual = expr.getType(context); + PyType actual = context.getType(expr); assertNotNull(actual); assertEquals("int", actual.getName()); } @@ -326,7 +326,7 @@ public class PyTypeTest extends PyTestCase { "\n" + "expr = f(1)\n"); TypeEvalContext context = TypeEvalContext.slow().withTracing(); - PyType actual = expr.getType(context); + PyType actual = context.getType(expr); assertNotNull(actual); assertEquals("int", actual.getName()); } @@ -336,7 +336,7 @@ public class PyTypeTest extends PyTestCase { PyExpression expr = parseExpr("def f():\n" + " expr = yield 2\n"); TypeEvalContext context = TypeEvalContext.slow().withTracing(); - PyType actual = expr.getType(context); + PyType actual = context.getType(expr); assertNull(actual); } @@ -381,7 +381,7 @@ public class PyTypeTest extends PyTestCase { "x = f()\n" + "expr = x.start\n"); TypeEvalContext context = TypeEvalContext.slow().withTracing(); - PyType actual = expr.getType(context); + PyType actual = context.getType(expr); assertNull(actual); } @@ -393,7 +393,7 @@ public class PyTypeTest extends PyTestCase { "x = C()\n" + "expr = type(x)\n"); TypeEvalContext context = TypeEvalContext.slow().withTracing(); - PyType type = expr.getType(context); + PyType type = context.getType(expr); assertInstanceOf(type, PyClassType.class); assertTrue("Got instance type instead of class type", ((PyClassType)type).isDefinition()); } @@ -405,7 +405,7 @@ public class PyTypeTest extends PyTestCase { "\n" + "expr = type(C)\n"); TypeEvalContext context = TypeEvalContext.slow().withTracing(); - PyType type = expr.getType(context); + PyType type = context.getType(expr); assertInstanceOf(type, PyClassType.class); assertEquals(type.getName(), "type"); } @@ -415,7 +415,7 @@ public class PyTypeTest extends PyTestCase { PyExpression expr = parseExpr("def f(x):\n" + " expr = type(x)\n"); TypeEvalContext context = TypeEvalContext.slow().withTracing(); - PyType type = expr.getType(context); + PyType type = context.getType(expr); assertNull(type); } @@ -445,7 +445,7 @@ public class PyTypeTest extends PyTestCase { public void testListComprehensionType() { final PyExpression expr = parseExpr("expr = [str(x) for x in range(10)]\n"); final TypeEvalContext context = TypeEvalContext.slow().withTracing(); - final PyType type = expr.getType(context); + final PyType type = context.getType(expr); assertNotNull(type); assertInstanceOf(type, PyCollectionType.class); assertEquals(type.getName(), "list"); @@ -459,7 +459,7 @@ public class PyTypeTest extends PyTestCase { public void testGeneratorComprehensionType() { final PyExpression expr = parseExpr("expr = (str(x) for x in range(10))\n"); final TypeEvalContext context = TypeEvalContext.slow().withTracing(); - final PyType type = expr.getType(context); + final PyType type = context.getType(expr); assertNotNull(type); assertInstanceOf(type, PyCollectionType.class); assertEquals(type.getName(), "__generator"); @@ -491,7 +491,7 @@ public class PyTypeTest extends PyTestCase { private void doTest(final String expectedType, final String text) { PyExpression expr = parseExpr(text); TypeEvalContext context = TypeEvalContext.slow().withTracing(); - PyType actual = expr.getType(context); + PyType actual = context.getType(expr); PyType expected = PyTypeParser.getTypeByName(expr, expectedType); if (expected != null) { assertNotNull(context.printTrace(), actual);