@zzzen/pyright-internal 1.2.0-dev.20240421 → 1.2.0-dev.20240428
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer/analyzerNodeInfo.d.ts +1 -4
- package/dist/analyzer/analyzerNodeInfo.js +1 -11
- package/dist/analyzer/analyzerNodeInfo.js.map +1 -1
- package/dist/analyzer/binder.d.ts +0 -2
- package/dist/analyzer/binder.js +42 -66
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.js +57 -17
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/constructors.js +31 -13
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.d.ts +1 -1
- package/dist/analyzer/dataClasses.js +23 -11
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/deprecatedSymbols.js +2 -4
- package/dist/analyzer/deprecatedSymbols.js.map +1 -1
- package/dist/analyzer/namedTuples.js +0 -8
- package/dist/analyzer/namedTuples.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.js +10 -10
- package/dist/analyzer/parseTreeUtils.d.ts +6 -3
- package/dist/analyzer/parseTreeUtils.js +75 -46
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/protocols.js +32 -13
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/scope.d.ts +14 -7
- package/dist/analyzer/scope.js +25 -16
- package/dist/analyzer/scope.js.map +1 -1
- package/dist/analyzer/scopeUtils.js +3 -3
- package/dist/analyzer/scopeUtils.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +232 -200
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +5 -1
- package/dist/analyzer/typeGuards.js +35 -110
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typeUtils.js +5 -3
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typedDicts.js +4 -6
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.js +10 -0
- package/dist/analyzer/types.js.map +1 -1
- package/dist/common/console.d.ts +12 -1
- package/dist/common/console.js +22 -3
- package/dist/common/console.js.map +1 -1
- package/dist/common/diagnostic.d.ts +4 -0
- package/dist/common/diagnostic.js +10 -4
- package/dist/common/diagnostic.js.map +1 -1
- package/dist/common/envVarUtils.d.ts +2 -2
- package/dist/common/envVarUtils.js.map +1 -1
- package/dist/common/languageServerInterface.d.ts +6 -3
- package/dist/common/languageServerInterface.js +11 -0
- package/dist/common/languageServerInterface.js.map +1 -1
- package/dist/common/uri/uri.d.ts +2 -0
- package/dist/common/uri/uri.js +3 -1
- package/dist/common/uri/uri.js.map +1 -1
- package/dist/languageService/callHierarchyProvider.js +4 -1
- package/dist/languageService/callHierarchyProvider.js.map +1 -1
- package/dist/languageService/completionProvider.js +12 -8
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/documentSymbolCollector.js +1 -1
- package/dist/languageService/referencesProvider.js +3 -2
- package/dist/languageService/referencesProvider.js.map +1 -1
- package/dist/parser/parseNodes.d.ts +2 -2
- package/dist/tests/checker.test.js +8 -0
- package/dist/tests/checker.test.js.map +1 -1
- package/dist/tests/fourslash/{completions.importDunderNames.fourslash.js → completions.import.dunderNames.fourslash.js} +1 -1
- package/dist/tests/fourslash/completions.import.dunderNames.fourslash.js.map +1 -0
- package/dist/tests/fourslash/{completions.importsDuplicates.fourslash.js → completions.import.duplicates.fourslash.js} +1 -1
- package/dist/tests/fourslash/{completions.importsDuplicates.fourslash.js.map → completions.import.duplicates.fourslash.js.map} +1 -1
- package/dist/tests/fourslash/completions.import.exactMatch.fourslash.js +29 -0
- package/dist/tests/fourslash/completions.import.exactMatch.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.import.excludeAlreadyImported.fourslash.js +14 -0
- package/dist/tests/fourslash/completions.import.excludeAlreadyImported.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.import.interimFile.fourslash.disabled.d.ts +1 -0
- package/dist/tests/fourslash/{completions.importInterimFile.fourslash.disabled.js → completions.import.interimFile.fourslash.disabled.js} +1 -1
- package/dist/tests/fourslash/completions.import.interimFile.fourslash.disabled.js.map +1 -0
- package/dist/tests/fourslash/{completions.importPrivateNoPytyped.fourslash.js → completions.import.privateNoPytyped.fourslash.js} +1 -1
- package/dist/tests/fourslash/completions.import.privateNoPytyped.fourslash.js.map +1 -0
- package/dist/tests/fourslash/{completions.importPytyped.fourslash.js → completions.import.pytyped.fourslash.js} +1 -1
- package/dist/tests/fourslash/completions.import.pytyped.fourslash.js.map +1 -0
- package/dist/tests/fourslash/{completions.importPytypedLocal.fourslash.js → completions.import.pytypedLocal.fourslash.js} +1 -1
- package/dist/tests/fourslash/completions.import.pytypedLocal.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.import.submodule.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/{completions.importSubmodule.fourslash.js → completions.import.submodule.fourslash.js} +1 -1
- package/dist/tests/fourslash/completions.import.submodule.fourslash.js.map +1 -0
- package/dist/tests/harness/fourslash/testState.js +1 -1
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/harness/vfs/pathValidation.js +2 -1
- package/dist/tests/harness/vfs/pathValidation.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +1 -1
- package/dist/tests/typeEvaluator2.test.js +4 -0
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +1 -1
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +4 -0
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +2 -2
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/dist/workspaceFactory.d.ts +3 -1
- package/dist/workspaceFactory.js.map +1 -1
- package/package.json +1 -1
- package/dist/tests/fourslash/completions.importDunderNames.fourslash.js.map +0 -1
- package/dist/tests/fourslash/completions.importInterimFile.fourslash.disabled.js.map +0 -1
- package/dist/tests/fourslash/completions.importPrivateNoPytyped.fourslash.js.map +0 -1
- package/dist/tests/fourslash/completions.importPytyped.fourslash.js.map +0 -1
- package/dist/tests/fourslash/completions.importPytypedLocal.fourslash.js.map +0 -1
- package/dist/tests/fourslash/completions.importSubmodule.fourslash.js.map +0 -1
- /package/dist/tests/fourslash/{completions.importDunderNames.fourslash.d.ts → completions.import.dunderNames.fourslash.d.ts} +0 -0
- /package/dist/tests/fourslash/{completions.importPrivateNoPytyped.fourslash.d.ts → completions.import.duplicates.fourslash.d.ts} +0 -0
- /package/dist/tests/fourslash/{completions.importInterimFile.fourslash.disabled.d.ts → completions.import.exactMatch.fourslash.d.ts} +0 -0
- /package/dist/tests/fourslash/{completions.importSubmodule.fourslash.d.ts → completions.import.excludeAlreadyImported.fourslash.d.ts} +0 -0
- /package/dist/tests/fourslash/{completions.importPytyped.fourslash.d.ts → completions.import.privateNoPytyped.fourslash.d.ts} +0 -0
- /package/dist/tests/fourslash/{completions.importPytypedLocal.fourslash.d.ts → completions.import.pytyped.fourslash.d.ts} +0 -0
- /package/dist/tests/fourslash/{completions.importsDuplicates.fourslash.d.ts → completions.import.pytypedLocal.fourslash.d.ts} +0 -0
@@ -1685,7 +1685,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
1685
1685
|
// where the type isn't declared in this class but is in
|
1686
1686
|
// a parent class.
|
1687
1687
|
if (!((_a = getDeclaredTypeOfSymbol(symbol, expression)) === null || _a === void 0 ? void 0 : _a.type) &&
|
1688
|
-
symbolWithScope.scope.type ===
|
1688
|
+
symbolWithScope.scope.type === 3 /* ScopeType.Class */) {
|
1689
1689
|
const enclosingClass = ParseTreeUtils.getEnclosingClassOrFunction(expression);
|
1690
1690
|
if (enclosingClass && enclosingClass.nodeType === 10 /* ParseNodeType.Class */) {
|
1691
1691
|
const classTypeInfo = getTypeOfClass(enclosingClass);
|
@@ -2203,7 +2203,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2203
2203
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(nameNode);
|
2204
2204
|
// If this is a class scope and there is no type declared for this class variable,
|
2205
2205
|
// see if a parent class has a type declared.
|
2206
|
-
if (declaredType === undefined && symbolWithScope.scope.type ===
|
2206
|
+
if (declaredType === undefined && symbolWithScope.scope.type === 3 /* ScopeType.Class */) {
|
2207
2207
|
const containingClass = ParseTreeUtils.getEnclosingClass(nameNode);
|
2208
2208
|
if (containingClass) {
|
2209
2209
|
const classType = getTypeOfClass(containingClass);
|
@@ -2244,7 +2244,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2244
2244
|
// variable that can be overridden by a child class, use the more general
|
2245
2245
|
// version by stripping off the literal.
|
2246
2246
|
const scope = ScopeUtils.getScopeForNode(nameNode);
|
2247
|
-
if ((scope === null || scope === void 0 ? void 0 : scope.type) ===
|
2247
|
+
if ((scope === null || scope === void 0 ? void 0 : scope.type) === 3 /* ScopeType.Class */) {
|
2248
2248
|
if (types_1.TypeBase.isInstance(destType) &&
|
2249
2249
|
!(0, symbolNameUtils_1.isConstantName)(nameValue) &&
|
2250
2250
|
!isFinalVariable(symbolWithScope.symbol)) {
|
@@ -2945,143 +2945,131 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2945
2945
|
let type;
|
2946
2946
|
let isIncomplete = false;
|
2947
2947
|
const allowForwardReferences = (flags & 4 /* EvaluatorFlags.AllowForwardReferences */) !== 0 || fileInfo.isStubFile;
|
2948
|
-
//
|
2949
|
-
|
2950
|
-
|
2951
|
-
|
2952
|
-
|
2953
|
-
|
2954
|
-
|
2955
|
-
|
2948
|
+
// Look for the scope that contains the value definition and
|
2949
|
+
// see if it has a declared type.
|
2950
|
+
let symbolWithScope = lookUpSymbolRecursive(node, name, !allowForwardReferences, allowForwardReferences && (flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0);
|
2951
|
+
if (!symbolWithScope) {
|
2952
|
+
// If the node is part of a "from X import Y as Z" statement and the node
|
2953
|
+
// is the "Y" (non-aliased) name, we need to look up the alias symbol
|
2954
|
+
// since the non-aliased name is not in the symbol table.
|
2955
|
+
const alias = getAliasFromImport(node);
|
2956
|
+
if (alias) {
|
2957
|
+
symbolWithScope = lookUpSymbolRecursive(alias, alias.value, !allowForwardReferences, allowForwardReferences && (flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0);
|
2958
|
+
}
|
2959
|
+
}
|
2960
|
+
if (symbolWithScope) {
|
2961
|
+
let useCodeFlowAnalysis = !allowForwardReferences;
|
2962
|
+
// If the symbol is implicitly imported from the builtin
|
2963
|
+
// scope, there's no need to use code flow analysis.
|
2964
|
+
if (symbolWithScope.scope.type === 5 /* ScopeType.Builtin */) {
|
2965
|
+
useCodeFlowAnalysis = false;
|
2966
|
+
}
|
2967
|
+
symbol = symbolWithScope.symbol;
|
2956
2968
|
setSymbolAccessed(fileInfo, symbol, node);
|
2957
|
-
|
2958
|
-
|
2959
|
-
|
2960
|
-
|
2961
|
-
|
2962
|
-
|
2963
|
-
|
2964
|
-
|
2965
|
-
|
2966
|
-
const alias = getAliasFromImport(node);
|
2967
|
-
if (alias) {
|
2968
|
-
symbolWithScope = lookUpSymbolRecursive(alias, alias.value, !allowForwardReferences, allowForwardReferences && (flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0);
|
2969
|
+
// If we're not supposed to be analyzing this function, skip the remaining work
|
2970
|
+
// to determine the name's type. Simply evaluate its type as Any.
|
2971
|
+
if (!fileInfo.diagnosticRuleSet.analyzeUnannotatedFunctions) {
|
2972
|
+
const containingFunction = ParseTreeUtils.getEnclosingFunction(node);
|
2973
|
+
if (containingFunction && ParseTreeUtils.isUnannotatedFunction(containingFunction)) {
|
2974
|
+
return {
|
2975
|
+
type: types_1.AnyType.create(),
|
2976
|
+
isIncomplete: false,
|
2977
|
+
};
|
2969
2978
|
}
|
2970
2979
|
}
|
2971
|
-
|
2972
|
-
|
2973
|
-
|
2974
|
-
|
2975
|
-
|
2976
|
-
|
2977
|
-
|
2978
|
-
|
2979
|
-
setSymbolAccessed(fileInfo, symbol, node);
|
2980
|
-
// If we're not supposed to be analyzing this function, skip the remaining work
|
2981
|
-
// to determine the name's type. Simply evaluate its type as Any.
|
2982
|
-
if (!fileInfo.diagnosticRuleSet.analyzeUnannotatedFunctions) {
|
2983
|
-
const containingFunction = ParseTreeUtils.getEnclosingFunction(node);
|
2984
|
-
if (containingFunction && ParseTreeUtils.isUnannotatedFunction(containingFunction)) {
|
2985
|
-
return {
|
2986
|
-
type: types_1.AnyType.create(),
|
2987
|
-
isIncomplete: false,
|
2988
|
-
};
|
2989
|
-
}
|
2980
|
+
// Get the effective type (either the declared type or the inferred type).
|
2981
|
+
// If we're using code flow analysis, pass the usage node so we consider
|
2982
|
+
// only the assignment nodes that are reachable from this usage.
|
2983
|
+
const effectiveTypeInfo = getEffectiveTypeOfSymbolForUsage(symbol, useCodeFlowAnalysis ? node : undefined);
|
2984
|
+
let effectiveType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(effectiveTypeInfo.type);
|
2985
|
+
if (effectiveTypeInfo.isIncomplete) {
|
2986
|
+
if ((0, types_1.isUnbound)(effectiveType)) {
|
2987
|
+
effectiveType = types_1.UnknownType.create(/* isIncomplete */ true);
|
2990
2988
|
}
|
2991
|
-
|
2992
|
-
|
2993
|
-
|
2994
|
-
|
2995
|
-
|
2996
|
-
|
2997
|
-
|
2998
|
-
|
2999
|
-
|
3000
|
-
|
3001
|
-
|
3002
|
-
|
3003
|
-
|
3004
|
-
|
3005
|
-
|
3006
|
-
|
3007
|
-
|
3008
|
-
|
3009
|
-
|
3010
|
-
|
3011
|
-
|
3012
|
-
|
3013
|
-
|
3014
|
-
if (!symbolWithScope.isBeyondExecutionScope && symbol.isInitiallyUnbound()) {
|
3015
|
-
typeAtStart = types_1.UnboundType.create();
|
3016
|
-
// Is this a module-level scope? If so, see if it's an alias of a builtin.
|
3017
|
-
if (symbolWithScope.scope.type === 3 /* ScopeType.Module */) {
|
3018
|
-
(0, debug_1.assert)(symbolWithScope.scope.parent);
|
3019
|
-
const builtInSymbol = symbolWithScope.scope.parent.lookUpSymbol(name);
|
3020
|
-
if (builtInSymbol) {
|
3021
|
-
const builtInEffectiveType = getEffectiveTypeOfSymbolForUsage(builtInSymbol);
|
3022
|
-
typeAtStart = builtInEffectiveType.type;
|
3023
|
-
}
|
3024
|
-
}
|
3025
|
-
}
|
3026
|
-
if (symbolWithScope.isBeyondExecutionScope) {
|
3027
|
-
const outerScopeTypeResult = getCodeFlowTypeForCapturedVariable(node, symbolWithScope, effectiveType);
|
3028
|
-
if (outerScopeTypeResult === null || outerScopeTypeResult === void 0 ? void 0 : outerScopeTypeResult.type) {
|
3029
|
-
type = outerScopeTypeResult.type;
|
3030
|
-
typeAtStart = type;
|
3031
|
-
isTypeAtStartIncomplete = !!outerScopeTypeResult.isIncomplete;
|
2989
|
+
isIncomplete = true;
|
2990
|
+
}
|
2991
|
+
if (effectiveTypeInfo.isRecursiveDefinition && isNodeReachable(node)) {
|
2992
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.recursiveDefinition().format({ name }), node);
|
2993
|
+
}
|
2994
|
+
const isSpecialBuiltIn = !!effectiveType && (0, types_1.isInstantiableClass)(effectiveType) && types_1.ClassType.isSpecialBuiltIn(effectiveType);
|
2995
|
+
type = effectiveType;
|
2996
|
+
if (useCodeFlowAnalysis && !isSpecialBuiltIn) {
|
2997
|
+
// See if code flow analysis can tell us anything more about the type.
|
2998
|
+
// If the symbol is declared outside of our execution scope, use its effective
|
2999
|
+
// type. If it's declared inside our execution scope, it generally starts
|
3000
|
+
// as unbound at the start of the code flow.
|
3001
|
+
let typeAtStart = effectiveType;
|
3002
|
+
let isTypeAtStartIncomplete = false;
|
3003
|
+
if (!symbolWithScope.isBeyondExecutionScope && symbol.isInitiallyUnbound()) {
|
3004
|
+
typeAtStart = types_1.UnboundType.create();
|
3005
|
+
// Is this a module-level scope? If so, see if it's an alias of a builtin.
|
3006
|
+
if (symbolWithScope.scope.type === 4 /* ScopeType.Module */) {
|
3007
|
+
(0, debug_1.assert)(symbolWithScope.scope.parent);
|
3008
|
+
const builtInSymbol = symbolWithScope.scope.parent.lookUpSymbol(name);
|
3009
|
+
if (builtInSymbol) {
|
3010
|
+
const builtInEffectiveType = getEffectiveTypeOfSymbolForUsage(builtInSymbol);
|
3011
|
+
typeAtStart = builtInEffectiveType.type;
|
3032
3012
|
}
|
3033
3013
|
}
|
3034
|
-
|
3035
|
-
|
3036
|
-
|
3037
|
-
|
3038
|
-
|
3039
|
-
|
3040
|
-
|
3041
|
-
}
|
3042
|
-
if (codeFlowTypeResult.isIncomplete) {
|
3043
|
-
isIncomplete = true;
|
3014
|
+
}
|
3015
|
+
if (symbolWithScope.isBeyondExecutionScope) {
|
3016
|
+
const outerScopeTypeResult = getCodeFlowTypeForCapturedVariable(node, symbolWithScope, effectiveType);
|
3017
|
+
if (outerScopeTypeResult === null || outerScopeTypeResult === void 0 ? void 0 : outerScopeTypeResult.type) {
|
3018
|
+
type = outerScopeTypeResult.type;
|
3019
|
+
typeAtStart = type;
|
3020
|
+
isTypeAtStartIncomplete = !!outerScopeTypeResult.isIncomplete;
|
3044
3021
|
}
|
3045
3022
|
}
|
3046
|
-
|
3047
|
-
|
3048
|
-
|
3049
|
-
|
3050
|
-
|
3051
|
-
|
3052
|
-
|
3053
|
-
|
3054
|
-
|
3055
|
-
|
3056
|
-
|
3057
|
-
|
3058
|
-
|
3059
|
-
|
3060
|
-
|
3061
|
-
|
3062
|
-
|
3063
|
-
|
3064
|
-
|
3065
|
-
|
3066
|
-
|
3067
|
-
|
3068
|
-
|
3069
|
-
|
3070
|
-
|
3071
|
-
|
3023
|
+
const codeFlowTypeResult = getFlowTypeOfReference(node, /* startNode */ undefined, {
|
3024
|
+
targetSymbolId: symbol.id,
|
3025
|
+
typeAtStart: { type: typeAtStart, isIncomplete: isTypeAtStartIncomplete },
|
3026
|
+
skipConditionalNarrowing: (flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0,
|
3027
|
+
});
|
3028
|
+
if (codeFlowTypeResult.type) {
|
3029
|
+
type = codeFlowTypeResult.type;
|
3030
|
+
}
|
3031
|
+
if (codeFlowTypeResult.isIncomplete) {
|
3032
|
+
isIncomplete = true;
|
3033
|
+
}
|
3034
|
+
}
|
3035
|
+
// Detect, report, and fill in missing type arguments if appropriate.
|
3036
|
+
type = reportMissingTypeArguments(node, type, flags);
|
3037
|
+
if ((flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0) {
|
3038
|
+
// Verify that the name does not refer to a (non type alias) variable.
|
3039
|
+
if (effectiveTypeInfo.includesVariableDecl && !type.typeAliasInfo) {
|
3040
|
+
let isAllowedTypeForVariable = (0, types_1.isTypeVar)(type) || (0, typeUtils_1.isTypeAliasPlaceholder)(type);
|
3041
|
+
if ((0, types_1.isClass)(type) &&
|
3042
|
+
!type.includeSubclasses &&
|
3043
|
+
!symbol.hasTypedDeclarations() &&
|
3044
|
+
types_1.ClassType.isValidTypeAliasClass(type)) {
|
3045
|
+
// This check exempts class types that are created by calling
|
3046
|
+
// NewType, NamedTuple, etc.
|
3047
|
+
isAllowedTypeForVariable = true;
|
3048
|
+
}
|
3049
|
+
// Disable for assignments in the typings.pyi file, since it defines special forms.
|
3050
|
+
if (!isAllowedTypeForVariable && !fileInfo.isTypingStubFile) {
|
3051
|
+
// This might be a union that was previously a type alias
|
3052
|
+
// but was reconstituted in such a way that we lost the
|
3053
|
+
// typeAliasInfo. Avoid the false positive error by suppressing
|
3054
|
+
// the error when it looks like a plausible type alias type.
|
3055
|
+
if (effectiveTypeInfo.includesIllegalTypeAliasDecl ||
|
3056
|
+
!types_1.TypeBase.isInstantiable(type) ||
|
3057
|
+
(flags & 2 /* EvaluatorFlags.DoNotSpecialize */) !== 0) {
|
3058
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.typeAnnotationVariable(), node);
|
3059
|
+
type = types_1.UnknownType.create();
|
3072
3060
|
}
|
3073
3061
|
}
|
3074
3062
|
}
|
3075
3063
|
}
|
3064
|
+
}
|
3065
|
+
else {
|
3066
|
+
// Handle the special case of "reveal_type" and "reveal_locals".
|
3067
|
+
if (name === 'reveal_type' || name === 'reveal_locals') {
|
3068
|
+
type = types_1.AnyType.create();
|
3069
|
+
}
|
3076
3070
|
else {
|
3077
|
-
|
3078
|
-
|
3079
|
-
type = types_1.AnyType.create();
|
3080
|
-
}
|
3081
|
-
else {
|
3082
|
-
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUndefinedVariable, localize_1.LocMessage.symbolIsUndefined().format({ name }), node);
|
3083
|
-
type = types_1.UnknownType.create();
|
3084
|
-
}
|
3071
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUndefinedVariable, localize_1.LocMessage.symbolIsUndefined().format({ name }), node);
|
3072
|
+
type = types_1.UnknownType.create();
|
3085
3073
|
}
|
3086
3074
|
}
|
3087
3075
|
if ((0, types_1.isParamSpec)(type)) {
|
@@ -5852,7 +5840,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5852
5840
|
scope = ScopeUtils.getScopeForNode(curNode);
|
5853
5841
|
// Stop when we get a valid scope that's not a list comprehension
|
5854
5842
|
// scope. That includes lambdas, functions, classes, and modules.
|
5855
|
-
if (scope && scope.type !==
|
5843
|
+
if (scope && scope.type !== 1 /* ScopeType.ListComprehension */) {
|
5856
5844
|
break;
|
5857
5845
|
}
|
5858
5846
|
curNode = curNode.parent;
|
@@ -8146,7 +8134,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8146
8134
|
}
|
8147
8135
|
}
|
8148
8136
|
// Calculate the return type.
|
8149
|
-
let returnType = getFunctionEffectiveReturnType(type, matchResults.argParams);
|
8137
|
+
let returnType = getFunctionEffectiveReturnType(type, { args: matchResults.argParams, errorNode });
|
8150
8138
|
if (condition.length > 0) {
|
8151
8139
|
returnType = types_1.TypeBase.cloneForCondition(returnType, condition);
|
8152
8140
|
}
|
@@ -9202,8 +9190,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9202
9190
|
if (!(0, types_1.isClassInstance)(arg1Type) || !(0, typeUtils_1.isTupleClass)(arg1Type) || arg1Type.tupleTypeArguments === undefined) {
|
9203
9191
|
return undefined;
|
9204
9192
|
}
|
9205
|
-
const classType = types_1.ClassType.createInstantiable(className, ParseTreeUtils.getClassFullName(errorNode, fileInfo.moduleName, className), fileInfo.moduleName, fileInfo.fileUri, 1073741824 /* ClassTypeFlags.ValidTypeAliasClass */, ParseTreeUtils.getTypeSourceId(errorNode),
|
9206
|
-
/* declaredMetaclass */ undefined, arg1Type.details.effectiveMetaclass);
|
9193
|
+
const classType = types_1.ClassType.createInstantiable(className, ParseTreeUtils.getClassFullName(errorNode, fileInfo.moduleName, className), fileInfo.moduleName, fileInfo.fileUri, 1073741824 /* ClassTypeFlags.ValidTypeAliasClass */, ParseTreeUtils.getTypeSourceId(errorNode), metaclass, arg1Type.details.effectiveMetaclass);
|
9207
9194
|
arg1Type.tupleTypeArguments.forEach((typeArg) => {
|
9208
9195
|
const specializedType = makeTopLevelTypeVarsConcrete(typeArg.type);
|
9209
9196
|
if ((0, typeUtils_1.isEffectivelyInstantiable)(specializedType)) {
|
@@ -9362,6 +9349,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9362
9349
|
const keyTypes = [];
|
9363
9350
|
const valueTypes = [];
|
9364
9351
|
let isIncomplete = false;
|
9352
|
+
let typeErrors = false;
|
9365
9353
|
// Handle TypedDict's as a special case.
|
9366
9354
|
if (types_1.ClassType.isTypedDictClass(concreteExpectedType)) {
|
9367
9355
|
// Remove any conditions associated with the type so the resulting type isn't
|
@@ -9369,13 +9357,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9369
9357
|
concreteExpectedType = types_1.TypeBase.cloneForCondition(concreteExpectedType, undefined);
|
9370
9358
|
const expectedTypedDictEntries = (0, typedDicts_1.getTypedDictMembersForClass)(evaluatorInterface, concreteExpectedType);
|
9371
9359
|
// Infer the key and value types if possible.
|
9372
|
-
|
9360
|
+
const keyValueTypeResult = getKeyAndValueTypesFromDictionary(node, keyTypes, valueTypes,
|
9373
9361
|
/* forceStrictInference */ true,
|
9374
9362
|
/* isValueTypeInvariant */ true,
|
9375
9363
|
/* expectedKeyType */ undefined,
|
9376
|
-
/* expectedValueType */ undefined, expectedTypedDictEntries, expectedDiagAddendum)
|
9364
|
+
/* expectedValueType */ undefined, expectedTypedDictEntries, expectedDiagAddendum);
|
9365
|
+
if (keyValueTypeResult.isIncomplete) {
|
9377
9366
|
isIncomplete = true;
|
9378
9367
|
}
|
9368
|
+
if (keyValueTypeResult.typeErrors) {
|
9369
|
+
typeErrors = true;
|
9370
|
+
}
|
9379
9371
|
const resultTypedDict = (0, typedDicts_1.assignToTypedDict)(evaluatorInterface, concreteExpectedType, keyTypes, valueTypes,
|
9380
9372
|
// Don't overwrite existing expectedDiagAddendum messages if they were
|
9381
9373
|
// already provided by getKeyValueTypesFromDictionary.
|
@@ -9423,10 +9415,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9423
9415
|
}
|
9424
9416
|
}
|
9425
9417
|
// Infer the key and value types if possible.
|
9426
|
-
|
9427
|
-
/* forceStrictInference */ true, isValueTypeInvariant, expectedKeyType, expectedValueType, undefined, expectedDiagAddendum)
|
9418
|
+
const keyValueResult = getKeyAndValueTypesFromDictionary(node, keyTypes, valueTypes,
|
9419
|
+
/* forceStrictInference */ true, isValueTypeInvariant, expectedKeyType, expectedValueType, undefined, expectedDiagAddendum);
|
9420
|
+
if (keyValueResult.isIncomplete) {
|
9428
9421
|
isIncomplete = true;
|
9429
9422
|
}
|
9423
|
+
if (keyValueResult.typeErrors) {
|
9424
|
+
typeErrors = true;
|
9425
|
+
}
|
9430
9426
|
const specializedKeyType = inferTypeArgFromExpectedEntryType((0, typeUtils_1.makeInferenceContext)(expectedKeyType), keyTypes.map((result) => result.type),
|
9431
9427
|
/* isNarrowable */ false);
|
9432
9428
|
const specializedValueType = inferTypeArgFromExpectedEntryType((0, typeUtils_1.makeInferenceContext)(expectedValueType), valueTypes.map((result) => result.type), !isValueTypeInvariant);
|
@@ -9434,7 +9430,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9434
9430
|
return undefined;
|
9435
9431
|
}
|
9436
9432
|
const type = getBuiltInObject(node, 'dict', [specializedKeyType, specializedValueType]);
|
9437
|
-
return { type, isIncomplete };
|
9433
|
+
return { type, isIncomplete, typeErrors };
|
9438
9434
|
}
|
9439
9435
|
// Attempts to infer the type of a dictionary statement. If hasExpectedType
|
9440
9436
|
// is true, strict inference is used for the subexpressions.
|
@@ -9446,12 +9442,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9446
9442
|
const valueTypeResults = [];
|
9447
9443
|
let isEmptyContainer = false;
|
9448
9444
|
let isIncomplete = false;
|
9445
|
+
let typeErrors = false;
|
9449
9446
|
// Infer the key and value types if possible.
|
9450
|
-
|
9447
|
+
const keyValueResult = getKeyAndValueTypesFromDictionary(node, keyTypeResults, valueTypeResults,
|
9451
9448
|
/* forceStrictInference */ hasExpectedType,
|
9452
|
-
/* isValueTypeInvariant */ false)
|
9449
|
+
/* isValueTypeInvariant */ false);
|
9450
|
+
if (keyValueResult.isIncomplete) {
|
9453
9451
|
isIncomplete = true;
|
9454
9452
|
}
|
9453
|
+
if (keyValueResult.typeErrors) {
|
9454
|
+
typeErrors = true;
|
9455
|
+
}
|
9455
9456
|
// Strip any literal values.
|
9456
9457
|
const keyTypes = keyTypeResults.map((t) => stripLiteralValue(t.type));
|
9457
9458
|
const valueTypes = valueTypeResults.map((t) => stripLiteralValue(t.type));
|
@@ -9485,10 +9486,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9485
9486
|
return { type: types_1.UnknownType.create() };
|
9486
9487
|
}
|
9487
9488
|
}
|
9488
|
-
return { type, isIncomplete };
|
9489
|
+
return { type, isIncomplete, typeErrors };
|
9489
9490
|
}
|
9490
9491
|
function getKeyAndValueTypesFromDictionary(node, keyTypes, valueTypes, forceStrictInference, isValueTypeInvariant, expectedKeyType, expectedValueType, expectedTypedDictEntries, expectedDiagAddendum) {
|
9491
9492
|
let isIncomplete = false;
|
9493
|
+
let typeErrors = false;
|
9492
9494
|
// Infer the key and value types if possible.
|
9493
9495
|
node.entries.forEach((entryNode, index) => {
|
9494
9496
|
var _a, _b, _c, _d;
|
@@ -9499,6 +9501,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9499
9501
|
if (keyTypeResult.isIncomplete) {
|
9500
9502
|
isIncomplete = true;
|
9501
9503
|
}
|
9504
|
+
if (keyTypeResult.typeErrors) {
|
9505
|
+
typeErrors = true;
|
9506
|
+
}
|
9502
9507
|
const keyType = keyTypeResult.type;
|
9503
9508
|
if (!keyTypeResult.isIncomplete && !keyTypeResult.typeErrors) {
|
9504
9509
|
verifySetEntryOrDictKeyIsHashable(entryNode.keyExpression, keyType, /* isDictKey */ true);
|
@@ -9537,6 +9542,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9537
9542
|
if (valueTypeResult.isIncomplete) {
|
9538
9543
|
isIncomplete = true;
|
9539
9544
|
}
|
9545
|
+
if (valueTypeResult.typeErrors) {
|
9546
|
+
typeErrors = true;
|
9547
|
+
}
|
9540
9548
|
if (forceStrictInference || index < maxEntriesToUseForInference) {
|
9541
9549
|
// If an existing key has the same literal type, delete the previous
|
9542
9550
|
// key since we're overwriting it here.
|
@@ -9572,6 +9580,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9572
9580
|
if (unexpandedTypeResult.isIncomplete) {
|
9573
9581
|
isIncomplete = true;
|
9574
9582
|
}
|
9583
|
+
if (unexpandedTypeResult.typeErrors) {
|
9584
|
+
typeErrors = true;
|
9585
|
+
}
|
9575
9586
|
const unexpandedType = unexpandedTypeResult.type;
|
9576
9587
|
if ((0, types_1.isAnyOrUnknown)(unexpandedType)) {
|
9577
9588
|
addUnknown = false;
|
@@ -9629,6 +9640,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9629
9640
|
if (dictEntryTypeResult.isIncomplete) {
|
9630
9641
|
isIncomplete = true;
|
9631
9642
|
}
|
9643
|
+
if (dictEntryTypeResult.typeErrors) {
|
9644
|
+
typeErrors = true;
|
9645
|
+
}
|
9632
9646
|
// The result should be a tuple.
|
9633
9647
|
if ((0, types_1.isClassInstance)(dictEntryType) && (0, typeUtils_1.isTupleClass)(dictEntryType)) {
|
9634
9648
|
const typeArgs = (_d = dictEntryType.tupleTypeArguments) === null || _d === void 0 ? void 0 : _d.map((t) => t.type);
|
@@ -9648,7 +9662,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9648
9662
|
}
|
9649
9663
|
}
|
9650
9664
|
});
|
9651
|
-
return isIncomplete;
|
9665
|
+
return { type: types_1.AnyType.create(), isIncomplete, typeErrors };
|
9652
9666
|
}
|
9653
9667
|
function getTypeOfListOrSet(node, flags, inferenceContext) {
|
9654
9668
|
var _a;
|
@@ -9945,23 +9959,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9945
9959
|
return undefined;
|
9946
9960
|
});
|
9947
9961
|
}
|
9948
|
-
|
9949
|
-
return getTypeOfLambdaWithExpectedType(node, expectedFunctionTypes.length > 0 ? expectedFunctionTypes[0] : undefined, inferenceContext,
|
9950
|
-
/* forceSpeculative */ false);
|
9951
|
-
}
|
9952
|
-
// Sort the expected types for deterministic results.
|
9953
|
-
expectedFunctionTypes = (0, typeUtils_1.sortTypes)(expectedFunctionTypes);
|
9962
|
+
let expectedSubtype;
|
9954
9963
|
// If there's more than one type, try each in turn until we find one that works.
|
9955
|
-
|
9956
|
-
|
9957
|
-
|
9958
|
-
|
9959
|
-
|
9960
|
-
/* forceSpeculative */
|
9964
|
+
if (expectedFunctionTypes.length > 1) {
|
9965
|
+
// Sort the expected types for deterministic results.
|
9966
|
+
expectedFunctionTypes = (0, typeUtils_1.sortTypes)(expectedFunctionTypes);
|
9967
|
+
for (const subtype of expectedFunctionTypes) {
|
9968
|
+
const result = getTypeOfLambdaWithExpectedType(node, subtype, inferenceContext,
|
9969
|
+
/* forceSpeculative */ true);
|
9970
|
+
if (!result.typeErrors) {
|
9971
|
+
expectedSubtype = subtype;
|
9972
|
+
break;
|
9973
|
+
}
|
9961
9974
|
}
|
9962
9975
|
}
|
9963
|
-
|
9964
|
-
|
9976
|
+
if (!expectedSubtype && expectedFunctionTypes.length > 0) {
|
9977
|
+
expectedSubtype = expectedFunctionTypes[0];
|
9978
|
+
}
|
9979
|
+
return getTypeOfLambdaWithExpectedType(node, expectedSubtype, inferenceContext, /* forceSpeculative */ false);
|
9965
9980
|
}
|
9966
9981
|
function getTypeOfLambdaWithExpectedType(node, expectedType, inferenceContext, forceSpeculative) {
|
9967
9982
|
let isIncomplete = !!(inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete);
|
@@ -11539,7 +11554,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11539
11554
|
const scope = ScopeUtils.getScopeForNode(node);
|
11540
11555
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
11541
11556
|
let classFlags = 0 /* ClassTypeFlags.None */;
|
11542
|
-
if ((scope === null || scope === void 0 ? void 0 : scope.type) ===
|
11557
|
+
if ((scope === null || scope === void 0 ? void 0 : scope.type) === 5 /* ScopeType.Builtin */ ||
|
11543
11558
|
fileInfo.isTypingStubFile ||
|
11544
11559
|
fileInfo.isTypingExtensionsStubFile ||
|
11545
11560
|
fileInfo.isBuiltInStubFile ||
|
@@ -12045,7 +12060,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12045
12060
|
if (hashSymbol && hashSymbol.isClassMember() && !hashSymbol.getSynthesizedType()) {
|
12046
12061
|
skipSynthesizeHash = true;
|
12047
12062
|
}
|
12048
|
-
const synthesizeMethods = () => (0, dataClasses_1.synthesizeDataClassMethods)(evaluatorInterface, node, classType, skipSynthesizedInit, hasExistingInitMethod, skipSynthesizeHash);
|
12063
|
+
const synthesizeMethods = () => (0, dataClasses_1.synthesizeDataClassMethods)(evaluatorInterface, node, classType, isNamedTupleSubclass, skipSynthesizedInit, hasExistingInitMethod, skipSynthesizeHash);
|
12049
12064
|
// If this is a NamedTuple subclass, immediately synthesize dataclass methods
|
12050
12065
|
// because we also need to update the MRO classes in this case. For regular
|
12051
12066
|
// dataclasses, we'll defer the method synthesis to avoid circular dependencies.
|
@@ -12202,9 +12217,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12202
12217
|
}
|
12203
12218
|
function evaluateTypeParameterList(node) {
|
12204
12219
|
const paramTypes = [];
|
12220
|
+
const typeParamScope = AnalyzerNodeInfo.getScope(node);
|
12221
|
+
(0, debug_1.assert)(typeParamScope !== undefined);
|
12205
12222
|
node.parameters.forEach((param) => {
|
12206
12223
|
var _a;
|
12207
|
-
const paramSymbol =
|
12224
|
+
const paramSymbol = typeParamScope.symbolTable.get(param.name.value);
|
12208
12225
|
if (!paramSymbol) {
|
12209
12226
|
// This can happen if the code is unreachable.
|
12210
12227
|
return;
|
@@ -14633,13 +14650,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14633
14650
|
}
|
14634
14651
|
function lookUpSymbolRecursive(node, name, honorCodeFlow, preferGlobalScope = false) {
|
14635
14652
|
var _a;
|
14636
|
-
const
|
14637
|
-
|
14638
|
-
|
14653
|
+
const scopeNodeInfo = ParseTreeUtils.getEvaluationScopeNode(node);
|
14654
|
+
const scope = AnalyzerNodeInfo.getScope(scopeNodeInfo.node);
|
14655
|
+
let symbolWithScope = scope === null || scope === void 0 ? void 0 : scope.lookUpSymbolRecursive(name, { useProxyScope: !!scopeNodeInfo.useProxyScope });
|
14656
|
+
const scopeType = (_a = scope === null || scope === void 0 ? void 0 : scope.type) !== null && _a !== void 0 ? _a : 4 /* ScopeType.Module */;
|
14639
14657
|
// Functions and list comprehensions don't allow access to implicitly
|
14640
14658
|
// aliased symbols in outer scopes if they haven't yet been assigned
|
14641
|
-
// within the local scope.
|
14642
|
-
const scopeTypeHonorsCodeFlow = scopeType !==
|
14659
|
+
// within the local scope. Same with type parameter scopes.
|
14660
|
+
const scopeTypeHonorsCodeFlow = scopeType !== 2 /* ScopeType.Function */ &&
|
14661
|
+
scopeType !== 1 /* ScopeType.ListComprehension */ &&
|
14662
|
+
scopeType !== 0 /* ScopeType.TypeParameter */;
|
14643
14663
|
if (symbolWithScope && honorCodeFlow && scopeTypeHonorsCodeFlow) {
|
14644
14664
|
// Filter the declarations based on flow reachability.
|
14645
14665
|
const reachableDecl = symbolWithScope.symbol.getDeclarations().find((decl) => {
|
@@ -14671,11 +14691,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14671
14691
|
// If none of the declarations are reachable from the current node,
|
14672
14692
|
// search for the symbol in outer scopes.
|
14673
14693
|
if (!reachableDecl) {
|
14674
|
-
if (symbolWithScope.scope.type !==
|
14694
|
+
if (symbolWithScope.scope.type !== 2 /* ScopeType.Function */) {
|
14675
14695
|
let nextScopeToSearch = symbolWithScope.scope.parent;
|
14676
|
-
const isOutsideCallerModule = symbolWithScope.isOutsideCallerModule || symbolWithScope.scope.type ===
|
14696
|
+
const isOutsideCallerModule = symbolWithScope.isOutsideCallerModule || symbolWithScope.scope.type === 4 /* ScopeType.Module */;
|
14677
14697
|
let isBeyondExecutionScope = symbolWithScope.isBeyondExecutionScope || symbolWithScope.scope.isIndependentlyExecutable();
|
14678
|
-
if (symbolWithScope.scope.type ===
|
14698
|
+
if (symbolWithScope.scope.type === 3 /* ScopeType.Class */) {
|
14679
14699
|
// There is an odd documented behavior for classes in that
|
14680
14700
|
// symbol resolution skips to the global scope rather than
|
14681
14701
|
// the next scope in the chain.
|
@@ -14686,7 +14706,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14686
14706
|
}
|
14687
14707
|
}
|
14688
14708
|
if (nextScopeToSearch) {
|
14689
|
-
symbolWithScope = nextScopeToSearch.lookUpSymbolRecursive(name,
|
14709
|
+
symbolWithScope = nextScopeToSearch.lookUpSymbolRecursive(name, {
|
14710
|
+
isOutsideCallerModule,
|
14711
|
+
isBeyondExecutionScope,
|
14712
|
+
});
|
14690
14713
|
}
|
14691
14714
|
else {
|
14692
14715
|
symbolWithScope = undefined;
|
@@ -14702,16 +14725,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14702
14725
|
// resolution over local resolutions.
|
14703
14726
|
if (symbolWithScope && preferGlobalScope) {
|
14704
14727
|
let curSymbolWithScope = symbolWithScope;
|
14705
|
-
while (curSymbolWithScope.scope.type !==
|
14706
|
-
curSymbolWithScope.scope.type !==
|
14728
|
+
while (curSymbolWithScope.scope.type !== 4 /* ScopeType.Module */ &&
|
14729
|
+
curSymbolWithScope.scope.type !== 5 /* ScopeType.Builtin */ &&
|
14730
|
+
curSymbolWithScope.scope.type !== 0 /* ScopeType.TypeParameter */ &&
|
14707
14731
|
curSymbolWithScope.scope.parent) {
|
14708
|
-
curSymbolWithScope = curSymbolWithScope.scope.parent.lookUpSymbolRecursive(name,
|
14732
|
+
curSymbolWithScope = curSymbolWithScope.scope.parent.lookUpSymbolRecursive(name, {
|
14733
|
+
isOutsideCallerModule: curSymbolWithScope.isOutsideCallerModule,
|
14734
|
+
isBeyondExecutionScope: curSymbolWithScope.isBeyondExecutionScope ||
|
14735
|
+
curSymbolWithScope.scope.isIndependentlyExecutable(),
|
14736
|
+
});
|
14709
14737
|
if (!curSymbolWithScope) {
|
14710
14738
|
break;
|
14711
14739
|
}
|
14712
14740
|
}
|
14713
|
-
if ((curSymbolWithScope === null || curSymbolWithScope === void 0 ? void 0 : curSymbolWithScope.scope.type) ===
|
14714
|
-
(curSymbolWithScope === null || curSymbolWithScope === void 0 ? void 0 : curSymbolWithScope.scope.type) ===
|
14741
|
+
if ((curSymbolWithScope === null || curSymbolWithScope === void 0 ? void 0 : curSymbolWithScope.scope.type) === 4 /* ScopeType.Module */ ||
|
14742
|
+
(curSymbolWithScope === null || curSymbolWithScope === void 0 ? void 0 : curSymbolWithScope.scope.type) === 5 /* ScopeType.Builtin */) {
|
14715
14743
|
symbolWithScope = curSymbolWithScope;
|
14716
14744
|
}
|
14717
14745
|
}
|
@@ -14989,17 +15017,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14989
15017
|
// Determine if this is part of a "type" statement.
|
14990
15018
|
const isWithinTypeAliasStatement = !!ParseTreeUtils.getParentNodeOfType(node, 77 /* ParseNodeType.TypeAlias */);
|
14991
15019
|
const allowForwardReferences = isWithinTypeAnnotation || isWithinTypeAliasStatement || fileInfo.isStubFile;
|
14992
|
-
|
14993
|
-
|
14994
|
-
|
14995
|
-
symbol = typeParamSymbol;
|
14996
|
-
}
|
14997
|
-
else {
|
14998
|
-
const symbolWithScope = lookUpSymbolRecursive(node, node.value, !allowForwardReferences, isWithinTypeAnnotation);
|
14999
|
-
symbol = symbolWithScope === null || symbolWithScope === void 0 ? void 0 : symbolWithScope.symbol;
|
15000
|
-
}
|
15001
|
-
if (symbol) {
|
15002
|
-
(0, collectionUtils_1.appendArray)(declarations, symbol.getDeclarations());
|
15020
|
+
const symbolWithScope = lookUpSymbolRecursive(node, node.value, !allowForwardReferences, isWithinTypeAnnotation);
|
15021
|
+
if (symbolWithScope) {
|
15022
|
+
(0, collectionUtils_1.appendArray)(declarations, symbolWithScope.symbol.getDeclarations());
|
15003
15023
|
}
|
15004
15024
|
}
|
15005
15025
|
return declarations;
|
@@ -15256,6 +15276,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15256
15276
|
}
|
15257
15277
|
typeVar = types_1.TypeVarType.cloneForScopeId(typeVar, ParseTreeUtils.getScopeIdForNode(scopeNode.nodeType === 77 /* ParseNodeType.TypeAlias */ ? scopeNode.name : scopeNode), scopeNode.name.value, scopeType);
|
15258
15278
|
}
|
15279
|
+
writeTypeCache(node, { type: typeVar }, /* flags */ undefined);
|
15280
|
+
writeTypeCache(node.name, { type: typeVar }, /* flags */ undefined);
|
15259
15281
|
return typeVar;
|
15260
15282
|
}
|
15261
15283
|
function getInferredTypeOfDeclaration(symbol, decl) {
|
@@ -15849,17 +15871,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15849
15871
|
// a type annotation, that type is returned. If not, an attempt is made to infer
|
15850
15872
|
// the return type. If a list of args is provided, the inference logic may take
|
15851
15873
|
// into account argument types to infer the return type.
|
15852
|
-
function getFunctionEffectiveReturnType(type,
|
15874
|
+
function getFunctionEffectiveReturnType(type, callSiteInfo, inferTypeIfNeeded = true) {
|
15853
15875
|
const specializedReturnType = types_1.FunctionType.getSpecializedReturnType(type, /* includeInferred */ false);
|
15854
15876
|
if (specializedReturnType && !(0, types_1.isUnknown)(specializedReturnType)) {
|
15855
15877
|
return adjustCallableReturnType(type, specializedReturnType, /* liveTypeVarScopes */ []);
|
15856
15878
|
}
|
15857
15879
|
if (inferTypeIfNeeded) {
|
15858
|
-
return getFunctionInferredReturnType(type,
|
15880
|
+
return getFunctionInferredReturnType(type, callSiteInfo);
|
15859
15881
|
}
|
15860
15882
|
return types_1.UnknownType.create();
|
15861
15883
|
}
|
15862
|
-
function _getFunctionInferredReturnType(type,
|
15884
|
+
function _getFunctionInferredReturnType(type, callSiteInfo) {
|
15863
15885
|
var _a;
|
15864
15886
|
let returnType;
|
15865
15887
|
let isIncomplete = false;
|
@@ -15927,7 +15949,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15927
15949
|
types_1.FunctionType.hasUnannotatedParams(type) &&
|
15928
15950
|
!types_1.FunctionType.isStubDefinition(type) &&
|
15929
15951
|
!types_1.FunctionType.isPyTypedDefinition(type) &&
|
15930
|
-
|
15952
|
+
callSiteInfo) {
|
15931
15953
|
let hasDecorators = false;
|
15932
15954
|
let isAsync = false;
|
15933
15955
|
const declNode = (_a = type.details.declaration) === null || _a === void 0 ? void 0 : _a.node;
|
@@ -15942,7 +15964,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15942
15964
|
// We can't use this technique if decorators or async are used because they
|
15943
15965
|
// would need to be applied to the inferred return type.
|
15944
15966
|
if (!hasDecorators && !isAsync) {
|
15945
|
-
const contextualReturnType = getFunctionInferredReturnTypeUsingArguments(type,
|
15967
|
+
const contextualReturnType = getFunctionInferredReturnTypeUsingArguments(type, callSiteInfo);
|
15946
15968
|
if (contextualReturnType) {
|
15947
15969
|
returnType = contextualReturnType;
|
15948
15970
|
}
|
@@ -15950,7 +15972,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15950
15972
|
}
|
15951
15973
|
return returnType;
|
15952
15974
|
}
|
15953
|
-
function getFunctionInferredReturnTypeUsingArguments(type,
|
15975
|
+
function getFunctionInferredReturnTypeUsingArguments(type, callSiteInfo) {
|
15976
|
+
const args = callSiteInfo.args;
|
15954
15977
|
let contextualReturnType;
|
15955
15978
|
if (!type.details.declaration) {
|
15956
15979
|
return undefined;
|
@@ -15988,6 +16011,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15988
16011
|
}
|
15989
16012
|
const paramTypes = [];
|
15990
16013
|
let isResultFromCache = false;
|
16014
|
+
// If the call is located in a loop, don't use literal argument types
|
16015
|
+
// for the same reason we don't do literal math in loops.
|
16016
|
+
const stripLiteralArgTypes = ParseTreeUtils.isWithinLoop(callSiteInfo.errorNode);
|
15991
16017
|
// Suppress diagnostics because we don't want to generate errors.
|
15992
16018
|
suppressDiagnostics(functionNode, () => {
|
15993
16019
|
var _a, _b;
|
@@ -16033,6 +16059,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
16033
16059
|
if (!paramType) {
|
16034
16060
|
paramType = types_1.UnknownType.create();
|
16035
16061
|
}
|
16062
|
+
if (stripLiteralArgTypes) {
|
16063
|
+
paramType = stripLiteralValue(paramType);
|
16064
|
+
}
|
16036
16065
|
paramTypes.push(paramType);
|
16037
16066
|
writeTypeCache(param.name, { type: paramType }, 0 /* EvaluatorFlags.None */);
|
16038
16067
|
}
|
@@ -19047,19 +19076,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
19047
19076
|
: firstParamType);
|
19048
19077
|
}
|
19049
19078
|
}
|
19050
|
-
else
|
19051
|
-
|
19052
|
-
if (
|
19053
|
-
|
19054
|
-
memberTypeFirstParam.
|
19055
|
-
|
19056
|
-
|
19057
|
-
|
19058
|
-
|
19059
|
-
|
19060
|
-
|
19079
|
+
else {
|
19080
|
+
const subDiag = diag === null || diag === void 0 ? void 0 : diag.createAddendum();
|
19081
|
+
if (!assignType(memberTypeFirstParamType, firstParamType, subDiag === null || subDiag === void 0 ? void 0 : subDiag.createAddendum(), typeVarContext,
|
19082
|
+
/* srcTypeVarContext */ undefined, 8192 /* AssignTypeFlags.AllowUnspecifiedTypeArguments */, recursionCount)) {
|
19083
|
+
if (memberTypeFirstParam.name &&
|
19084
|
+
!memberTypeFirstParam.isNameSynthesized &&
|
19085
|
+
memberTypeFirstParam.hasDeclaredType) {
|
19086
|
+
if (subDiag) {
|
19087
|
+
subDiag.addMessage(localize_1.LocMessage.bindTypeMismatch().format({
|
19088
|
+
type: printType(baseType),
|
19089
|
+
methodName: memberType.details.name || '<anonymous>',
|
19090
|
+
paramName: memberTypeFirstParam.name,
|
19091
|
+
}));
|
19092
|
+
}
|
19093
|
+
return undefined;
|
19061
19094
|
}
|
19062
|
-
return undefined;
|
19063
19095
|
}
|
19064
19096
|
}
|
19065
19097
|
}
|