@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
@@ -90,7 +90,7 @@ function getTypeNarrowingCallback(evaluator, reference, testExpression, isPositi
|
|
90
90
|
ParseTreeUtils.isMatchingExpression(reference, leftExpression.d.leftExpr) &&
|
91
91
|
leftExpression.d.items.length === 1 &&
|
92
92
|
!leftExpression.d.trailingComma &&
|
93
|
-
leftExpression.d.items[0].d.argCategory === 0 /*
|
93
|
+
leftExpression.d.items[0].d.argCategory === 0 /* ArgCategory.Simple */ &&
|
94
94
|
!leftExpression.d.items[0].d.name &&
|
95
95
|
leftExpression.d.items[0].d.valueExpr.nodeType === 40 /* ParseNodeType.Number */ &&
|
96
96
|
leftExpression.d.items[0].d.valueExpr.d.isInteger &&
|
@@ -126,7 +126,7 @@ function getTypeNarrowingCallback(evaluator, reference, testExpression, isPositi
|
|
126
126
|
// Look for "type(X) is Y", "type(X) is not Y", "type(X) == Y" or "type(X) != Y".
|
127
127
|
if (testExpression.d.leftExpr.nodeType === 9 /* ParseNodeType.Call */) {
|
128
128
|
if (testExpression.d.leftExpr.d.args.length === 1 &&
|
129
|
-
testExpression.d.leftExpr.d.args[0].d.argCategory === 0 /*
|
129
|
+
testExpression.d.leftExpr.d.args[0].d.argCategory === 0 /* ArgCategory.Simple */) {
|
130
130
|
const arg0Expr = testExpression.d.leftExpr.d.args[0].d.valueExpr;
|
131
131
|
if (ParseTreeUtils.isMatchingExpression(reference, arg0Expr)) {
|
132
132
|
const callType = evaluator.getTypeOfExpression(testExpression.d.leftExpr.d.leftExpr, 2 /* EvalFlags.CallBaseDefaults */).type;
|
@@ -175,7 +175,7 @@ function getTypeNarrowingCallback(evaluator, reference, testExpression, isPositi
|
|
175
175
|
if (testExpression.d.leftExpr.nodeType === 27 /* ParseNodeType.Index */ &&
|
176
176
|
testExpression.d.leftExpr.d.items.length === 1 &&
|
177
177
|
!testExpression.d.leftExpr.d.trailingComma &&
|
178
|
-
testExpression.d.leftExpr.d.items[0].d.argCategory === 0 /*
|
178
|
+
testExpression.d.leftExpr.d.items[0].d.argCategory === 0 /* ArgCategory.Simple */ &&
|
179
179
|
ParseTreeUtils.isMatchingExpression(reference, testExpression.d.leftExpr.d.leftExpr)) {
|
180
180
|
const indexTypeResult = evaluator.getTypeOfExpression(testExpression.d.leftExpr.d.items[0].d.valueExpr);
|
181
181
|
const indexType = indexTypeResult.type;
|
@@ -241,7 +241,7 @@ function getTypeNarrowingCallback(evaluator, reference, testExpression, isPositi
|
|
241
241
|
if (testExpression.d.leftExpr.nodeType === 27 /* ParseNodeType.Index */ &&
|
242
242
|
testExpression.d.leftExpr.d.items.length === 1 &&
|
243
243
|
!testExpression.d.leftExpr.d.trailingComma &&
|
244
|
-
testExpression.d.leftExpr.d.items[0].d.argCategory === 0 /*
|
244
|
+
testExpression.d.leftExpr.d.items[0].d.argCategory === 0 /* ArgCategory.Simple */ &&
|
245
245
|
ParseTreeUtils.isMatchingExpression(reference, testExpression.d.leftExpr.d.leftExpr)) {
|
246
246
|
const indexTypeResult = evaluator.getTypeOfExpression(testExpression.d.leftExpr.d.items[0].d.valueExpr);
|
247
247
|
const indexType = indexTypeResult.type;
|
@@ -489,10 +489,11 @@ function getTypeNarrowingCallback(evaluator, reference, testExpression, isPositi
|
|
489
489
|
const functionReturnTypeResult = evaluator.getTypeOfExpression(testExpression);
|
490
490
|
const functionReturnType = functionReturnTypeResult.type;
|
491
491
|
if ((0, types_1.isClassInstance)(functionReturnType) &&
|
492
|
-
types_1.ClassType.isBuiltIn(functionReturnType, '
|
493
|
-
functionReturnType.priv.
|
494
|
-
|
495
|
-
const
|
492
|
+
types_1.ClassType.isBuiltIn(functionReturnType, ['TypeGuard', 'TypeIs']) &&
|
493
|
+
functionReturnType.priv.typeArgs &&
|
494
|
+
functionReturnType.priv.typeArgs.length > 0) {
|
495
|
+
const isStrictTypeGuard = types_1.ClassType.isBuiltIn(functionReturnType, 'TypeIs');
|
496
|
+
const typeGuardType = functionReturnType.priv.typeArgs[0];
|
496
497
|
const isIncomplete = !!callTypeResult.isIncomplete || !!functionReturnTypeResult.isIncomplete;
|
497
498
|
return (type) => {
|
498
499
|
return {
|
@@ -596,14 +597,14 @@ function getDeclsForLocalVar(evaluator, name, reachableFrom, requireUnique) {
|
|
596
597
|
return undefined;
|
597
598
|
}
|
598
599
|
if (decls.length === 0 ||
|
599
|
-
decls.some((decl) => decl.type !== 1 /* DeclarationType.Variable */ && decl.type !== 2 /* DeclarationType.
|
600
|
+
decls.some((decl) => decl.type !== 1 /* DeclarationType.Variable */ && decl.type !== 2 /* DeclarationType.Param */)) {
|
600
601
|
return undefined;
|
601
602
|
}
|
602
603
|
// If there are any assignments within different scopes (e.g. via a "global" or
|
603
604
|
// "nonlocal" reference), don't consider it a local variable.
|
604
605
|
let prevDeclScope;
|
605
606
|
if (decls.some((decl) => {
|
606
|
-
const nodeToConsider = decl.type === 2 /* DeclarationType.
|
607
|
+
const nodeToConsider = decl.type === 2 /* DeclarationType.Param */ ? decl.node.d.name : decl.node;
|
607
608
|
const declScopeNode = ParseTreeUtils.getExecutionScopeNode(nodeToConsider);
|
608
609
|
if (prevDeclScope && declScopeNode !== prevDeclScope) {
|
609
610
|
return true;
|
@@ -624,7 +625,17 @@ function narrowTypeForUserDefinedTypeGuard(evaluator, type, typeGuardType, isPos
|
|
624
625
|
// For non-strict type guards, always narrow to the typeGuardType
|
625
626
|
// in the positive case and don't narrow in the negative case.
|
626
627
|
if (!isStrictTypeGuard) {
|
627
|
-
|
628
|
+
let result = type;
|
629
|
+
if (isPositiveTest) {
|
630
|
+
result = typeGuardType;
|
631
|
+
// If the type guard is a non-constrained TypeVar, add a
|
632
|
+
// condition to the resulting type.
|
633
|
+
if ((0, types_1.isTypeVar)(type) && !(0, types_1.isParamSpec)(type) && type.shared.constraints.length === 0) {
|
634
|
+
result = (0, typeUtils_1.addConditionToType)(result, [{ typeVar: type, constraintIndex: 0 }]);
|
635
|
+
}
|
636
|
+
return result;
|
637
|
+
}
|
638
|
+
return result;
|
628
639
|
}
|
629
640
|
const filterTypes = [];
|
630
641
|
(0, typeUtils_1.doForEachSubtype)(typeGuardType, (typeGuardSubtype) => {
|
@@ -655,14 +666,14 @@ function narrowTypeForTruthiness(evaluator, type, isPositiveTest) {
|
|
655
666
|
function narrowTupleTypeForIsNone(evaluator, type, isPositiveTest, indexValue) {
|
656
667
|
return evaluator.mapSubtypesExpandTypeVars(type, /* options */ undefined, (subtype) => {
|
657
668
|
const tupleType = (0, typeUtils_1.getSpecializedTupleType)(subtype);
|
658
|
-
if (!tupleType || (0, typeUtils_1.isUnboundedTupleClass)(tupleType) || !tupleType.priv.
|
669
|
+
if (!tupleType || (0, typeUtils_1.isUnboundedTupleClass)(tupleType) || !tupleType.priv.tupleTypeArgs) {
|
659
670
|
return subtype;
|
660
671
|
}
|
661
|
-
const tupleLength = tupleType.priv.
|
672
|
+
const tupleLength = tupleType.priv.tupleTypeArgs.length;
|
662
673
|
if (indexValue < 0 || indexValue >= tupleLength) {
|
663
674
|
return subtype;
|
664
675
|
}
|
665
|
-
const typeOfEntry = evaluator.makeTopLevelTypeVarsConcrete(tupleType.priv.
|
676
|
+
const typeOfEntry = evaluator.makeTopLevelTypeVarsConcrete(tupleType.priv.tupleTypeArgs[indexValue].type);
|
666
677
|
if (isPositiveTest) {
|
667
678
|
if (!evaluator.assignType(typeOfEntry, evaluator.getNoneType())) {
|
668
679
|
return undefined;
|
@@ -781,8 +792,8 @@ function getIsInstanceClassTypes(evaluator, argType) {
|
|
781
792
|
}
|
782
793
|
else if ((0, types_1.isFunction)(subtype) &&
|
783
794
|
subtype.shared.parameters.length === 2 &&
|
784
|
-
subtype.shared.parameters[0].category === 1 /*
|
785
|
-
subtype.shared.parameters[1].category === 2 /*
|
795
|
+
subtype.shared.parameters[0].category === 1 /* ParamCategory.ArgsList */ &&
|
796
|
+
subtype.shared.parameters[1].category === 2 /* ParamCategory.KwargsDict */) {
|
786
797
|
classTypeList.push(subtype);
|
787
798
|
}
|
788
799
|
else {
|
@@ -795,8 +806,8 @@ function getIsInstanceClassTypes(evaluator, argType) {
|
|
795
806
|
return;
|
796
807
|
}
|
797
808
|
if ((0, types_1.isClass)(type) && types_1.TypeBase.isInstance(type) && (0, typeUtils_1.isTupleClass)(type)) {
|
798
|
-
if (type.priv.
|
799
|
-
type.priv.
|
809
|
+
if (type.priv.tupleTypeArgs) {
|
810
|
+
type.priv.tupleTypeArgs.forEach((tupleEntry) => {
|
800
811
|
addClassTypesRecursive(tupleEntry.type, recursionCount + 1);
|
801
812
|
});
|
802
813
|
}
|
@@ -826,8 +837,11 @@ function isIsinstanceFilterSuperclass(evaluator, varType, concreteVarType, filte
|
|
826
837
|
return true;
|
827
838
|
}
|
828
839
|
if (isInstanceCheck) {
|
840
|
+
// We convert both types to instances in case they are protocol
|
841
|
+
// classes. A protocol class isn't allowed to be assigned to
|
842
|
+
// type[T], so this would otherwise fail.
|
829
843
|
if (types_1.ClassType.isProtocolClass(concreteFilterType) &&
|
830
|
-
evaluator.assignType(concreteFilterType, concreteVarType)) {
|
844
|
+
evaluator.assignType(types_1.ClassType.cloneAsInstance(concreteFilterType), types_1.ClassType.cloneAsInstance(concreteVarType))) {
|
831
845
|
return true;
|
832
846
|
}
|
833
847
|
}
|
@@ -845,7 +859,11 @@ function isIsinstanceFilterSubclass(evaluator, varType, concreteFilterType, isIn
|
|
845
859
|
return true;
|
846
860
|
}
|
847
861
|
if (isInstanceCheck) {
|
848
|
-
|
862
|
+
// We convert both types to instances in case they are protocol
|
863
|
+
// classes. A protocol class isn't allowed to be assigned to
|
864
|
+
// type[T], so this would otherwise fail.
|
865
|
+
if (types_1.ClassType.isProtocolClass(varType) &&
|
866
|
+
evaluator.assignType(types_1.ClassType.cloneAsInstance(varType), types_1.ClassType.cloneAsInstance(concreteFilterType))) {
|
849
867
|
return true;
|
850
868
|
}
|
851
869
|
}
|
@@ -894,10 +912,8 @@ function narrowTypeForIsInstanceInternal(evaluator, type, filterTypes, isInstanc
|
|
894
912
|
// If the class was implicitly specialized (e.g. because its type
|
895
913
|
// parameters have default values), replace the default type arguments
|
896
914
|
// with Unknown.
|
897
|
-
if (concreteFilterType.priv.
|
898
|
-
concreteFilterType = (0, typeUtils_1.specializeWithUnknownTypeArgs)(types_1.ClassType.
|
899
|
-
/* typeArguments */ undefined,
|
900
|
-
/* isTypeArgumentExplicit */ false), evaluator.getTupleClassType());
|
915
|
+
if (concreteFilterType.priv.typeArgs && !concreteFilterType.priv.isTypeArgExplicit) {
|
916
|
+
concreteFilterType = (0, typeUtils_1.specializeWithUnknownTypeArgs)(types_1.ClassType.specialize(concreteFilterType, /* typeArgs */ undefined), evaluator.getTupleClassType());
|
901
917
|
}
|
902
918
|
filterIsSuperclass = isIsinstanceFilterSuperclass(evaluator, varType, concreteVarType, filterType, concreteFilterType, isInstanceCheck);
|
903
919
|
filterIsSubclass = isIsinstanceFilterSubclass(evaluator, concreteVarType, concreteFilterType, isInstanceCheck);
|
@@ -933,12 +949,10 @@ function narrowTypeForIsInstanceInternal(evaluator, type, filterTypes, isInstanc
|
|
933
949
|
}
|
934
950
|
}
|
935
951
|
else if (filterIsSubclass) {
|
936
|
-
if (evaluator.assignType(concreteVarType, concreteFilterType,
|
952
|
+
if (evaluator.assignType((0, typeUtils_1.convertToInstance)(concreteVarType), (0, typeUtils_1.convertToInstance)(concreteFilterType),
|
937
953
|
/* diag */ undefined,
|
938
954
|
/* destTypeVarContext */ undefined,
|
939
|
-
/* srcTypeVarContext */ undefined, 1024 /* AssignTypeFlags.IgnoreTypeVarScope */ |
|
940
|
-
16384 /* AssignTypeFlags.IgnoreProtocolAssignmentCheck */ |
|
941
|
-
32768 /* AssignTypeFlags.AllowIsinstanceSpecialForms */)) {
|
955
|
+
/* srcTypeVarContext */ undefined, 1024 /* AssignTypeFlags.IgnoreTypeVarScope */ | 16384 /* AssignTypeFlags.AllowIsinstanceSpecialForms */)) {
|
942
956
|
// If the variable type is a superclass of the isinstance
|
943
957
|
// filter, we can narrow the type to the subclass.
|
944
958
|
let specializedFilterType = filterType;
|
@@ -946,16 +960,13 @@ function narrowTypeForIsInstanceInternal(evaluator, type, filterTypes, isInstanc
|
|
946
960
|
// important because a specialized version of the filter cannot
|
947
961
|
// be passed to isinstance or issubclass.
|
948
962
|
if ((0, types_1.isClass)(filterType)) {
|
949
|
-
if (types_1.ClassType.isSpecialBuiltIn(filterType) ||
|
950
|
-
filterType.
|
951
|
-
if (!filterType.priv.typeArguments ||
|
952
|
-
!filterType.priv.isTypeArgumentExplicit ||
|
963
|
+
if (types_1.ClassType.isSpecialBuiltIn(filterType) || filterType.shared.typeParams.length > 0) {
|
964
|
+
if (!filterType.priv.isTypeArgExplicit &&
|
953
965
|
!types_1.ClassType.isSameGenericClass(concreteVarType, filterType)) {
|
954
966
|
const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(filterType));
|
955
|
-
const unspecializedFilterType = types_1.ClassType.
|
956
|
-
/*
|
957
|
-
|
958
|
-
if ((0, constraintSolver_1.addConstraintsForExpectedType)(evaluator, unspecializedFilterType, concreteVarType, typeVarContext,
|
967
|
+
const unspecializedFilterType = types_1.ClassType.specialize(filterType,
|
968
|
+
/* typeArg */ undefined);
|
969
|
+
if ((0, constraintSolver_1.addConstraintsForExpectedType)(evaluator, (0, typeUtils_1.convertToInstance)(unspecializedFilterType), (0, typeUtils_1.convertToInstance)(concreteVarType), typeVarContext,
|
959
970
|
/* liveTypeVarScopes */ undefined, errorNode.start)) {
|
960
971
|
specializedFilterType = (0, typeUtils_1.applySolvedTypeVars)(unspecializedFilterType, typeVarContext, {
|
961
972
|
unknownIfNotFound: true,
|
@@ -969,6 +980,16 @@ function narrowTypeForIsInstanceInternal(evaluator, type, filterTypes, isInstanc
|
|
969
980
|
filteredTypes.push((0, typeUtils_1.addConditionToType)(specializedFilterType, conditions));
|
970
981
|
}
|
971
982
|
}
|
983
|
+
else if (types_1.ClassType.isSameGenericClass(concreteVarType, concreteFilterType)) {
|
984
|
+
// Don't attempt to narrow in this case.
|
985
|
+
if (((_a = concreteVarType.priv) === null || _a === void 0 ? void 0 : _a.literalValue) === undefined &&
|
986
|
+
((_b = concreteFilterType.priv) === null || _b === void 0 ? void 0 : _b.literalValue) === undefined) {
|
987
|
+
const intersection = intersectSameClassType(evaluator, concreteVarType, concreteFilterType);
|
988
|
+
filteredTypes.push(intersection !== null && intersection !== void 0 ? intersection : varType);
|
989
|
+
// Don't attempt to narrow in the negative direction.
|
990
|
+
isClassRelationshipIndeterminate = true;
|
991
|
+
}
|
992
|
+
}
|
972
993
|
else if (allowIntersections &&
|
973
994
|
!types_1.ClassType.isFinal(concreteVarType) &&
|
974
995
|
!types_1.ClassType.isFinal(concreteFilterType)) {
|
@@ -977,39 +998,16 @@ function narrowTypeForIsInstanceInternal(evaluator, type, filterTypes, isInstanc
|
|
977
998
|
// be a mix-in class used with the other. In this case, we'll
|
978
999
|
// synthesize a new class type that represents an intersection of
|
979
1000
|
// the two types.
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
let effectiveMetaclass = concreteVarType.shared.effectiveMetaclass;
|
984
|
-
if (concreteFilterType.shared.effectiveMetaclass) {
|
985
|
-
if (!effectiveMetaclass ||
|
986
|
-
evaluator.assignType(effectiveMetaclass, concreteFilterType.shared.effectiveMetaclass)) {
|
987
|
-
effectiveMetaclass = concreteFilterType.shared.effectiveMetaclass;
|
988
|
-
}
|
989
|
-
}
|
990
|
-
let newClassType = types_1.ClassType.createInstantiable(className, ParseTreeUtils.getClassFullName(errorNode, fileInfo.moduleName, className), fileInfo.moduleName, fileInfo.fileUri, 0 /* ClassTypeFlags.None */, ParseTreeUtils.getTypeSourceId(errorNode),
|
991
|
-
/* declaredMetaclass */ undefined, effectiveMetaclass, concreteVarType.shared.docString);
|
992
|
-
newClassType.shared.baseClasses = [
|
993
|
-
types_1.ClassType.cloneAsInstantiable(concreteVarType),
|
994
|
-
concreteFilterType,
|
995
|
-
];
|
996
|
-
(0, typeUtils_1.computeMroLinearization)(newClassType);
|
997
|
-
newClassType = (0, typeUtils_1.addConditionToType)(newClassType, (_a = concreteFilterType.props) === null || _a === void 0 ? void 0 : _a.condition);
|
998
|
-
if ((0, types_1.isTypeVar)(varType) &&
|
999
|
-
!varType.shared.isParamSpec &&
|
1000
|
-
varType.shared.constraints.length === 0) {
|
1001
|
-
newClassType = (0, typeUtils_1.addConditionToType)(newClassType, [
|
1002
|
-
{ typeVar: varType, constraintIndex: 0 },
|
1003
|
-
]);
|
1004
|
-
}
|
1005
|
-
let newClassInstanceType = types_1.ClassType.cloneAsInstance(newClassType);
|
1006
|
-
if ((_b = concreteVarType.props) === null || _b === void 0 ? void 0 : _b.condition) {
|
1007
|
-
newClassInstanceType = (0, typeUtils_1.addConditionToType)(newClassInstanceType, (_c = concreteVarType.props) === null || _c === void 0 ? void 0 : _c.condition);
|
1001
|
+
let newClassType = evaluator.createSubclass(errorNode, concreteVarType, concreteFilterType);
|
1002
|
+
if ((0, types_1.isTypeVar)(varType) && !(0, types_1.isParamSpec)(varType) && varType.shared.constraints.length === 0) {
|
1003
|
+
newClassType = (0, typeUtils_1.addConditionToType)(newClassType, [{ typeVar: varType, constraintIndex: 0 }]);
|
1008
1004
|
}
|
1005
|
+
let newClassObjType = types_1.ClassType.cloneAsInstance(newClassType);
|
1006
|
+
newClassObjType = (0, typeUtils_1.addConditionToType)(newClassObjType, (_c = concreteVarType.props) === null || _c === void 0 ? void 0 : _c.condition);
|
1009
1007
|
// If this is a issubclass check, we do a double conversion from instantiable
|
1010
1008
|
// to instance back to instantiable to make sure that the includeSubclasses flag
|
1011
1009
|
// gets cleared.
|
1012
|
-
filteredTypes.push(isInstanceCheck ?
|
1010
|
+
filteredTypes.push(isInstanceCheck ? newClassObjType : types_1.ClassType.cloneAsInstantiable(newClassObjType));
|
1013
1011
|
}
|
1014
1012
|
}
|
1015
1013
|
}
|
@@ -1079,7 +1077,7 @@ function narrowTypeForIsInstanceInternal(evaluator, type, filterTypes, isInstanc
|
|
1079
1077
|
else if (evaluator.assignType(concreteVarType, filterType,
|
1080
1078
|
/* diag */ undefined,
|
1081
1079
|
/* destTypeVarContext */ undefined,
|
1082
|
-
/* srcTypeVarContext */ undefined,
|
1080
|
+
/* srcTypeVarContext */ undefined, 16384 /* AssignTypeFlags.AllowIsinstanceSpecialForms */)) {
|
1083
1081
|
if (isPositiveTest) {
|
1084
1082
|
filteredTypes.push(filterType);
|
1085
1083
|
}
|
@@ -1122,7 +1120,7 @@ function narrowTypeForIsInstanceInternal(evaluator, type, filterTypes, isInstanc
|
|
1122
1120
|
// This will normally be treated as type[Any], which is compatible with
|
1123
1121
|
// any metaclass, but we specifically want to treat type as the class
|
1124
1122
|
// type[object] in this case.
|
1125
|
-
if (types_1.ClassType.isBuiltIn(filterMetaclass, 'type') && !filterMetaclass.priv.
|
1123
|
+
if (types_1.ClassType.isBuiltIn(filterMetaclass, 'type') && !filterMetaclass.priv.isTypeArgExplicit) {
|
1126
1124
|
if (!types_1.ClassType.isBuiltIn(metaclassType, 'type')) {
|
1127
1125
|
isMetaclassOverlap = false;
|
1128
1126
|
}
|
@@ -1257,8 +1255,9 @@ function narrowTypeForIsInstanceInternal(evaluator, type, filterTypes, isInstanc
|
|
1257
1255
|
if ((0, types_1.isInstantiableClass)(subtype) || isSubtypeMetaclass) {
|
1258
1256
|
// Handle the special case of isinstance(x, metaclass).
|
1259
1257
|
const includesMetaclassType = filterTypes.some((classType) => (0, typeUtils_1.isInstantiableMetaclass)(classType));
|
1258
|
+
const includesObject = filterTypes.some((classType) => (0, types_1.isInstantiableClass)(classType) && types_1.ClassType.isBuiltIn(classType, 'object'));
|
1260
1259
|
if (isPositiveTest) {
|
1261
|
-
return includesMetaclassType ? negativeFallback : undefined;
|
1260
|
+
return includesMetaclassType || includesObject ? negativeFallback : undefined;
|
1262
1261
|
}
|
1263
1262
|
else {
|
1264
1263
|
return includesMetaclassType ? undefined : negativeFallback;
|
@@ -1300,6 +1299,35 @@ function narrowTypeForIsInstanceInternal(evaluator, type, filterTypes, isInstanc
|
|
1300
1299
|
}
|
1301
1300
|
return filteredType;
|
1302
1301
|
}
|
1302
|
+
// This function assumes that the caller has already verified that the two
|
1303
|
+
// types are the same class and are not literals. It also assumes that the
|
1304
|
+
// caller has verified that type1 is not assignable to type2 or vice versa.
|
1305
|
+
// Returns undefined if there is no intersection between the two types.
|
1306
|
+
function intersectSameClassType(evaluator, type1, type2) {
|
1307
|
+
var _a, _b;
|
1308
|
+
(0, debug_1.assert)((0, types_1.isInstantiableClass)(type1) && (0, types_1.isInstantiableClass)(type2));
|
1309
|
+
(0, debug_1.assert)(types_1.ClassType.isSameGenericClass(type1, type2));
|
1310
|
+
(0, debug_1.assert)(((_a = type1.priv) === null || _a === void 0 ? void 0 : _a.literalValue) === undefined);
|
1311
|
+
(0, debug_1.assert)(((_b = type2.priv) === null || _b === void 0 ? void 0 : _b.literalValue) === undefined);
|
1312
|
+
// Handle tuples specially.
|
1313
|
+
if (types_1.ClassType.isBuiltIn(type1, 'tuple')) {
|
1314
|
+
return intersectTupleTypes(type1, type1);
|
1315
|
+
}
|
1316
|
+
// Indicate that there is no intersection.
|
1317
|
+
return undefined;
|
1318
|
+
}
|
1319
|
+
function intersectTupleTypes(type1, type2) {
|
1320
|
+
var _a, _b;
|
1321
|
+
if (!type2.priv.tupleTypeArgs || (0, typeUtils_1.isTupleGradualForm)(type2)) {
|
1322
|
+
return (0, typeUtils_1.addConditionToType)(type1, (_a = type2.props) === null || _a === void 0 ? void 0 : _a.condition);
|
1323
|
+
}
|
1324
|
+
if (!type1.priv.tupleTypeArgs || (0, typeUtils_1.isTupleGradualForm)(type1)) {
|
1325
|
+
return (0, typeUtils_1.addConditionToType)(type2, (_b = type1.props) === null || _b === void 0 ? void 0 : _b.condition);
|
1326
|
+
}
|
1327
|
+
// For now, don't attempt to narrow in this case.
|
1328
|
+
// TODO - add more sophisticated logic here.
|
1329
|
+
return undefined;
|
1330
|
+
}
|
1303
1331
|
// Attempts to narrow a union of tuples based on their known length.
|
1304
1332
|
function narrowTypeForTupleLength(evaluator, referenceType, lengthValue, isPositiveTest, isLessThanCheck) {
|
1305
1333
|
return (0, typeUtils_1.mapSubtypes)(referenceType, (subtype) => {
|
@@ -1307,23 +1335,23 @@ function narrowTypeForTupleLength(evaluator, referenceType, lengthValue, isPosit
|
|
1307
1335
|
// If it's not a tuple, we can't narrow it.
|
1308
1336
|
if (!(0, types_1.isClassInstance)(concreteSubtype) ||
|
1309
1337
|
!(0, typeUtils_1.isTupleClass)(concreteSubtype) ||
|
1310
|
-
!concreteSubtype.priv.
|
1338
|
+
!concreteSubtype.priv.tupleTypeArgs) {
|
1311
1339
|
return subtype;
|
1312
1340
|
}
|
1313
1341
|
// If the tuple contains a variadic TypeVar, we can't narrow it.
|
1314
|
-
if (concreteSubtype.priv.
|
1342
|
+
if (concreteSubtype.priv.tupleTypeArgs.some((typeArg) => (0, types_1.isUnpackedTypeVarTuple)(typeArg.type))) {
|
1315
1343
|
return subtype;
|
1316
1344
|
}
|
1317
1345
|
// If the tuple contains no unbounded elements, then we know its length exactly.
|
1318
|
-
if (!concreteSubtype.priv.
|
1346
|
+
if (!concreteSubtype.priv.tupleTypeArgs.some((typeArg) => typeArg.isUnbounded)) {
|
1319
1347
|
const tupleLengthMatches = isLessThanCheck
|
1320
|
-
? concreteSubtype.priv.
|
1321
|
-
: concreteSubtype.priv.
|
1348
|
+
? concreteSubtype.priv.tupleTypeArgs.length < lengthValue
|
1349
|
+
: concreteSubtype.priv.tupleTypeArgs.length === lengthValue;
|
1322
1350
|
return tupleLengthMatches === isPositiveTest ? subtype : undefined;
|
1323
1351
|
}
|
1324
1352
|
// The tuple contains a "...". We'll expand this into as many elements as
|
1325
1353
|
// necessary to match the lengthValue.
|
1326
|
-
const elementsToAdd = lengthValue - concreteSubtype.priv.
|
1354
|
+
const elementsToAdd = lengthValue - concreteSubtype.priv.tupleTypeArgs.length + 1;
|
1327
1355
|
if (!isLessThanCheck) {
|
1328
1356
|
// If the specified length is smaller than the minimum length of this tuple,
|
1329
1357
|
// we can rule it out for a positive test and rule it in for a negative test.
|
@@ -1363,7 +1391,7 @@ function narrowTypeForTupleLength(evaluator, referenceType, lengthValue, isPosit
|
|
1363
1391
|
// to) the unbounded element.
|
1364
1392
|
function expandUnboundedTupleElement(tupleType, elementsToAdd, keepUnbounded) {
|
1365
1393
|
const tupleTypeArgs = [];
|
1366
|
-
tupleType.priv.
|
1394
|
+
tupleType.priv.tupleTypeArgs.forEach((typeArg) => {
|
1367
1395
|
if (!typeArg.isUnbounded) {
|
1368
1396
|
tupleTypeArgs.push(typeArg);
|
1369
1397
|
}
|
@@ -1391,13 +1419,13 @@ function narrowTypeForContainerType(evaluator, referenceType, containerType, isP
|
|
1391
1419
|
// with a known length.
|
1392
1420
|
if (!(0, types_1.isClassInstance)(containerType) ||
|
1393
1421
|
!types_1.ClassType.isBuiltIn(containerType, 'tuple') ||
|
1394
|
-
!containerType.priv.
|
1422
|
+
!containerType.priv.tupleTypeArgs) {
|
1395
1423
|
return referenceType;
|
1396
1424
|
}
|
1397
1425
|
// Determine which tuple types can be eliminated. Only "None" and
|
1398
1426
|
// literal types can be handled here.
|
1399
1427
|
const typesToEliminate = [];
|
1400
|
-
containerType.priv.
|
1428
|
+
containerType.priv.tupleTypeArgs.forEach((tupleEntry) => {
|
1401
1429
|
if (!tupleEntry.isUnbounded) {
|
1402
1430
|
if ((0, typeUtils_1.isNoneInstance)(tupleEntry.type)) {
|
1403
1431
|
typesToEliminate.push(tupleEntry.type);
|
@@ -1432,12 +1460,12 @@ function getElementTypeForContainerNarrowing(containerType) {
|
|
1432
1460
|
if (!(0, types_1.isClassInstance)(containerType) || !types_1.ClassType.isBuiltIn(containerType, supportedContainers)) {
|
1433
1461
|
return undefined;
|
1434
1462
|
}
|
1435
|
-
if (!containerType.priv.
|
1463
|
+
if (!containerType.priv.typeArgs || containerType.priv.typeArgs.length < 1) {
|
1436
1464
|
return undefined;
|
1437
1465
|
}
|
1438
|
-
let elementType = containerType.priv.
|
1439
|
-
if ((0, typeUtils_1.isTupleClass)(containerType) && containerType.priv.
|
1440
|
-
elementType = (0, types_1.combineTypes)(containerType.priv.
|
1466
|
+
let elementType = containerType.priv.typeArgs[0];
|
1467
|
+
if ((0, typeUtils_1.isTupleClass)(containerType) && containerType.priv.tupleTypeArgs) {
|
1468
|
+
elementType = (0, types_1.combineTypes)(containerType.priv.tupleTypeArgs.map((t) => t.type));
|
1441
1469
|
}
|
1442
1470
|
return elementType;
|
1443
1471
|
}
|
@@ -1587,10 +1615,8 @@ function narrowTypeForDiscriminatedTupleComparison(evaluator, referenceType, ind
|
|
1587
1615
|
typeof indexLiteralType.priv.literalValue === 'number' &&
|
1588
1616
|
(0, types_1.isClassInstance)(literalType)) {
|
1589
1617
|
const indexValue = indexLiteralType.priv.literalValue;
|
1590
|
-
if (subtype.priv.
|
1591
|
-
indexValue
|
1592
|
-
indexValue < subtype.priv.tupleTypeArguments.length) {
|
1593
|
-
const tupleEntryType = (_a = subtype.priv.tupleTypeArguments[indexValue]) === null || _a === void 0 ? void 0 : _a.type;
|
1618
|
+
if (subtype.priv.tupleTypeArgs && indexValue >= 0 && indexValue < subtype.priv.tupleTypeArgs.length) {
|
1619
|
+
const tupleEntryType = (_a = subtype.priv.tupleTypeArgs[indexValue]) === null || _a === void 0 ? void 0 : _a.type;
|
1594
1620
|
if (tupleEntryType && (0, typeUtils_1.isLiteralTypeOrUnion)(tupleEntryType)) {
|
1595
1621
|
if (isPositiveTest) {
|
1596
1622
|
return evaluator.assignType(tupleEntryType, literalType) ? subtype : undefined;
|
@@ -1736,8 +1762,8 @@ function narrowTypeForClassComparison(evaluator, referenceType, classType, isPos
|
|
1736
1762
|
types_1.TypeBase.isInstance(subtype) &&
|
1737
1763
|
types_1.ClassType.isBuiltIn(concreteSubtype, 'type')) {
|
1738
1764
|
concreteSubtype =
|
1739
|
-
concreteSubtype.priv.
|
1740
|
-
? (0, typeUtils_1.convertToInstantiable)(concreteSubtype.priv.
|
1765
|
+
concreteSubtype.priv.typeArgs && concreteSubtype.priv.typeArgs.length > 0
|
1766
|
+
? (0, typeUtils_1.convertToInstantiable)(concreteSubtype.priv.typeArgs[0])
|
1741
1767
|
: types_1.UnknownType.create();
|
1742
1768
|
}
|
1743
1769
|
if ((0, types_1.isAnyOrUnknown)(concreteSubtype)) {
|
@@ -1897,9 +1923,9 @@ function narrowTypeForCallable(evaluator, type, isPositiveTest, errorNode, allow
|
|
1897
1923
|
newClassType = (0, typeUtils_1.addConditionToType)(newClassType, (_a = subtype.props) === null || _a === void 0 ? void 0 : _a.condition);
|
1898
1924
|
// Add a __call__ method to the new class.
|
1899
1925
|
const callMethod = types_1.FunctionType.createSynthesizedInstance('__call__');
|
1900
|
-
const selfParam = types_1.FunctionParam.create(0 /*
|
1901
|
-
types_1.FunctionType.
|
1902
|
-
types_1.FunctionType.
|
1926
|
+
const selfParam = types_1.FunctionParam.create(0 /* ParamCategory.Simple */, types_1.ClassType.cloneAsInstance(newClassType), types_1.FunctionParamFlags.TypeDeclared, 'self');
|
1927
|
+
types_1.FunctionType.addParam(callMethod, selfParam);
|
1928
|
+
types_1.FunctionType.addDefaultParams(callMethod);
|
1903
1929
|
callMethod.shared.declaredReturnType = types_1.UnknownType.create();
|
1904
1930
|
types_1.ClassType.getSymbolTable(newClassType).set('__call__', symbol_1.Symbol.createWithType(4 /* SymbolFlags.ClassMember */, callMethod));
|
1905
1931
|
return types_1.ClassType.cloneAsInstance(newClassType);
|