@zzzen/pyright-internal 1.2.0-dev.20230212 → 1.2.0-dev.20230226
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/backgroundAnalysisProgram.d.ts +1 -0
- package/dist/analyzer/backgroundAnalysisProgram.js +5 -0
- package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
- package/dist/analyzer/binder.js +9 -1
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.js +12 -6
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +1 -1
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/commentUtils.d.ts +6 -1
- package/dist/analyzer/commentUtils.js +100 -25
- package/dist/analyzer/commentUtils.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +0 -10
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/declaration.d.ts +2 -0
- package/dist/analyzer/declaration.js.map +1 -1
- package/dist/analyzer/importResolver.d.ts +3 -2
- package/dist/analyzer/importResolver.js +28 -19
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/importStatementUtils.d.ts +1 -0
- package/dist/analyzer/importStatementUtils.js +14 -1
- package/dist/analyzer/importStatementUtils.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.d.ts +5 -2
- package/dist/analyzer/parseTreeUtils.js +21 -3
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/patternMatching.d.ts +1 -0
- package/dist/analyzer/patternMatching.js +54 -6
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.d.ts +11 -4
- package/dist/analyzer/program.js +122 -25
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/properties.js +5 -1
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.js +4 -3
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/service.d.ts +7 -6
- package/dist/analyzer/service.js +31 -39
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +4 -0
- package/dist/analyzer/sourceFile.js +85 -16
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +127 -76
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/backgroundAnalysisBase.d.ts +2 -2
- package/dist/backgroundAnalysisBase.js +21 -8
- package/dist/backgroundAnalysisBase.js.map +1 -1
- package/dist/backgroundThreadBase.js +1 -0
- package/dist/backgroundThreadBase.js.map +1 -1
- package/dist/commands/commandController.js +1 -0
- package/dist/commands/commandController.js.map +1 -1
- package/dist/commands/quickActionCommand.js +2 -2
- package/dist/commands/quickActionCommand.js.map +1 -1
- package/dist/common/cancellationUtils.d.ts +18 -2
- package/dist/common/cancellationUtils.js +80 -3
- package/dist/common/cancellationUtils.js.map +1 -1
- package/dist/common/commandLineOptions.d.ts +2 -0
- package/dist/common/commandLineOptions.js.map +1 -1
- package/dist/common/configOptions.d.ts +3 -0
- package/dist/common/configOptions.js +10 -1
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/core.d.ts +2 -0
- package/dist/common/core.js +9 -1
- package/dist/common/core.js.map +1 -1
- package/dist/common/diagnostic.d.ts +15 -3
- package/dist/common/diagnostic.js +13 -4
- package/dist/common/diagnostic.js.map +1 -1
- package/dist/common/editAction.d.ts +1 -0
- package/dist/common/editAction.js +8 -0
- package/dist/common/editAction.js.map +1 -1
- package/dist/common/extensibility.d.ts +36 -12
- package/dist/common/extensibility.js +63 -18
- package/dist/common/extensibility.js.map +1 -1
- package/dist/common/fileBasedCancellationUtils.d.ts +0 -1
- package/dist/common/fileBasedCancellationUtils.js +7 -81
- package/dist/common/fileBasedCancellationUtils.js.map +1 -1
- package/dist/common/pathUtils.d.ts +3 -0
- package/dist/common/pathUtils.js +18 -0
- package/dist/common/pathUtils.js.map +1 -1
- package/dist/common/textEditTracker.d.ts +37 -0
- package/dist/common/textEditTracker.js +301 -0
- package/dist/common/textEditTracker.js.map +1 -0
- package/dist/common/workspaceEditUtils.d.ts +14 -8
- package/dist/common/workspaceEditUtils.js +115 -59
- package/dist/common/workspaceEditUtils.js.map +1 -1
- package/dist/languageServerBase.d.ts +3 -0
- package/dist/languageServerBase.js +93 -4
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/analyzerServiceExecutor.js +1 -0
- package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
- package/dist/languageService/codeActionProvider.js +1 -1
- package/dist/languageService/codeActionProvider.js.map +1 -1
- package/dist/languageService/completionProvider.js +3 -3
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/definitionProvider.js +1 -1
- package/dist/languageService/definitionProvider.js.map +1 -1
- package/dist/languageService/documentSymbolCollector.js +1 -1
- package/dist/languageService/documentSymbolCollector.js.map +1 -1
- package/dist/languageService/hoverProvider.js +13 -6
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/importAdder.d.ts +5 -1
- package/dist/languageService/importAdder.js +50 -14
- package/dist/languageService/importAdder.js.map +1 -1
- package/dist/languageService/indentationUtils.d.ts +5 -1
- package/dist/languageService/indentationUtils.js +12 -2
- package/dist/languageService/indentationUtils.js.map +1 -1
- package/dist/languageService/insertionPointUtils.js +28 -7
- package/dist/languageService/insertionPointUtils.js.map +1 -1
- package/dist/languageService/renameModuleProvider.d.ts +20 -10
- package/dist/languageService/renameModuleProvider.js +300 -229
- package/dist/languageService/renameModuleProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +12 -0
- package/dist/localization/localize.js +6 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.en-us.json +8 -1
- package/dist/tests/checker.test.js +5 -0
- package/dist/tests/checker.test.js.map +1 -1
- package/dist/tests/fourslash/hover.docstring.parameter.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.docstring.parameter.fourslash.js +57 -0
- package/dist/tests/fourslash/hover.docstring.parameter.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.inferred.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.inferred.fourslash.js +24 -0
- package/dist/tests/fourslash/hover.inferred.fourslash.js.map +1 -0
- package/dist/tests/harness/fourslash/testState.js +9 -2
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/importAdder.test.js +40 -3
- package/dist/tests/importAdder.test.js.map +1 -1
- package/dist/tests/indentationUtils.reindent.test.js +1 -1
- package/dist/tests/indentationUtils.reindent.test.js.map +1 -1
- package/dist/tests/insertionPointUtils.test.js +70 -3
- package/dist/tests/insertionPointUtils.test.js.map +1 -1
- package/dist/tests/moveSymbol.importAdder.test.js +192 -0
- package/dist/tests/moveSymbol.importAdder.test.js.map +1 -0
- package/dist/tests/moveSymbol.insertion.test.d.ts +1 -0
- package/dist/tests/moveSymbol.insertion.test.js +397 -0
- package/dist/tests/moveSymbol.insertion.test.js.map +1 -0
- package/dist/tests/moveSymbol.misc.test.d.ts +1 -0
- package/dist/tests/moveSymbol.misc.test.js +142 -0
- package/dist/tests/moveSymbol.misc.test.js.map +1 -0
- package/dist/tests/moveSymbol.updateReference.test.d.ts +1 -0
- package/dist/tests/{updateSymbolReference.test.js → moveSymbol.updateReference.test.js} +235 -158
- package/dist/tests/moveSymbol.updateReference.test.js.map +1 -0
- package/dist/tests/parseTreeUtils.test.js +36 -13
- package/dist/tests/parseTreeUtils.test.js.map +1 -1
- package/dist/tests/renameModuleTestUtils.js +9 -3
- package/dist/tests/renameModuleTestUtils.js.map +1 -1
- package/dist/tests/testStateUtils.d.ts +2 -0
- package/dist/tests/testStateUtils.js +25 -22
- package/dist/tests/testStateUtils.js.map +1 -1
- package/dist/tests/textEditUtil.test.d.ts +1 -0
- package/dist/tests/textEditUtil.test.js +107 -0
- package/dist/tests/textEditUtil.test.js.map +1 -0
- package/dist/tests/typeEvaluator1.test.js +4 -0
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +12 -0
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +9 -0
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +5 -1
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/workspaceEditUtils.test.js +7 -7
- package/dist/tests/workspaceEditUtils.test.js.map +1 -1
- package/dist/workspaceMap.d.ts +0 -1
- package/dist/workspaceMap.js +0 -11
- package/dist/workspaceMap.js.map +1 -1
- package/package.json +3 -3
- package/dist/common/textEditUtils.d.ts +0 -24
- package/dist/common/textEditUtils.js +0 -167
- package/dist/common/textEditUtils.js.map +0 -1
- package/dist/tests/updateSymbolReference.test.js.map +0 -1
- /package/dist/tests/{updateSymbolReference.test.d.ts → moveSymbol.importAdder.test.d.ts} +0 -0
@@ -121,12 +121,12 @@ const binaryOperatorMap = {
|
|
121
121
|
[8 /* BitwiseXor */]: ['__xor__', '__rxor__'],
|
122
122
|
[17 /* LeftShift */]: ['__lshift__', '__rlshift__'],
|
123
123
|
[31 /* RightShift */]: ['__rshift__', '__rrshift__'],
|
124
|
-
[12 /* Equals */]: ['__eq__', '
|
125
|
-
[28 /* NotEquals */]: ['__ne__', '
|
126
|
-
[20 /* LessThan */]: ['__lt__', '
|
127
|
-
[21 /* LessThanOrEqual */]: ['__le__', '
|
128
|
-
[15 /* GreaterThan */]: ['__gt__', '
|
129
|
-
[16 /* GreaterThanOrEqual */]: ['__ge__', '
|
124
|
+
[12 /* Equals */]: ['__eq__', '__eq__'],
|
125
|
+
[28 /* NotEquals */]: ['__ne__', '__ne__'],
|
126
|
+
[20 /* LessThan */]: ['__lt__', '__gt__'],
|
127
|
+
[21 /* LessThanOrEqual */]: ['__le__', '__ge__'],
|
128
|
+
[15 /* GreaterThan */]: ['__gt__', '__lt__'],
|
129
|
+
[16 /* GreaterThanOrEqual */]: ['__ge__', '__le__'],
|
130
130
|
};
|
131
131
|
// Map of operators that always return a bool result.
|
132
132
|
const booleanOperatorMap = {
|
@@ -298,8 +298,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
298
298
|
}
|
299
299
|
}
|
300
300
|
function isTypeCached(node) {
|
301
|
-
const
|
302
|
-
|
301
|
+
const cacheEntry = readTypeCacheEntry(node);
|
302
|
+
if (!cacheEntry) {
|
303
|
+
return false;
|
304
|
+
}
|
305
|
+
return (!cacheEntry.typeResult.isIncomplete || cacheEntry.incompleteGenerationCount === incompleteGenerationCount);
|
303
306
|
}
|
304
307
|
function readTypeCache(node, flags) {
|
305
308
|
var _a, _b;
|
@@ -689,7 +692,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
689
692
|
typeResult.type = types_1.UnknownType.create();
|
690
693
|
}
|
691
694
|
}
|
692
|
-
if (!
|
695
|
+
if (!(0, typeUtils_1.isEffectivelyInstantiable)(typeResult.type)) {
|
693
696
|
const isEmptyVariadic = (0, types_1.isClassInstance)(typeResult.type) &&
|
694
697
|
types_1.ClassType.isTupleClass(typeResult.type) &&
|
695
698
|
((_a = typeResult.type.tupleTypeArguments) === null || _a === void 0 ? void 0 : _a.length) === 0;
|
@@ -2027,7 +2030,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2027
2030
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
2028
2031
|
if ((0, types_1.isUnion)(type)) {
|
2029
2032
|
(0, typeUtils_1.doForEachSubtype)(type, (subtype) => {
|
2030
|
-
if (!
|
2033
|
+
if (!(0, typeUtils_1.isEffectivelyInstantiable)(subtype)) {
|
2031
2034
|
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeNotClass().format({ type: printType(subtype) }));
|
2032
2035
|
}
|
2033
2036
|
});
|
@@ -3703,8 +3706,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3703
3706
|
// Determine whether to replace Self variables with a specific
|
3704
3707
|
// class. Avoid doing this if there's a "bindToType" specified
|
3705
3708
|
// because that case is used for super() calls where we want
|
3706
|
-
// to leave the Self type generic (not specialized).
|
3707
|
-
|
3709
|
+
// to leave the Self type generic (not specialized). We'll also
|
3710
|
+
// skip this for __new__ methods because they are not bound
|
3711
|
+
// to the class but rather assume the type of the cls argument.
|
3712
|
+
const selfClass = bindToType || memberName === '__new__' ? undefined : classType;
|
3708
3713
|
const typeResult = getTypeOfMemberInternal(memberInfo, selfClass);
|
3709
3714
|
if (typeResult) {
|
3710
3715
|
type = typeResult.type;
|
@@ -4007,6 +4012,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4007
4012
|
// If this function is an instance member (e.g. a lambda that was
|
4008
4013
|
// assigned to an instance variable), don't perform any binding.
|
4009
4014
|
if (!isAccessedThroughObject || (memberInfo && !memberInfo.isInstanceMember)) {
|
4015
|
+
// Skip binding if the class appears to be a metaclass (i.e. a subclass of
|
4016
|
+
// `type`) because the first parameter of instance methods in a metaclass
|
4017
|
+
// are not `self` instances.
|
4018
|
+
const isMetaclass = !isAccessedThroughObject &&
|
4019
|
+
(0, types_1.isClass)(baseTypeClass) &&
|
4020
|
+
(flags & 16 /* TreatConstructorAsClassMethod */) === 0 &&
|
4021
|
+
baseTypeClass.details.mro.some((mroType) => (0, types_1.isClass)(mroType) && types_1.ClassType.isBuiltIn(mroType, 'type'));
|
4022
|
+
if (isMetaclass) {
|
4023
|
+
return concreteSubtype;
|
4024
|
+
}
|
4010
4025
|
return bindFunctionToClassOrObject(isAccessedThroughObject ? types_1.ClassType.cloneAsInstance(baseTypeClass) : baseTypeClass, concreteSubtype, memberInfo && (0, types_1.isInstantiableClass)(memberInfo.classType) ? memberInfo.classType : undefined, errorNode,
|
4011
4026
|
/* recursionCount */ undefined, treatConstructorAsClassMember, bindToType);
|
4012
4027
|
}
|
@@ -5185,7 +5200,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5185
5200
|
return { type: types_1.UnknownType.create(/* isIncomplete */ true), isIncomplete: true };
|
5186
5201
|
}
|
5187
5202
|
const assertedType = (0, typeUtils_1.convertToInstance)(getTypeOfArgumentExpectingType(node.arguments[1]).type);
|
5188
|
-
if (!(0, types_1.isTypeSame)(assertedType, arg0TypeResult.type, { treatAnySameAsUnknown: true })) {
|
5203
|
+
if (!(0, types_1.isTypeSame)(assertedType, arg0TypeResult.type, { treatAnySameAsUnknown: true, ignorePseudoGeneric: true })) {
|
5189
5204
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.assertTypeTypeMismatch().format({
|
5190
5205
|
expected: printType(assertedType),
|
5191
5206
|
received: printType(arg0TypeResult.type),
|
@@ -5243,7 +5258,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5243
5258
|
}
|
5244
5259
|
}
|
5245
5260
|
if (expectedRevealType) {
|
5246
|
-
if (!(0, types_1.isTypeSame)(expectedRevealType, type)) {
|
5261
|
+
if (!(0, types_1.isTypeSame)(expectedRevealType, type, { ignorePseudoGeneric: true })) {
|
5247
5262
|
const expectedRevealTypeText = printType(expectedRevealType);
|
5248
5263
|
addError(localize_1.Localizer.Diagnostic.revealTypeExpectedTypeMismatch().format({
|
5249
5264
|
expected: expectedRevealTypeText,
|
@@ -5401,9 +5416,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5401
5416
|
type: resultIsInstance
|
5402
5417
|
? types_1.ClassType.cloneAsInstance(lookupResults.classType)
|
5403
5418
|
: lookupResults.classType,
|
5404
|
-
bindToType:
|
5405
|
-
? types_1.
|
5406
|
-
:
|
5419
|
+
bindToType: bindToType
|
5420
|
+
? types_1.TypeBase.cloneForCondition((0, typeUtils_1.synthesizeTypeVarForSelfCls)(bindToType, !resultIsInstance), bindToType.condition)
|
5421
|
+
: undefined,
|
5407
5422
|
};
|
5408
5423
|
}
|
5409
5424
|
}
|
@@ -5676,6 +5691,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5676
5691
|
});
|
5677
5692
|
const effectiveTypeVarContext = typeVarContext !== null && typeVarContext !== void 0 ? typeVarContext : new typeVarContext_1.TypeVarContext();
|
5678
5693
|
effectiveTypeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(lastMatch.overload));
|
5694
|
+
if (lastMatch.overload.details.constructorTypeVarScopeId) {
|
5695
|
+
effectiveTypeVarContext.addSolveForScope(lastMatch.overload.details.constructorTypeVarScopeId);
|
5696
|
+
}
|
5679
5697
|
effectiveTypeVarContext.unlock();
|
5680
5698
|
return validateFunctionArgumentTypesWithExpectedType(errorNode, lastMatch, effectiveTypeVarContext, skipUnknownArgCheck, inferenceContext);
|
5681
5699
|
};
|
@@ -6394,6 +6412,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6394
6412
|
}
|
6395
6413
|
}
|
6396
6414
|
case 3 /* None */: {
|
6415
|
+
if (types_1.TypeBase.isInstantiable(expandedSubtype)) {
|
6416
|
+
if (noneType && (0, types_1.isInstantiableClass)(noneType)) {
|
6417
|
+
const functionResult = validateCallArguments(errorNode, argList, { type: noneType }, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount);
|
6418
|
+
if (functionResult.isTypeIncomplete) {
|
6419
|
+
isTypeIncomplete = true;
|
6420
|
+
}
|
6421
|
+
if (functionResult.argumentErrors) {
|
6422
|
+
argumentErrors = true;
|
6423
|
+
}
|
6424
|
+
}
|
6425
|
+
return types_1.NoneType.createInstance();
|
6426
|
+
}
|
6397
6427
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportOptionalCall, diagnosticRules_1.DiagnosticRule.reportOptionalCall, localize_1.Localizer.Diagnostic.noneNotCallable(), errorNode);
|
6398
6428
|
return undefined;
|
6399
6429
|
}
|
@@ -8249,9 +8279,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8249
8279
|
/* declaredMetaclass */ undefined, arg1Type.details.effectiveMetaclass);
|
8250
8280
|
arg1Type.tupleTypeArguments.forEach((typeArg) => {
|
8251
8281
|
const specializedType = makeTopLevelTypeVarsConcrete(typeArg.type);
|
8252
|
-
if ((0,
|
8253
|
-
(0, types_1.isAnyOrUnknown)(specializedType) ||
|
8254
|
-
((0, types_1.isClassInstance)(specializedType) && types_1.ClassType.isBuiltIn(specializedType, 'type'))) {
|
8282
|
+
if ((0, typeUtils_1.isEffectivelyInstantiable)(specializedType)) {
|
8255
8283
|
classType.details.baseClasses.push(specializedType);
|
8256
8284
|
}
|
8257
8285
|
else {
|
@@ -8523,9 +8551,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8523
8551
|
}
|
8524
8552
|
}
|
8525
8553
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
8526
|
-
// Don't use literal math if either of the
|
8527
|
-
//
|
8528
|
-
// so the literal values may change each time.
|
8554
|
+
// Don't use literal math if either of the operation is within a loop
|
8555
|
+
// because the literal values may change each time.
|
8529
8556
|
const isLiteralMathAllowed = !ParseTreeUtils.isWithinLoop(node);
|
8530
8557
|
// Don't special-case tuple __add__ if the left type is a union. This
|
8531
8558
|
// can result in an infinite loop if we keep creating new tuple types
|
@@ -8632,11 +8659,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8632
8659
|
// If the LHS class didn't support the magic method for augmented
|
8633
8660
|
// assignment, fall back on the normal binary expression evaluator.
|
8634
8661
|
const binaryOperator = operatorMap[node.operator][1];
|
8635
|
-
// Don't use literal math if either of the
|
8636
|
-
//
|
8637
|
-
|
8638
|
-
const isLiteralMathAllowed = !leftTypeResult.isIncomplete &&
|
8639
|
-
!rightTypeResult.isIncomplete &&
|
8662
|
+
// Don't use literal math if either of the operation is within a loop
|
8663
|
+
// because the literal values may change each time.
|
8664
|
+
const isLiteralMathAllowed = !ParseTreeUtils.isWithinLoop(node) &&
|
8640
8665
|
(0, typeUtils_1.getUnionSubtypeCount)(leftType) * (0, typeUtils_1.getUnionSubtypeCount)(rightType) <
|
8641
8666
|
maxLiteralMathSubtypeCount;
|
8642
8667
|
// Don't special-case tuple __add__ if the left type is a union. This
|
@@ -9516,7 +9541,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9516
9541
|
const typesToCombine = [];
|
9517
9542
|
let isIncomplete = false;
|
9518
9543
|
let typeErrors = false;
|
9519
|
-
|
9544
|
+
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
9545
|
+
const constExprValue = (0, staticExpressions_1.evaluateStaticBoolExpression)(node.testExpression, fileInfo.executionEnvironment, fileInfo.definedConstants);
|
9546
|
+
if (constExprValue !== false && isNodeReachable(node.ifExpression)) {
|
9520
9547
|
const ifType = getTypeOfExpression(node.ifExpression, flags, inferenceContext);
|
9521
9548
|
typesToCombine.push(ifType.type);
|
9522
9549
|
if (ifType.isIncomplete) {
|
@@ -9526,7 +9553,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9526
9553
|
typeErrors = true;
|
9527
9554
|
}
|
9528
9555
|
}
|
9529
|
-
if (isNodeReachable(node.elseExpression)) {
|
9556
|
+
if (constExprValue !== true && isNodeReachable(node.elseExpression)) {
|
9530
9557
|
const elseType = getTypeOfExpression(node.elseExpression, flags, inferenceContext);
|
9531
9558
|
typesToCombine.push(elseType.type);
|
9532
9559
|
if (elseType.isIncomplete) {
|
@@ -9548,14 +9575,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9548
9575
|
if (functionTypeInfo) {
|
9549
9576
|
const returnType = types_1.FunctionType.getSpecializedReturnType(functionTypeInfo.functionType);
|
9550
9577
|
if (returnType) {
|
9578
|
+
expectedYieldType = (0, typeUtils_1.getGeneratorYieldType)(returnType, !!enclosingFunction.isAsync);
|
9551
9579
|
const generatorTypeArgs = (0, typeUtils_1.getGeneratorTypeArgs)(returnType);
|
9552
|
-
if (generatorTypeArgs) {
|
9553
|
-
|
9554
|
-
expectedYieldType = generatorTypeArgs[0];
|
9555
|
-
}
|
9556
|
-
if (generatorTypeArgs.length >= 2) {
|
9557
|
-
sentType = generatorTypeArgs[1];
|
9558
|
-
}
|
9580
|
+
if (generatorTypeArgs && generatorTypeArgs.length >= 2) {
|
9581
|
+
sentType = generatorTypeArgs[1];
|
9559
9582
|
}
|
9560
9583
|
}
|
9561
9584
|
}
|
@@ -10073,7 +10096,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10073
10096
|
if (!validateTypeArg(typeArgs[0])) {
|
10074
10097
|
typeArg0Type = types_1.UnknownType.create();
|
10075
10098
|
}
|
10076
|
-
else if (!
|
10099
|
+
else if (!(0, typeUtils_1.isEffectivelyInstantiable)(typeArg0Type)) {
|
10077
10100
|
addExpectedClassDiagnostic(typeArg0Type, typeArgs[0].node);
|
10078
10101
|
typeArg0Type = types_1.UnknownType.create();
|
10079
10102
|
}
|
@@ -10515,7 +10538,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10515
10538
|
if (!validateTypeArg(typeArg, { allowVariadicTypeVar: true, allowUnpackedTuples: true })) {
|
10516
10539
|
typeArgType = types_1.UnknownType.create();
|
10517
10540
|
}
|
10518
|
-
else if (!
|
10541
|
+
else if (!(0, typeUtils_1.isEffectivelyInstantiable)(typeArgType)) {
|
10519
10542
|
addExpectedClassDiagnostic(typeArgType, typeArg.node);
|
10520
10543
|
typeArgType = types_1.UnknownType.create();
|
10521
10544
|
}
|
@@ -10779,7 +10802,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10779
10802
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
10780
10803
|
// If the entire statement has already been evaluated, don't
|
10781
10804
|
// re-evaluate it.
|
10782
|
-
if (
|
10805
|
+
if (isTypeCached(node)) {
|
10783
10806
|
return;
|
10784
10807
|
}
|
10785
10808
|
let flags = 0 /* None */;
|
@@ -11007,7 +11030,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11007
11030
|
return aliasType;
|
11008
11031
|
}
|
11009
11032
|
function evaluateTypesForAugmentedAssignment(node) {
|
11010
|
-
if (
|
11033
|
+
if (isTypeCached(node)) {
|
11011
11034
|
return;
|
11012
11035
|
}
|
11013
11036
|
const destTypeResult = getTypeOfAugmentedAssignment(node, /* inferenceContext */ undefined);
|
@@ -11118,7 +11141,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11118
11141
|
argType = (0, types_1.removeUnbound)(argType);
|
11119
11142
|
}
|
11120
11143
|
if (!(0, types_1.isAnyOrUnknown)(argType) && !(0, types_1.isUnbound)(argType)) {
|
11121
|
-
if (
|
11144
|
+
if ((0, types_1.isClass)(argType) && types_1.TypeBase.isInstance(argType) && types_1.ClassType.isBuiltIn(argType, 'type')) {
|
11145
|
+
argType =
|
11146
|
+
argType.typeArguments && argType.typeArguments.length > 0
|
11147
|
+
? argType.typeArguments[0]
|
11148
|
+
: types_1.UnknownType.create();
|
11149
|
+
}
|
11150
|
+
else if (!(0, types_1.isInstantiableClass)(argType)) {
|
11122
11151
|
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.baseClassInvalid(), arg);
|
11123
11152
|
argType = types_1.UnknownType.create();
|
11124
11153
|
}
|
@@ -11919,10 +11948,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11919
11948
|
if (functionDecl === null || functionDecl === void 0 ? void 0 : functionDecl.isGenerator) {
|
11920
11949
|
functionFlags |= 16 /* Generator */;
|
11921
11950
|
}
|
11922
|
-
// Special-case magic method __class_getitem__, which is implicitly a class method.
|
11923
|
-
if (containingClassNode && node.name.value === '__class_getitem__') {
|
11924
|
-
functionFlags |= 2 /* ClassMethod */;
|
11925
|
-
}
|
11926
11951
|
if (fileInfo.isStubFile) {
|
11927
11952
|
functionFlags |= 2048 /* StubDefinition */;
|
11928
11953
|
}
|
@@ -12445,15 +12470,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12445
12470
|
function getFunctionFlagsFromDecorators(node, isInClass) {
|
12446
12471
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
12447
12472
|
let flags = 0 /* None */;
|
12448
|
-
|
12449
|
-
|
12450
|
-
|
12451
|
-
|
12452
|
-
|
12453
|
-
|
12454
|
-
|
12455
|
-
|
12456
|
-
|
12473
|
+
if (isInClass) {
|
12474
|
+
// The "__new__" magic method is not an instance method.
|
12475
|
+
// It acts as a static method instead.
|
12476
|
+
if (node.name.value === '__new__') {
|
12477
|
+
flags |= 1 /* ConstructorMethod */;
|
12478
|
+
}
|
12479
|
+
// Several magic methods are treated as class methods implicitly
|
12480
|
+
// by the runtime. Check for these here.
|
12481
|
+
const implicitClassMethods = ['__init_subclass__', '__class_getitem__'];
|
12482
|
+
if (implicitClassMethods.some((name) => node.name.value === name)) {
|
12483
|
+
flags |= 2 /* ClassMethod */;
|
12484
|
+
}
|
12457
12485
|
}
|
12458
12486
|
for (const decoratorNode of node.decorators) {
|
12459
12487
|
// Some stub files (e.g. builtins.pyi) rely on forward declarations of decorators.
|
@@ -12785,14 +12813,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12785
12813
|
const inferredReturnTypes = [];
|
12786
12814
|
if (functionDecl === null || functionDecl === void 0 ? void 0 : functionDecl.returnStatements) {
|
12787
12815
|
functionDecl.returnStatements.forEach((returnNode) => {
|
12788
|
-
var _a;
|
12789
12816
|
if (isNodeReachable(returnNode)) {
|
12790
12817
|
if (returnNode.returnExpression) {
|
12791
12818
|
const returnTypeResult = getTypeOfExpression(returnNode.returnExpression);
|
12792
12819
|
if (returnTypeResult.isIncomplete) {
|
12793
12820
|
isIncomplete = true;
|
12794
12821
|
}
|
12795
|
-
|
12822
|
+
let returnType = returnTypeResult.type;
|
12823
|
+
// If the return type includes an instance of a class with isEmptyContainer
|
12824
|
+
// set, clear that because we don't want this flag to "leak" into the
|
12825
|
+
// inferred return type.
|
12826
|
+
returnType = (0, typeUtils_1.mapSubtypes)(returnType, (subtype) => {
|
12827
|
+
if ((0, types_1.isClassInstance)(subtype) && subtype.isEmptyContainer) {
|
12828
|
+
return types_1.ClassType.cloneForSpecialization(subtype, subtype.typeArguments, !!subtype.isTypeArgumentExplicit, subtype.includeSubclasses, subtype.tupleTypeArguments,
|
12829
|
+
/* isEmptyContainer */ false);
|
12830
|
+
}
|
12831
|
+
return subtype;
|
12832
|
+
});
|
12833
|
+
inferredReturnTypes.push(returnType);
|
12796
12834
|
}
|
12797
12835
|
else {
|
12798
12836
|
inferredReturnTypes.push(types_1.NoneType.createInstance());
|
@@ -12900,7 +12938,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12900
12938
|
}
|
12901
12939
|
function evaluateTypesForForStatement(node) {
|
12902
12940
|
var _a, _b;
|
12903
|
-
if (
|
12941
|
+
if (isTypeCached(node)) {
|
12904
12942
|
return;
|
12905
12943
|
}
|
12906
12944
|
const iteratorTypeResult = getTypeOfExpression(node.iterableExpression);
|
@@ -12911,7 +12949,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12911
12949
|
function evaluateTypesForExceptStatement(node) {
|
12912
12950
|
// This should be called only if the except node has a target exception.
|
12913
12951
|
(0, debug_1.assert)(node.typeExpression !== undefined);
|
12914
|
-
if (
|
12952
|
+
if (isTypeCached(node)) {
|
12915
12953
|
return;
|
12916
12954
|
}
|
12917
12955
|
const exceptionTypeResult = getTypeOfExpression(node.typeExpression);
|
@@ -12959,7 +12997,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12959
12997
|
writeTypeCache(node, { type: targetType }, 0 /* None */);
|
12960
12998
|
}
|
12961
12999
|
function evaluateTypesForWithStatement(node) {
|
12962
|
-
if (
|
13000
|
+
if (isTypeCached(node)) {
|
12963
13001
|
return;
|
12964
13002
|
}
|
12965
13003
|
const exprTypeResult = getTypeOfExpression(node.expression);
|
@@ -13025,7 +13063,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13025
13063
|
}
|
13026
13064
|
function evaluateTypesForImportAs(node) {
|
13027
13065
|
var _a;
|
13028
|
-
if (
|
13066
|
+
if (isTypeCached(node)) {
|
13029
13067
|
return;
|
13030
13068
|
}
|
13031
13069
|
let symbolNameNode;
|
@@ -13057,7 +13095,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13057
13095
|
}
|
13058
13096
|
function evaluateTypesForImportFromAs(node) {
|
13059
13097
|
var _a;
|
13060
|
-
if (
|
13098
|
+
if (isTypeCached(node)) {
|
13061
13099
|
return;
|
13062
13100
|
}
|
13063
13101
|
const aliasNode = node.alias || node.name;
|
@@ -13113,7 +13151,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13113
13151
|
writeTypeCache(node, { type: symbolType }, 0 /* None */);
|
13114
13152
|
}
|
13115
13153
|
function evaluateTypesForMatchStatement(node) {
|
13116
|
-
if (
|
13154
|
+
if (isTypeCached(node)) {
|
13117
13155
|
return;
|
13118
13156
|
}
|
13119
13157
|
const subjectTypeResult = getTypeOfExpression(node.subjectExpression);
|
@@ -13128,19 +13166,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13128
13166
|
writeTypeCache(node, { type: subjectType, isIncomplete: !!subjectTypeResult.isIncomplete }, 0 /* None */);
|
13129
13167
|
}
|
13130
13168
|
function evaluateTypesForCaseStatement(node) {
|
13131
|
-
if (
|
13169
|
+
if (isTypeCached(node)) {
|
13132
13170
|
return;
|
13133
13171
|
}
|
13134
13172
|
if (!node.parent || node.parent.nodeType !== 63 /* Match */) {
|
13135
13173
|
(0, debug_1.fail)('Expected parent of case statement to be match statement');
|
13136
13174
|
return;
|
13137
13175
|
}
|
13176
|
+
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
13138
13177
|
const subjectTypeResult = getTypeOfExpression(node.parent.subjectExpression);
|
13139
13178
|
let subjectType = subjectTypeResult.type;
|
13140
13179
|
// Apply negative narrowing for each of the cases prior to the current one
|
13141
13180
|
// except for those that have a guard expression.
|
13142
13181
|
for (const caseStatement of node.parent.cases) {
|
13143
13182
|
if (caseStatement === node) {
|
13183
|
+
if (fileInfo.diagnosticRuleSet.reportUnnecessaryComparison !== 'none') {
|
13184
|
+
(0, patternMatching_1.checkForUnusedPattern)(evaluatorInterface, node.pattern, subjectType);
|
13185
|
+
}
|
13144
13186
|
break;
|
13145
13187
|
}
|
13146
13188
|
if (!caseStatement.guardExpression) {
|
@@ -13162,7 +13204,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13162
13204
|
writeTypeCache(node, { type: subjectType, isIncomplete: !!subjectTypeResult.isIncomplete }, 0 /* None */);
|
13163
13205
|
}
|
13164
13206
|
function evaluateTypesForImportFrom(node) {
|
13165
|
-
if (
|
13207
|
+
if (isTypeCached(node)) {
|
13166
13208
|
return;
|
13167
13209
|
}
|
13168
13210
|
// Use the first element of the name parts as the symbol.
|
@@ -14944,7 +14986,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14944
14986
|
// Infer the type.
|
14945
14987
|
const typesToCombine = [];
|
14946
14988
|
const decls = symbol.getDeclarations();
|
14947
|
-
const isFinalVar = (0, symbolUtils_1.isFinalVariable)(symbol);
|
14948
14989
|
let isIncomplete = false;
|
14949
14990
|
let sawPendingEvaluation = false;
|
14950
14991
|
let includesVariableDecl = false;
|
@@ -15042,7 +15083,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15042
15083
|
if (!fileInfo.isTypingStubFile) {
|
15043
15084
|
includesVariableDecl = true;
|
15044
15085
|
}
|
15045
|
-
let isConstant =
|
15086
|
+
let isConstant = false;
|
15087
|
+
if (resolvedDecl.type === 1 /* Variable */) {
|
15088
|
+
if (resolvedDecl.isConstant || resolvedDecl.isFinal) {
|
15089
|
+
isConstant = true;
|
15090
|
+
}
|
15091
|
+
}
|
15046
15092
|
// Treat enum values declared within an enum class as though they are const even
|
15047
15093
|
// though they may not be named as such.
|
15048
15094
|
if ((0, types_1.isClassInstance)(type) &&
|
@@ -15052,7 +15098,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15052
15098
|
}
|
15053
15099
|
// If the symbol is constant, we can retain the literal
|
15054
15100
|
// value. Otherwise, strip literal values to widen the type.
|
15055
|
-
if (types_1.TypeBase.isInstance(type) && !isExplicitTypeAlias && !isConstant
|
15101
|
+
if (types_1.TypeBase.isInstance(type) && !isExplicitTypeAlias && !isConstant) {
|
15056
15102
|
type = stripLiteralValue(type);
|
15057
15103
|
}
|
15058
15104
|
}
|
@@ -15695,12 +15741,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15695
15741
|
// specified inheritance chain, taking into account its type arguments.
|
15696
15742
|
function assignClassWithTypeArgs(destType, srcType, inheritanceChain, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount) {
|
15697
15743
|
let curSrcType = srcType;
|
15698
|
-
let
|
15744
|
+
let curDestTypeVarContext = destTypeVarContext;
|
15699
15745
|
let effectiveFlags = flags;
|
15700
15746
|
inferTypeParameterVarianceForClass(destType);
|
15701
15747
|
effectiveFlags |= 8 /* SkipSolveTypeVars */;
|
15702
15748
|
if (!destTypeVarContext) {
|
15703
|
-
|
15749
|
+
curDestTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(destType));
|
15704
15750
|
effectiveFlags &= ~8 /* SkipSolveTypeVars */;
|
15705
15751
|
}
|
15706
15752
|
else {
|
@@ -15711,6 +15757,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15711
15757
|
}
|
15712
15758
|
for (let ancestorIndex = inheritanceChain.length - 1; ancestorIndex >= 0; ancestorIndex--) {
|
15713
15759
|
const ancestorType = inheritanceChain[ancestorIndex];
|
15760
|
+
const curSrcTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(curSrcType));
|
15714
15761
|
// If we've hit an "unknown", all bets are off, and we need to assume
|
15715
15762
|
// that the type is assignable.
|
15716
15763
|
if ((0, types_1.isUnknown)(ancestorType)) {
|
@@ -15728,7 +15775,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15728
15775
|
// Handle built-in types that support arbitrary numbers
|
15729
15776
|
// of type parameters like Tuple.
|
15730
15777
|
if (ancestorIndex === 0 && destType.tupleTypeArguments && curSrcType.tupleTypeArguments) {
|
15731
|
-
return assignTupleTypeArgs(destType, curSrcType, diag,
|
15778
|
+
return assignTupleTypeArgs(destType, curSrcType, diag, curDestTypeVarContext, flags, recursionCount);
|
15732
15779
|
}
|
15733
15780
|
// If there are no type parameters on this class, we're done.
|
15734
15781
|
const ancestorTypeParams = types_1.ClassType.getTypeParameters(ancestorType);
|
@@ -15740,12 +15787,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15740
15787
|
return true;
|
15741
15788
|
}
|
15742
15789
|
// Validate that the type arguments match.
|
15743
|
-
if (!verifyTypeArgumentsAssignable(ancestorType, curSrcType, diag,
|
15744
|
-
/* srcTypeVarContext */ undefined, effectiveFlags, recursionCount)) {
|
15790
|
+
if (!verifyTypeArgumentsAssignable(ancestorType, curSrcType, diag, curDestTypeVarContext, curSrcTypeVarContext, effectiveFlags, recursionCount)) {
|
15745
15791
|
return false;
|
15746
15792
|
}
|
15747
15793
|
// Allocate a new type var map for the next time through the loop.
|
15748
|
-
|
15794
|
+
curDestTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(ancestorType));
|
15749
15795
|
effectiveFlags &= ~8 /* SkipSolveTypeVars */;
|
15750
15796
|
}
|
15751
15797
|
if (destType.typeArguments) {
|
@@ -16108,8 +16154,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16108
16154
|
if ((0, types_1.isUnion)(destType)) {
|
16109
16155
|
return assignToUnionType(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, originalFlags, recursionCount);
|
16110
16156
|
}
|
16111
|
-
if ((0, types_1.isNoneInstance)(destType)
|
16112
|
-
|
16157
|
+
if ((0, types_1.isNoneInstance)(destType)) {
|
16158
|
+
if ((0, types_1.isNoneInstance)(srcType)) {
|
16159
|
+
return true;
|
16160
|
+
}
|
16161
|
+
if ((0, types_1.isClassInstance)(srcType) && types_1.ClassType.isBuiltIn(srcType, 'NoneType')) {
|
16162
|
+
return true;
|
16163
|
+
}
|
16113
16164
|
}
|
16114
16165
|
if ((0, types_1.isNoneTypeClass)(destType)) {
|
16115
16166
|
if ((0, types_1.isNoneTypeClass)(srcType)) {
|