@zzzen/pyright-internal 1.2.0-dev.20240714 → 1.2.0-dev.20240728
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.js +2 -2
- package/dist/analyzer/analyzerNodeInfo.js.map +1 -1
- package/dist/analyzer/binder.js +8 -8
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/cacheManager.js +3 -0
- package/dist/analyzer/cacheManager.js.map +1 -1
- package/dist/analyzer/checker.d.ts +3 -2
- package/dist/analyzer/checker.js +137 -142
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.d.ts +2 -2
- package/dist/analyzer/codeFlowEngine.js +74 -44
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/codeFlowTypes.js +1 -1
- package/dist/analyzer/codeFlowTypes.js.map +1 -1
- package/dist/analyzer/constraintSolver.d.ts +2 -2
- package/dist/analyzer/constraintSolver.js +166 -206
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructorTransform.d.ts +2 -3
- package/dist/analyzer/constructorTransform.js +18 -19
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/constructors.d.ts +3 -3
- package/dist/analyzer/constructors.js +72 -175
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.d.ts +2 -2
- package/dist/analyzer/dataClasses.js +60 -40
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/declaration.d.ts +9 -9
- package/dist/analyzer/declaration.js +9 -9
- package/dist/analyzer/declaration.js.map +1 -1
- package/dist/analyzer/declarationUtils.d.ts +1 -1
- package/dist/analyzer/declarationUtils.js +6 -6
- package/dist/analyzer/declarationUtils.js.map +1 -1
- package/dist/analyzer/decorators.js +5 -6
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/docStringConversion.js +2 -2
- package/dist/analyzer/docStringConversion.js.map +1 -1
- package/dist/analyzer/enums.d.ts +2 -2
- package/dist/analyzer/enums.js +6 -6
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/functionTransform.d.ts +2 -2
- package/dist/analyzer/functionTransform.js +4 -4
- package/dist/analyzer/functionTransform.js.map +1 -1
- package/dist/analyzer/importResolver.js +5 -3
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/namedTuples.d.ts +3 -3
- package/dist/analyzer/namedTuples.js +21 -22
- package/dist/analyzer/namedTuples.js.map +1 -1
- package/dist/analyzer/operations.js +145 -96
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.js +8 -8
- package/dist/analyzer/packageTypeVerifier.js.map +1 -1
- package/dist/analyzer/parameterUtils.d.ts +10 -10
- package/dist/analyzer/parameterUtils.js +60 -59
- package/dist/analyzer/parameterUtils.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.d.ts +7 -6
- package/dist/analyzer/parseTreeUtils.js +47 -24
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/patternMatching.js +109 -90
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.js +11 -4
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/properties.js +23 -19
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.js +23 -20
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/pythonPathUtils.js +1 -1
- package/dist/analyzer/pythonPathUtils.js.map +1 -1
- package/dist/analyzer/service.d.ts +3 -7
- package/dist/analyzer/service.js +28 -30
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/serviceUtils.d.ts +8 -0
- package/dist/analyzer/serviceUtils.js +31 -0
- package/dist/analyzer/serviceUtils.js.map +1 -0
- package/dist/analyzer/sourceFile.js +5 -19
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceMapper.d.ts +1 -1
- package/dist/analyzer/sourceMapper.js +4 -4
- package/dist/analyzer/sourceMapper.js.map +1 -1
- package/dist/analyzer/staticExpressions.js +1 -1
- package/dist/analyzer/staticExpressions.js.map +1 -1
- package/dist/analyzer/testWalker.js +13 -1
- package/dist/analyzer/testWalker.js.map +1 -1
- package/dist/analyzer/tracePrinter.js +4 -4
- package/dist/analyzer/tracePrinter.js.map +1 -1
- package/dist/analyzer/tuples.d.ts +9 -0
- package/dist/analyzer/tuples.js +252 -0
- package/dist/analyzer/tuples.js.map +1 -0
- package/dist/analyzer/typeComplexity.d.ts +2 -0
- package/dist/analyzer/typeComplexity.js +86 -0
- package/dist/analyzer/typeComplexity.js.map +1 -0
- package/dist/analyzer/typeEvaluator.js +1721 -1824
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +47 -40
- package/dist/analyzer/typeEvaluatorTypes.js +10 -1
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +116 -90
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.d.ts +1 -1
- package/dist/analyzer/typePrinter.js +54 -53
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeStubWriter.d.ts +3 -3
- package/dist/analyzer/typeStubWriter.js +15 -15
- package/dist/analyzer/typeStubWriter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +35 -29
- package/dist/analyzer/typeUtils.js +420 -357
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeVarContext.d.ts +24 -36
- package/dist/analyzer/typeVarContext.js +89 -193
- package/dist/analyzer/typeVarContext.js.map +1 -1
- package/dist/analyzer/typeWalker.js +4 -4
- package/dist/analyzer/typeWalker.js.map +1 -1
- package/dist/analyzer/typedDicts.d.ts +2 -2
- package/dist/analyzer/typedDicts.js +49 -53
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +89 -63
- package/dist/analyzer/types.js +163 -120
- package/dist/analyzer/types.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +12 -12
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/common/configOptions.d.ts +1 -0
- package/dist/common/configOptions.js +5 -0
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/diagnosticRules.d.ts +1 -0
- package/dist/common/diagnosticRules.js +1 -0
- package/dist/common/diagnosticRules.js.map +1 -1
- package/dist/common/fileSystem.d.ts +0 -1
- package/dist/common/fileSystem.js.map +1 -1
- package/dist/common/languageServerInterface.d.ts +13 -0
- package/dist/common/languageServerInterface.js +15 -1
- package/dist/common/languageServerInterface.js.map +1 -1
- package/dist/common/lspUtils.js +2 -2
- package/dist/common/memUtils.d.ts +4 -0
- package/dist/common/memUtils.js +33 -2
- package/dist/common/memUtils.js.map +1 -1
- package/dist/common/serviceKeys.d.ts +3 -0
- package/dist/common/serviceKeys.js +2 -0
- package/dist/common/serviceKeys.js.map +1 -1
- package/dist/common/serviceProviderExtensions.js +7 -0
- package/dist/common/serviceProviderExtensions.js.map +1 -1
- package/dist/languageServerBase.d.ts +4 -3
- package/dist/languageServerBase.js +14 -10
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/autoImporter.d.ts +3 -2
- package/dist/languageService/autoImporter.js +5 -1
- package/dist/languageService/autoImporter.js.map +1 -1
- package/dist/languageService/completionProvider.d.ts +5 -3
- package/dist/languageService/completionProvider.js +38 -37
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/completionProviderUtils.d.ts +1 -1
- package/dist/languageService/completionProviderUtils.js +3 -3
- package/dist/languageService/completionProviderUtils.js.map +1 -1
- package/dist/languageService/fileWatcherDynamicFeature.js +2 -2
- package/dist/languageService/fileWatcherDynamicFeature.js.map +1 -1
- package/dist/languageService/hoverProvider.js +14 -6
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/referencesProvider.d.ts +10 -4
- package/dist/languageService/referencesProvider.js +24 -12
- package/dist/languageService/referencesProvider.js.map +1 -1
- package/dist/languageService/renameProvider.js +21 -4
- package/dist/languageService/renameProvider.js.map +1 -1
- package/dist/languageService/signatureHelpProvider.js +1 -1
- package/dist/languageService/signatureHelpProvider.js.map +1 -1
- package/dist/languageService/tooltipUtils.js +3 -3
- package/dist/languageService/tooltipUtils.js.map +1 -1
- package/dist/localization/localize.d.ts +9 -3
- package/dist/localization/localize.js +8 -1
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +5 -2
- package/dist/localization/package.nls.de.json +5 -2
- package/dist/localization/package.nls.en-us.json +7 -1
- package/dist/localization/package.nls.es.json +5 -2
- package/dist/localization/package.nls.fr.json +5 -2
- package/dist/localization/package.nls.it.json +5 -2
- package/dist/localization/package.nls.ja.json +5 -2
- package/dist/localization/package.nls.ko.json +5 -2
- package/dist/localization/package.nls.pl.json +5 -2
- package/dist/localization/package.nls.pt-br.json +5 -2
- package/dist/localization/package.nls.qps-ploc.json +5 -2
- package/dist/localization/package.nls.ru.json +5 -2
- package/dist/localization/package.nls.tr.json +5 -2
- package/dist/localization/package.nls.zh-cn.json +5 -2
- package/dist/localization/package.nls.zh-tw.json +5 -2
- package/dist/parser/parseNodes.d.ts +12 -10
- package/dist/parser/parseNodes.js +23 -21
- package/dist/parser/parseNodes.js.map +1 -1
- package/dist/parser/parser.js +66 -43
- package/dist/parser/parser.js.map +1 -1
- package/dist/tests/checker.test.js +2 -2
- package/dist/tests/fourslash/rename.args.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/rename.args.fourslash.js +71 -0
- package/dist/tests/fourslash/rename.args.fourslash.js.map +1 -0
- package/dist/tests/fourslash/signature.builtinDocstrings.fourslash.js +4 -21
- package/dist/tests/fourslash/signature.builtinDocstrings.fourslash.js.map +1 -1
- package/dist/tests/fourslash/signature.complicated.fourslash.js +1 -1
- package/dist/tests/fourslash/signature.complicated.fourslash.js.map +1 -1
- package/dist/tests/harness/fourslash/fourSlashParser.js +1 -1
- package/dist/tests/harness/fourslash/fourSlashParser.js.map +1 -1
- package/dist/tests/harness/fourslash/testStateUtils.js +2 -2
- package/dist/tests/harness/fourslash/testStateUtils.js.map +1 -1
- package/dist/tests/harness/vfs/filesystem.d.ts +0 -1
- package/dist/tests/harness/vfs/filesystem.js +0 -4
- package/dist/tests/harness/vfs/filesystem.js.map +1 -1
- package/dist/tests/importResolver.test.js +62 -15
- package/dist/tests/importResolver.test.js.map +1 -1
- package/dist/tests/lsp/languageServerTestUtils.js +1 -1
- package/dist/tests/lsp/languageServerTestUtils.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +17 -0
- package/dist/tests/typeEvaluator1.test.js.map +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/typeEvaluator4.test.js +19 -7
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +8 -2
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/dist/tests/typeEvaluator6.test.js +76 -60
- package/dist/tests/typeEvaluator6.test.js.map +1 -1
- package/dist/tests/typeEvaluator7.test.js +5 -1
- package/dist/tests/typeEvaluator7.test.js.map +1 -1
- package/dist/tests/typePrinter.test.js +13 -18
- package/dist/tests/typePrinter.test.js.map +1 -1
- package/dist/workspaceFactory.d.ts +3 -2
- package/dist/workspaceFactory.js +15 -2
- package/dist/workspaceFactory.js.map +1 -1
- package/package.json +1 -1
@@ -110,6 +110,7 @@ function narrowTypeBasedOnSequencePattern(evaluator, type, pattern, isPositiveTe
|
|
110
110
|
let isPlausibleMatch = true;
|
111
111
|
let isDefiniteMatch = true;
|
112
112
|
const narrowedEntryTypes = [];
|
113
|
+
const unnarrowedEntryTypes = [];
|
113
114
|
let canNarrowTuple = entry.isTuple;
|
114
115
|
// Don't attempt to narrow tuples in the negative case if the subject
|
115
116
|
// contains indeterminate-length entries or the tuple is of indeterminate
|
@@ -118,8 +119,8 @@ function narrowTypeBasedOnSequencePattern(evaluator, type, pattern, isPositiveTe
|
|
118
119
|
if (entry.isIndeterminateLength) {
|
119
120
|
canNarrowTuple = false;
|
120
121
|
}
|
121
|
-
if ((0, types_1.isClassInstance)(entry.subtype) && entry.subtype.priv.
|
122
|
-
const unboundedIndex = entry.subtype.priv.
|
122
|
+
if ((0, types_1.isClassInstance)(entry.subtype) && entry.subtype.priv.tupleTypeArgs) {
|
123
|
+
const unboundedIndex = entry.subtype.priv.tupleTypeArgs.findIndex((typeArg) => typeArg.isUnbounded);
|
123
124
|
if (unboundedIndex >= 0) {
|
124
125
|
// If the pattern includes a "star" entry that aligns exactly with
|
125
126
|
// the corresponding unbounded entry in the tuple, we can narrow
|
@@ -138,18 +139,19 @@ function narrowTypeBasedOnSequencePattern(evaluator, type, pattern, isPositiveTe
|
|
138
139
|
isDefiniteMatch = false;
|
139
140
|
}
|
140
141
|
}
|
141
|
-
|
142
|
+
const negativeNarrowedDims = [];
|
142
143
|
pattern.d.entries.forEach((sequenceEntry, index) => {
|
143
144
|
const entryType = getTypeOfPatternSequenceEntry(evaluator, pattern, entry, index, pattern.d.entries.length, pattern.d.starEntryIndex,
|
144
145
|
/* unpackStarEntry */ true);
|
146
|
+
unnarrowedEntryTypes.push(entryType);
|
145
147
|
const narrowedEntryType = narrowTypeBasedOnPattern(evaluator, entryType, sequenceEntry, isPositiveTest);
|
146
148
|
if (isPositiveTest) {
|
147
149
|
if (index === pattern.d.starEntryIndex) {
|
148
150
|
if ((0, types_1.isClassInstance)(narrowedEntryType) &&
|
149
|
-
narrowedEntryType.priv.
|
151
|
+
narrowedEntryType.priv.tupleTypeArgs &&
|
150
152
|
!(0, typeUtils_1.isUnboundedTupleClass)(narrowedEntryType) &&
|
151
|
-
narrowedEntryType.priv.
|
152
|
-
(0, collectionUtils_1.appendArray)(narrowedEntryTypes, narrowedEntryType.priv.
|
153
|
+
narrowedEntryType.priv.tupleTypeArgs) {
|
154
|
+
(0, collectionUtils_1.appendArray)(narrowedEntryTypes, narrowedEntryType.priv.tupleTypeArgs.map((t) => t.type));
|
153
155
|
}
|
154
156
|
else {
|
155
157
|
narrowedEntryTypes.push(narrowedEntryType);
|
@@ -169,10 +171,11 @@ function narrowTypeBasedOnSequencePattern(evaluator, type, pattern, isPositiveTe
|
|
169
171
|
}
|
170
172
|
if (!(0, types_1.isNever)(narrowedEntryType)) {
|
171
173
|
isDefiniteMatch = false;
|
172
|
-
// Record
|
173
|
-
//
|
174
|
-
//
|
175
|
-
|
174
|
+
// Record which entries were narrowed in the negative case
|
175
|
+
// by storing their indexes. If more than one is narrowed,
|
176
|
+
// we need to perform tuple expansion to represent the
|
177
|
+
// resulting narrowed type.
|
178
|
+
negativeNarrowedDims.push(index);
|
176
179
|
narrowedEntryTypes.push(narrowedEntryType);
|
177
180
|
}
|
178
181
|
else {
|
@@ -199,12 +202,22 @@ function narrowTypeBasedOnSequencePattern(evaluator, type, pattern, isPositiveTe
|
|
199
202
|
return false;
|
200
203
|
}
|
201
204
|
// Can we narrow a tuple?
|
202
|
-
if (canNarrowTuple &&
|
205
|
+
if (canNarrowTuple && negativeNarrowedDims.length > 0) {
|
203
206
|
const tupleClassType = evaluator.getBuiltInType(pattern, 'tuple');
|
204
207
|
if (tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
+
// Expand the tuple in the dimensions that were narrowed.
|
209
|
+
// Start with the fully-narrowed set of entries.
|
210
|
+
const expandedEntryTypes = [];
|
211
|
+
for (const dim of negativeNarrowedDims) {
|
212
|
+
const newEntryTypes = [...unnarrowedEntryTypes];
|
213
|
+
newEntryTypes[dim] = narrowedEntryTypes[dim];
|
214
|
+
expandedEntryTypes.push(newEntryTypes);
|
215
|
+
}
|
216
|
+
entry.subtype = (0, types_1.combineTypes)(expandedEntryTypes.map((entryTypes) => {
|
217
|
+
return types_1.ClassType.cloneAsInstance((0, typeUtils_1.specializeTupleClass)(tupleClassType, entryTypes.map((t) => {
|
218
|
+
return { type: t, isUnbounded: false };
|
219
|
+
})));
|
220
|
+
}));
|
208
221
|
}
|
209
222
|
}
|
210
223
|
return true;
|
@@ -229,7 +242,7 @@ function narrowTypeBasedOnSequencePattern(evaluator, type, pattern, isPositiveTe
|
|
229
242
|
// If the type is a union that contains Any or Unknown, remove the other types
|
230
243
|
// before wrapping it in a Sequence.
|
231
244
|
typeArgType = (_a = (0, typeUtils_1.containsAnyOrUnknown)(typeArgType, /* recurse */ false)) !== null && _a !== void 0 ? _a : typeArgType;
|
232
|
-
entry.subtype = types_1.ClassType.cloneAsInstance(types_1.ClassType.
|
245
|
+
entry.subtype = types_1.ClassType.cloneAsInstance(types_1.ClassType.specialize(sequenceType, [typeArgType]));
|
233
246
|
}
|
234
247
|
}
|
235
248
|
}
|
@@ -380,8 +393,8 @@ function getPositionalMatchArgNames(evaluator, type) {
|
|
380
393
|
if ((0, types_1.isClassInstance)(matchArgsType) &&
|
381
394
|
(0, typeUtils_1.isTupleClass)(matchArgsType) &&
|
382
395
|
!(0, typeUtils_1.isUnboundedTupleClass)(matchArgsType) &&
|
383
|
-
matchArgsType.priv.
|
384
|
-
const tupleArgs = matchArgsType.priv.
|
396
|
+
matchArgsType.priv.tupleTypeArgs) {
|
397
|
+
const tupleArgs = matchArgsType.priv.tupleTypeArgs;
|
385
398
|
// Are all the args string literals?
|
386
399
|
if (tupleArgs.every((arg) => (0, types_1.isClassInstance)(arg.type) && types_1.ClassType.isBuiltIn(arg.type, 'str') && (0, typeUtils_1.isLiteralType)(arg.type))) {
|
387
400
|
return tupleArgs.map((arg) => arg.type.priv.literalValue);
|
@@ -455,10 +468,8 @@ function narrowTypeBasedOnClassPattern(evaluator, type, pattern, isPositiveTest)
|
|
455
468
|
return type;
|
456
469
|
}
|
457
470
|
let classType = exprType;
|
458
|
-
if (classType.shared.
|
459
|
-
classType = types_1.ClassType.
|
460
|
-
/* typeArguments */ undefined,
|
461
|
-
/* isTypeArgumentExplicit */ false);
|
471
|
+
if (classType.shared.typeParams.length > 0) {
|
472
|
+
classType = types_1.ClassType.specialize(classType, /* typeArgs */ undefined);
|
462
473
|
}
|
463
474
|
const classInstance = (0, typeUtils_1.convertToInstance)(classType);
|
464
475
|
const isPatternMetaclass = (0, typeUtils_1.isMetaclassInstance)(classInstance);
|
@@ -515,7 +526,7 @@ function narrowTypeBasedOnClassPattern(evaluator, type, pattern, isPositiveTest)
|
|
515
526
|
}
|
516
527
|
}
|
517
528
|
for (let index = 0; index < pattern.d.args.length; index++) {
|
518
|
-
const narrowedArgType =
|
529
|
+
const narrowedArgType = narrowTypeOfClassPatternArg(evaluator, pattern.d.args[index], index, positionalArgNames, subjectSubtypeExpanded, isPositiveTest);
|
519
530
|
if (!(0, types_1.isNever)(narrowedArgType)) {
|
520
531
|
return subjectSubtypeUnexpanded;
|
521
532
|
}
|
@@ -547,7 +558,7 @@ function narrowTypeBasedOnClassPattern(evaluator, type, pattern, isPositiveTest)
|
|
547
558
|
if ((0, types_1.isInstantiableClass)(expandedSubtype) && types_1.ClassType.isBuiltIn(expandedSubtype, 'Callable')) {
|
548
559
|
// Convert to an unknown callable type.
|
549
560
|
const unknownCallable = types_1.FunctionType.createSynthesizedInstance('', 32768 /* FunctionTypeFlags.GradualCallableForm */);
|
550
|
-
types_1.FunctionType.
|
561
|
+
types_1.FunctionType.addDefaultParams(unknownCallable,
|
551
562
|
/* useUnknown */ (0, types_1.isUnknown)(subjectSubtypeExpanded));
|
552
563
|
unknownCallable.shared.declaredReturnType = subjectSubtypeExpanded;
|
553
564
|
return unknownCallable;
|
@@ -592,11 +603,10 @@ function narrowTypeBasedOnClassPattern(evaluator, type, pattern, isPositiveTest)
|
|
592
603
|
// Try to retain the type arguments for the pattern class type.
|
593
604
|
if ((0, types_1.isInstantiableClass)(unexpandedSubtype) && (0, types_1.isClassInstance)(subjectSubtypeExpanded)) {
|
594
605
|
if (types_1.ClassType.isSpecialBuiltIn(unexpandedSubtype) ||
|
595
|
-
unexpandedSubtype.shared.
|
606
|
+
unexpandedSubtype.shared.typeParams.length > 0) {
|
596
607
|
const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(unexpandedSubtype));
|
597
|
-
const unspecializedMatchType = types_1.ClassType.
|
598
|
-
/*
|
599
|
-
/* isTypeArgumentExplicit */ false);
|
608
|
+
const unspecializedMatchType = types_1.ClassType.specialize(unexpandedSubtype,
|
609
|
+
/* typeArgs */ undefined);
|
600
610
|
const matchTypeInstance = types_1.ClassType.cloneAsInstance(unspecializedMatchType);
|
601
611
|
if ((0, constraintSolver_1.addConstraintsForExpectedType)(evaluator, matchTypeInstance, subjectSubtypeExpanded, typeVarContext,
|
602
612
|
/* liveTypeVarScopes */ undefined,
|
@@ -623,7 +633,7 @@ function narrowTypeBasedOnClassPattern(evaluator, type, pattern, isPositiveTest)
|
|
623
633
|
// Narrow the arg pattern. It's possible that the actual type of the object
|
624
634
|
// being matched is a subtype of the resultType, so it might contain additional
|
625
635
|
// attributes that we don't know about.
|
626
|
-
const narrowedArgType =
|
636
|
+
const narrowedArgType = narrowTypeOfClassPatternArg(evaluator, arg, index, positionalArgNames, resultType, isPositiveTest);
|
627
637
|
if ((0, types_1.isNever)(narrowedArgType)) {
|
628
638
|
isMatchValid = false;
|
629
639
|
}
|
@@ -658,7 +668,7 @@ function isClassSpecialCaseForClassPattern(classType) {
|
|
658
668
|
return false;
|
659
669
|
}
|
660
670
|
// Narrows the pattern provided for a class pattern argument.
|
661
|
-
function
|
671
|
+
function narrowTypeOfClassPatternArg(evaluator, arg, argIndex, positionalArgNames, matchType, isPositiveTest) {
|
662
672
|
var _a;
|
663
673
|
let argName;
|
664
674
|
if (arg.d.name) {
|
@@ -802,44 +812,40 @@ function getMappingPatternInfo(evaluator, type, node) {
|
|
802
812
|
});
|
803
813
|
return;
|
804
814
|
}
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
if ((0, types_1.isInstantiableClass)(mroClass) && types_1.ClassType.isBuiltIn(mroClass, 'Mapping')) {
|
809
|
-
mroClassToSpecialize = mroClass;
|
810
|
-
break;
|
811
|
-
}
|
815
|
+
const mappingType = evaluator.getTypingType(node, 'Mapping');
|
816
|
+
if (!mappingType || !(0, types_1.isInstantiableClass)(mappingType)) {
|
817
|
+
return;
|
812
818
|
}
|
813
|
-
|
814
|
-
|
815
|
-
|
819
|
+
const mappingObject = types_1.ClassType.cloneAsInstance(mappingType);
|
820
|
+
// Is it a subtype of Mapping?
|
821
|
+
const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(mappingObject));
|
822
|
+
if (evaluator.assignType(mappingObject, subtype, /* diag */ undefined, typeVarContext)) {
|
823
|
+
const specializedMapping = (0, typeUtils_1.applySolvedTypeVars)(mappingObject, typeVarContext);
|
824
|
+
if (specializedMapping.priv.typeArgs && specializedMapping.priv.typeArgs.length >= 2) {
|
816
825
|
mappingInfo.push({
|
817
826
|
subtype,
|
818
827
|
isDefinitelyMapping: true,
|
819
828
|
isDefinitelyNotMapping: false,
|
820
829
|
dictTypeArgs: {
|
821
|
-
key: specializedMapping.priv.
|
822
|
-
value: specializedMapping.priv.
|
830
|
+
key: specializedMapping.priv.typeArgs[0],
|
831
|
+
value: specializedMapping.priv.typeArgs[1],
|
823
832
|
},
|
824
833
|
});
|
825
834
|
}
|
826
835
|
return;
|
827
836
|
}
|
828
837
|
// Is it a superclass of Mapping?
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
},
|
841
|
-
});
|
842
|
-
}
|
838
|
+
if (evaluator.assignType(subtype, mappingObject)) {
|
839
|
+
mappingInfo.push({
|
840
|
+
subtype,
|
841
|
+
isDefinitelyMapping: false,
|
842
|
+
isDefinitelyNotMapping: false,
|
843
|
+
dictTypeArgs: {
|
844
|
+
key: types_1.UnknownType.create(),
|
845
|
+
value: types_1.UnknownType.create(),
|
846
|
+
},
|
847
|
+
});
|
848
|
+
return;
|
843
849
|
}
|
844
850
|
mappingInfo.push({
|
845
851
|
subtype,
|
@@ -861,7 +867,6 @@ function getSequencePatternInfo(evaluator, pattern, type) {
|
|
861
867
|
var _a;
|
862
868
|
const concreteSubtype = evaluator.makeTopLevelTypeVarsConcrete(subtype);
|
863
869
|
let mroClassToSpecialize;
|
864
|
-
let pushedEntry = false;
|
865
870
|
if ((0, types_1.isClassInstance)(concreteSubtype)) {
|
866
871
|
for (const mroClass of concreteSubtype.shared.mro) {
|
867
872
|
if (!(0, types_1.isInstantiableClass)(mroClass)) {
|
@@ -890,12 +895,12 @@ function getSequencePatternInfo(evaluator, pattern, type) {
|
|
890
895
|
}
|
891
896
|
}
|
892
897
|
if (mroClassToSpecialize) {
|
893
|
-
const specializedSequence = (0, typeUtils_1.partiallySpecializeType)(mroClassToSpecialize, concreteSubtype);
|
898
|
+
const specializedSequence = (0, typeUtils_1.partiallySpecializeType)(mroClassToSpecialize, concreteSubtype, evaluator.getTypeClassType());
|
894
899
|
if ((0, typeUtils_1.isTupleClass)(specializedSequence)) {
|
895
|
-
const typeArgs = (_a = specializedSequence.priv.
|
900
|
+
const typeArgs = (_a = specializedSequence.priv.tupleTypeArgs) !== null && _a !== void 0 ? _a : [
|
896
901
|
{ type: types_1.UnknownType.create(), isUnbounded: true },
|
897
902
|
];
|
898
|
-
const tupleIndeterminateIndex = typeArgs.findIndex((t) => t.isUnbounded || (0, types_1.
|
903
|
+
const tupleIndeterminateIndex = typeArgs.findIndex((t) => t.isUnbounded || (0, types_1.isUnpackedTypeVarTuple)(t.type));
|
899
904
|
let tupleDeterminateEntryCount = typeArgs.length;
|
900
905
|
// If the tuple contains an indeterminate entry, expand or remove that
|
901
906
|
// entry to match the length of the pattern if possible.
|
@@ -917,7 +922,7 @@ function getSequencePatternInfo(evaluator, pattern, type) {
|
|
917
922
|
const removedEntries = typeArgs.splice(patternStarEntryIndex, entriesToCombine);
|
918
923
|
typeArgs.splice(patternStarEntryIndex, 0, {
|
919
924
|
type: (0, types_1.combineTypes)(removedEntries.map((t) => t.type)),
|
920
|
-
isUnbounded: removedEntries.every((t) => t.isUnbounded || (0, types_1.
|
925
|
+
isUnbounded: removedEntries.every((t) => t.isUnbounded || (0, types_1.isUnpackedTypeVarTuple)(t.type)),
|
921
926
|
});
|
922
927
|
}
|
923
928
|
if (typeArgs.length === patternEntryCount) {
|
@@ -949,7 +954,7 @@ function getSequencePatternInfo(evaluator, pattern, type) {
|
|
949
954
|
isDefiniteNoMatch,
|
950
955
|
isPotentialNoMatch,
|
951
956
|
});
|
952
|
-
|
957
|
+
return;
|
953
958
|
}
|
954
959
|
// If the pattern contains a star entry and the pattern associated with
|
955
960
|
// the star entry is unbounded, we can remove it completely under the
|
@@ -988,7 +993,7 @@ function getSequencePatternInfo(evaluator, pattern, type) {
|
|
988
993
|
isTuple: true,
|
989
994
|
isDefiniteNoMatch,
|
990
995
|
});
|
991
|
-
|
996
|
+
return;
|
992
997
|
}
|
993
998
|
}
|
994
999
|
}
|
@@ -996,28 +1001,44 @@ function getSequencePatternInfo(evaluator, pattern, type) {
|
|
996
1001
|
sequenceInfo.push({
|
997
1002
|
subtype,
|
998
1003
|
entryTypes: [
|
999
|
-
specializedSequence.priv.
|
1000
|
-
? specializedSequence.priv.
|
1004
|
+
specializedSequence.priv.typeArgs && specializedSequence.priv.typeArgs.length > 0
|
1005
|
+
? specializedSequence.priv.typeArgs[0]
|
1001
1006
|
: types_1.UnknownType.create(),
|
1002
1007
|
],
|
1003
1008
|
isIndeterminateLength: true,
|
1004
1009
|
isDefiniteNoMatch: false,
|
1005
1010
|
});
|
1006
|
-
|
1011
|
+
return;
|
1007
1012
|
}
|
1008
1013
|
}
|
1009
1014
|
}
|
1010
|
-
if (!
|
1011
|
-
// If it wasn't a subtype of Sequence, see if it's a supertype.
|
1015
|
+
if (!mroClassToSpecialize) {
|
1012
1016
|
const sequenceType = evaluator.getTypingType(pattern, 'Sequence');
|
1013
1017
|
if (sequenceType && (0, types_1.isInstantiableClass)(sequenceType)) {
|
1018
|
+
const sequenceObject = types_1.ClassType.cloneAsInstance(sequenceType);
|
1019
|
+
// Is it a subtype of Sequence?
|
1020
|
+
const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(sequenceType));
|
1021
|
+
if (evaluator.assignType(sequenceObject, subtype, /* diag */ undefined, typeVarContext)) {
|
1022
|
+
const specializedSequence = (0, typeUtils_1.applySolvedTypeVars)(sequenceObject, typeVarContext);
|
1023
|
+
if (specializedSequence.priv.typeArgs && specializedSequence.priv.typeArgs.length > 0) {
|
1024
|
+
sequenceInfo.push({
|
1025
|
+
subtype,
|
1026
|
+
entryTypes: [specializedSequence.priv.typeArgs[0]],
|
1027
|
+
isIndeterminateLength: true,
|
1028
|
+
isDefiniteNoMatch: false,
|
1029
|
+
isPotentialNoMatch: false,
|
1030
|
+
});
|
1031
|
+
return;
|
1032
|
+
}
|
1033
|
+
}
|
1034
|
+
// If it wasn't a subtype of Sequence, see if it's a supertype.
|
1014
1035
|
const sequenceTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(sequenceType));
|
1015
1036
|
if ((0, constraintSolver_1.addConstraintsForExpectedType)(evaluator, types_1.ClassType.cloneAsInstance(sequenceType), subtype, sequenceTypeVarContext, (0, parseTreeUtils_1.getTypeVarScopesForNode)(pattern), pattern.start)) {
|
1016
1037
|
const specializedSequence = (0, typeUtils_1.applySolvedTypeVars)(types_1.ClassType.cloneAsInstantiable(sequenceType), sequenceTypeVarContext);
|
1017
|
-
if (specializedSequence.priv.
|
1038
|
+
if (specializedSequence.priv.typeArgs && specializedSequence.priv.typeArgs.length > 0) {
|
1018
1039
|
sequenceInfo.push({
|
1019
1040
|
subtype,
|
1020
|
-
entryTypes: [specializedSequence.priv.
|
1041
|
+
entryTypes: [specializedSequence.priv.typeArgs[0]],
|
1021
1042
|
isIndeterminateLength: true,
|
1022
1043
|
isDefiniteNoMatch: false,
|
1023
1044
|
isPotentialNoMatch: true,
|
@@ -1025,8 +1046,7 @@ function getSequencePatternInfo(evaluator, pattern, type) {
|
|
1025
1046
|
return;
|
1026
1047
|
}
|
1027
1048
|
}
|
1028
|
-
if (evaluator.assignType(subtype, types_1.ClassType.
|
1029
|
-
/* isTypeArgumentExplicit */ true))) {
|
1049
|
+
if (evaluator.assignType(subtype, types_1.ClassType.specialize(types_1.ClassType.cloneAsInstance(sequenceType), [types_1.UnknownType.create()]))) {
|
1030
1050
|
sequenceInfo.push({
|
1031
1051
|
subtype,
|
1032
1052
|
entryTypes: [types_1.UnknownType.create()],
|
@@ -1037,14 +1057,14 @@ function getSequencePatternInfo(evaluator, pattern, type) {
|
|
1037
1057
|
return;
|
1038
1058
|
}
|
1039
1059
|
}
|
1040
|
-
// Push an entry that indicates that this is definitely not a match.
|
1041
|
-
sequenceInfo.push({
|
1042
|
-
subtype,
|
1043
|
-
entryTypes: [],
|
1044
|
-
isIndeterminateLength: true,
|
1045
|
-
isDefiniteNoMatch: true,
|
1046
|
-
});
|
1047
1060
|
}
|
1061
|
+
// Push an entry that indicates that this is definitely not a match.
|
1062
|
+
sequenceInfo.push({
|
1063
|
+
subtype,
|
1064
|
+
entryTypes: [],
|
1065
|
+
isIndeterminateLength: true,
|
1066
|
+
isDefiniteNoMatch: true,
|
1067
|
+
});
|
1048
1068
|
});
|
1049
1069
|
return sequenceInfo;
|
1050
1070
|
}
|
@@ -1069,7 +1089,7 @@ function getTypeOfPatternSequenceEntry(evaluator, node, sequenceInfo, entryIndex
|
|
1069
1089
|
// its type other than it's "Unknown". We could evaluate it as an
|
1070
1090
|
// "object", but that will cause problems given that this type will
|
1071
1091
|
// be wrapped in a "list" below, and lists are invariant.
|
1072
|
-
if ((0, types_1.
|
1092
|
+
if ((0, types_1.isTypeVarTuple)(type) && !type.priv.isVariadicInUnion) {
|
1073
1093
|
return types_1.UnknownType.create();
|
1074
1094
|
}
|
1075
1095
|
return evaluator.stripLiteralValue(type);
|
@@ -1189,8 +1209,7 @@ function assignTypeToPatternTargets(evaluator, type, isTypeIncomplete, pattern)
|
|
1189
1209
|
const dictClass = evaluator.getBuiltInType(pattern, 'dict');
|
1190
1210
|
const strType = evaluator.getBuiltInObject(pattern, 'str');
|
1191
1211
|
const dictType = dictClass && (0, types_1.isInstantiableClass)(dictClass) && (0, types_1.isClassInstance)(strType)
|
1192
|
-
? types_1.ClassType.cloneAsInstance(types_1.ClassType.
|
1193
|
-
/* isTypeArgumentExplicit */ true))
|
1212
|
+
? types_1.ClassType.cloneAsInstance(types_1.ClassType.specialize(dictClass, [keyType, valueType]))
|
1194
1213
|
: types_1.UnknownType.create();
|
1195
1214
|
evaluator.assignTypeToExpression(mappingEntry.d.target, { type: dictType, isIncomplete: isTypeIncomplete }, mappingEntry.d.target);
|
1196
1215
|
}
|
@@ -1216,7 +1235,7 @@ function assignTypeToPatternTargets(evaluator, type, isTypeIncomplete, pattern)
|
|
1216
1235
|
positionalArgNames = getPositionalMatchArgNames(evaluator, types_1.ClassType.cloneAsInstantiable(expandedSubtype));
|
1217
1236
|
}
|
1218
1237
|
pattern.d.args.forEach((arg, index) => {
|
1219
|
-
const narrowedArgType =
|
1238
|
+
const narrowedArgType = narrowTypeOfClassPatternArg(evaluator, arg, index, positionalArgNames, types_1.ClassType.cloneAsInstantiable(expandedSubtype),
|
1220
1239
|
/* isPositiveTest */ true);
|
1221
1240
|
argTypes[index].push(narrowedArgType);
|
1222
1241
|
});
|
@@ -1255,7 +1274,7 @@ function wrapTypeInList(evaluator, node, type) {
|
|
1255
1274
|
// If the type is a union that contains an Any or Unknown, eliminate the other
|
1256
1275
|
// types before wrapping it in a list.
|
1257
1276
|
type = (_a = (0, typeUtils_1.containsAnyOrUnknown)(type, /* recurse */ false)) !== null && _a !== void 0 ? _a : type;
|
1258
|
-
return types_1.ClassType.
|
1277
|
+
return types_1.ClassType.specialize(listObjectType, [type]);
|
1259
1278
|
}
|
1260
1279
|
return types_1.UnknownType.create();
|
1261
1280
|
}
|
@@ -1273,8 +1292,8 @@ function validateClassPattern(evaluator, pattern) {
|
|
1273
1292
|
// Check for certain uses of type aliases that generate runtime exceptions.
|
1274
1293
|
if (((_b = exprType.props) === null || _b === void 0 ? void 0 : _b.typeAliasInfo) &&
|
1275
1294
|
(0, types_1.isInstantiableClass)(exprType) &&
|
1276
|
-
exprType.priv.
|
1277
|
-
exprType.priv.
|
1295
|
+
exprType.priv.typeArgs &&
|
1296
|
+
exprType.priv.isTypeArgExplicit) {
|
1278
1297
|
evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.classPatternTypeAlias().format({ type: evaluator.printType(exprType) }), pattern.d.className);
|
1279
1298
|
}
|
1280
1299
|
else if (!(0, types_1.isInstantiableClass)(exprType)) {
|
@@ -1324,7 +1343,7 @@ function getPatternSubtypeNarrowingCallback(evaluator, reference, subjectExpress
|
|
1324
1343
|
if (subjectExpression.nodeType === 27 /* ParseNodeType.Index */ &&
|
1325
1344
|
subjectExpression.d.items.length === 1 &&
|
1326
1345
|
!subjectExpression.d.trailingComma &&
|
1327
|
-
subjectExpression.d.items[0].d.argCategory === 0 /*
|
1346
|
+
subjectExpression.d.items[0].d.argCategory === 0 /* ArgCategory.Simple */ &&
|
1328
1347
|
(0, parseTreeUtils_1.isMatchingExpression)(reference, subjectExpression.d.leftExpr)) {
|
1329
1348
|
const indexTypeResult = evaluator.getTypeOfExpression(subjectExpression.d.items[0].d.valueExpr);
|
1330
1349
|
const indexType = indexTypeResult.type;
|
@@ -1375,10 +1394,10 @@ function getPatternSubtypeNarrowingCallback(evaluator, reference, subjectExpress
|
|
1375
1394
|
(0, typeUtils_1.doForEachSubtype)(narrowedSubjectType, (subtype) => {
|
1376
1395
|
if ((0, types_1.isClassInstance)(subtype) &&
|
1377
1396
|
types_1.ClassType.isBuiltIn(subtype, 'tuple') &&
|
1378
|
-
subtype.priv.
|
1379
|
-
matchingEntryIndex < subtype.priv.
|
1380
|
-
subtype.priv.
|
1381
|
-
narrowedSubtypes.push(subtype.priv.
|
1397
|
+
subtype.priv.tupleTypeArgs &&
|
1398
|
+
matchingEntryIndex < subtype.priv.tupleTypeArgs.length &&
|
1399
|
+
subtype.priv.tupleTypeArgs.every((e) => !e.isUnbounded)) {
|
1400
|
+
narrowedSubtypes.push(subtype.priv.tupleTypeArgs[matchingEntryIndex].type);
|
1382
1401
|
}
|
1383
1402
|
else if ((0, types_1.isNever)(narrowedSubjectType)) {
|
1384
1403
|
narrowedSubtypes.push(narrowedSubjectType);
|