@zzzen/pyright-internal 1.2.0-dev.20240630 → 1.2.0-dev.20240707
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/binder.js +1 -1
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.js +4 -0
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +58 -23
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/constraintSolver.d.ts +1 -1
- package/dist/analyzer/constraintSolver.js +3 -3
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructors.js +34 -29
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +6 -3
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/declaration.d.ts +1 -1
- package/dist/analyzer/decorators.js +12 -12
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/enums.js +1 -1
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/operations.d.ts +4 -4
- package/dist/analyzer/operations.js +6 -6
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/patternMatching.js +27 -12
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/protocols.js +1 -1
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +3 -2
- package/dist/analyzer/sourceFile.js +5 -5
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +547 -531
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +28 -27
- package/dist/analyzer/typeEvaluatorTypes.js +45 -41
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +22 -18
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +12 -6
- package/dist/analyzer/typeUtils.js +36 -10
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/types.d.ts +3 -1
- package/dist/analyzer/types.js +7 -0
- package/dist/analyzer/types.js.map +1 -1
- package/dist/common/diagnostic.d.ts +14 -0
- package/dist/common/diagnostic.js +41 -1
- package/dist/common/diagnostic.js.map +1 -1
- package/dist/common/diagnosticSink.d.ts +4 -0
- package/dist/common/diagnosticSink.js +21 -1
- package/dist/common/diagnosticSink.js.map +1 -1
- package/dist/languageService/completionProvider.d.ts +1 -1
- package/dist/languageService/completionProvider.js +3 -3
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +3 -0
- package/dist/localization/localize.js +1 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.en-us.json +2 -1
- package/dist/parser/parser.js +6 -3
- package/dist/parser/parser.js.map +1 -1
- package/dist/pyright.js +265 -5
- package/dist/pyright.js.map +1 -1
- package/dist/tests/fourslash/hover.init.fourslash.js +1 -1
- package/dist/tests/fourslash/hover.init.fourslash.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +2 -2
- package/dist/tests/typeEvaluator3.test.js +2 -2
- package/dist/tests/typeEvaluator4.test.js +1 -1
- package/dist/tests/typeEvaluator7.test.js +2 -2
- package/dist/tests/typeEvaluator7.test.js.map +1 -1
- package/package.json +1 -1
@@ -15,35 +15,36 @@ import { AssignTypeFlags, ClassMember, InferenceContext, MemberAccessFlags, Uniq
|
|
15
15
|
import { TypeVarContext } from './typeVarContext';
|
16
16
|
import { AnyType, ClassType, FunctionParameter, FunctionType, OverloadedFunctionType, Type, TypeCondition, TypeVarType, UnknownType, Variance } from './types';
|
17
17
|
export declare const maxSubtypesForInferredType = 64;
|
18
|
-
export declare const enum
|
18
|
+
export declare const enum EvalFlags {
|
19
19
|
None = 0,
|
20
20
|
ConvertEllipsisToAny = 1,
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
21
|
+
NoSpecialize = 2,
|
22
|
+
ForwardRefs = 4,
|
23
|
+
StrLiteralAsType = 8,
|
24
|
+
NoFinal = 16,
|
25
|
+
NoParamSpec = 32,
|
26
|
+
NoTypeVarTuple = 64,
|
27
|
+
InstantiableType = 128,
|
28
|
+
TypeExpression = 256,
|
29
29
|
AllowMissingTypeArgs = 512,
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
30
|
+
AllowGeneric = 1024,
|
31
|
+
NoTypeVarWithScopeId = 2048,
|
32
|
+
AllowTypeVarWithoutScopeId = 4096,
|
33
|
+
TypeVarGetsCurScope = 8192,
|
34
|
+
EnforceVarianceConsistency = 16384,
|
35
|
+
VarTypeAnnotation = 32768,
|
36
|
+
NoClassVar = 131072,
|
37
|
+
NoNakedGeneric = 262144,
|
38
|
+
NotParsed = 524288,
|
39
39
|
AllowRequired = 1048576,
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
AllowUnpackedTuple = 2097152,
|
41
|
+
AllowUnpackedTypedDict = 4194304,
|
42
|
+
ParsesStringLiteral = 8388608,
|
43
|
+
NoConvertSpecialForm = 33554432,
|
44
|
+
NoNonTypeSpecialForms = 67108864,
|
45
45
|
AllowConcatenate = 134217728,
|
46
|
-
|
46
|
+
StripTupleLiterals = 268435456,
|
47
|
+
IsinstanceParam = 536870912,
|
47
48
|
CallBaseDefaults = 2,
|
48
49
|
IndexBaseDefaults = 2,
|
49
50
|
MemberAccessBaseDefaults = 2
|
@@ -239,7 +240,7 @@ export interface TypeEvaluator {
|
|
239
240
|
getTypeResult: (node: ExpressionNode) => TypeResult | undefined;
|
240
241
|
getTypeResultForDecorator: (node: DecoratorNode) => TypeResult | undefined;
|
241
242
|
getCachedType: (node: ExpressionNode) => Type | undefined;
|
242
|
-
getTypeOfExpression: (node: ExpressionNode, flags?:
|
243
|
+
getTypeOfExpression: (node: ExpressionNode, flags?: EvalFlags, context?: InferenceContext) => TypeResult;
|
243
244
|
getTypeOfAnnotation: (node: ExpressionNode, options?: AnnotationTypeOptions) => Type;
|
244
245
|
getTypeOfClass: (node: ClassNode) => ClassTypeResult | undefined;
|
245
246
|
getTypeOfFunction: (node: FunctionNode) => FunctionTypeResult | undefined;
|
@@ -312,7 +313,7 @@ export interface TypeEvaluator {
|
|
312
313
|
inferReturnTypeIfNecessary: (type: Type) => void;
|
313
314
|
inferTypeParameterVarianceForClass: (type: ClassType) => void;
|
314
315
|
assignTypeArguments: (destType: ClassType, srcType: ClassType, diag: DiagnosticAddendum | undefined, destTypeVarContext: TypeVarContext | undefined, srcTypeVarContext: TypeVarContext | undefined, flags: AssignTypeFlags, recursionCount: number) => boolean;
|
315
|
-
reportMissingTypeArguments: (node: ExpressionNode, type: Type, flags:
|
316
|
+
reportMissingTypeArguments: (node: ExpressionNode, type: Type, flags: EvalFlags) => Type;
|
316
317
|
isFinalVariable: (symbol: Symbol) => boolean;
|
317
318
|
isFinalVariableDeclaration: (decl: Declaration) => boolean;
|
318
319
|
isExplicitTypeAliasDeclaration: (decl: Declaration) => boolean;
|
@@ -332,7 +333,7 @@ export interface TypeEvaluator {
|
|
332
333
|
disposeEvaluator: () => void;
|
333
334
|
useSpeculativeMode: <T>(speculativeNode: ParseNode | undefined, callback: () => T) => T;
|
334
335
|
isSpeculativeModeInUse: (node: ParseNode | undefined) => boolean;
|
335
|
-
setTypeResultForNode: (node: ParseNode, typeResult: TypeResult, flags?:
|
336
|
+
setTypeResultForNode: (node: ParseNode, typeResult: TypeResult, flags?: EvalFlags) => void;
|
336
337
|
checkForCancellation: () => void;
|
337
338
|
printControlFlowGraph: (flowNode: FlowNode, reference: CodeFlowReferenceExpressionNode | undefined, callName: string, logger: ConsoleInterface) => void;
|
338
339
|
printTypeVarContext: (typeVarContext: TypeVarContext) => void;
|
@@ -8,89 +8,93 @@
|
|
8
8
|
* Abstract interface and other helper types for type evaluator module.
|
9
9
|
*/
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
11
|
-
exports.
|
11
|
+
exports.EvalFlags = exports.maxSubtypesForInferredType = void 0;
|
12
12
|
// Maximum number of unioned subtypes for an inferred type (e.g.
|
13
13
|
// a list) before the type is considered an "Any".
|
14
14
|
exports.maxSubtypesForInferredType = 64;
|
15
|
-
var
|
16
|
-
(function (
|
17
|
-
|
15
|
+
var EvalFlags;
|
16
|
+
(function (EvalFlags) {
|
17
|
+
EvalFlags[EvalFlags["None"] = 0] = "None";
|
18
18
|
// Interpret an ellipsis type annotation to mean "Any".
|
19
|
-
|
19
|
+
EvalFlags[EvalFlags["ConvertEllipsisToAny"] = 1] = "ConvertEllipsisToAny";
|
20
20
|
// Normally a generic named type is specialized with "Any"
|
21
21
|
// types. This flag indicates that specialization shouldn't take
|
22
22
|
// place.
|
23
|
-
|
23
|
+
EvalFlags[EvalFlags["NoSpecialize"] = 2] = "NoSpecialize";
|
24
24
|
// Allow forward references. Don't report unbound errors.
|
25
|
-
|
25
|
+
EvalFlags[EvalFlags["ForwardRefs"] = 4] = "ForwardRefs";
|
26
26
|
// Treat string literal as a type.
|
27
|
-
|
27
|
+
EvalFlags[EvalFlags["StrLiteralAsType"] = 8] = "StrLiteralAsType";
|
28
28
|
// 'Final' is not allowed in this context.
|
29
|
-
|
29
|
+
EvalFlags[EvalFlags["NoFinal"] = 16] = "NoFinal";
|
30
30
|
// A ParamSpec isn't allowed in this context.
|
31
|
-
|
31
|
+
EvalFlags[EvalFlags["NoParamSpec"] = 32] = "NoParamSpec";
|
32
32
|
// A TypeVarTuple isn't allowed in this context.
|
33
|
-
|
33
|
+
EvalFlags[EvalFlags["NoTypeVarTuple"] = 64] = "NoTypeVarTuple";
|
34
34
|
// Expression is expected to be an instantiable type rather
|
35
35
|
// than an instance (object)
|
36
|
-
|
37
|
-
// A type
|
38
|
-
//
|
36
|
+
EvalFlags[EvalFlags["InstantiableType"] = 128] = "InstantiableType";
|
37
|
+
// A type expression imposes grammatical and semantic limits on an
|
38
|
+
// expression. If this flag is set, illegal type expressions are
|
39
39
|
// flagged as errors.
|
40
|
-
|
40
|
+
EvalFlags[EvalFlags["TypeExpression"] = 256] = "TypeExpression";
|
41
41
|
// Suppress the reportMissingTypeArgument diagnostic in this context.
|
42
|
-
|
42
|
+
EvalFlags[EvalFlags["AllowMissingTypeArgs"] = 512] = "AllowMissingTypeArgs";
|
43
43
|
// The Generic class type is allowed in this context. It is
|
44
44
|
// normally not allowed if ExpectingType is set.
|
45
|
-
|
45
|
+
EvalFlags[EvalFlags["AllowGeneric"] = 1024] = "AllowGeneric";
|
46
46
|
// TypeVars within this expression must not refer to type vars
|
47
47
|
// used in an outer scope.
|
48
|
-
|
48
|
+
EvalFlags[EvalFlags["NoTypeVarWithScopeId"] = 2048] = "NoTypeVarWithScopeId";
|
49
49
|
// TypeVars within this expression do not need to refer to type vars
|
50
50
|
// used in an outer scope.
|
51
|
-
|
51
|
+
EvalFlags[EvalFlags["AllowTypeVarWithoutScopeId"] = 4096] = "AllowTypeVarWithoutScopeId";
|
52
52
|
// TypeVars within this expression that are otherwise not
|
53
53
|
// associated with an outer scope should be associated with
|
54
54
|
// the containing function's scope.
|
55
|
-
|
55
|
+
EvalFlags[EvalFlags["TypeVarGetsCurScope"] = 8192] = "TypeVarGetsCurScope";
|
56
56
|
// When a new class-scoped TypeVar is used within a class
|
57
57
|
// declaration, make sure that it is not used to parameterize
|
58
58
|
// a base class whose TypeVar variance is inconsistent.
|
59
|
-
|
59
|
+
EvalFlags[EvalFlags["EnforceVarianceConsistency"] = 16384] = "EnforceVarianceConsistency";
|
60
60
|
// Used for PEP 526-style variable type annotations
|
61
|
-
|
61
|
+
EvalFlags[EvalFlags["VarTypeAnnotation"] = 32768] = "VarTypeAnnotation";
|
62
62
|
// 'ClassVar' is not allowed in this context.
|
63
|
-
|
63
|
+
EvalFlags[EvalFlags["NoClassVar"] = 131072] = "NoClassVar";
|
64
64
|
// 'Generic' cannot be used without type arguments in this context.
|
65
|
-
|
65
|
+
EvalFlags[EvalFlags["NoNakedGeneric"] = 262144] = "NoNakedGeneric";
|
66
66
|
// The node is not parsed by the interpreter because it is within
|
67
67
|
// a comment or a string literal.
|
68
|
-
|
68
|
+
EvalFlags[EvalFlags["NotParsed"] = 524288] = "NotParsed";
|
69
69
|
// Required and NotRequired are allowed in this context.
|
70
|
-
|
70
|
+
EvalFlags[EvalFlags["AllowRequired"] = 1048576] = "AllowRequired";
|
71
71
|
// Allow Unpack annotation for a tuple or TypeVarTuple.
|
72
|
-
|
72
|
+
EvalFlags[EvalFlags["AllowUnpackedTuple"] = 2097152] = "AllowUnpackedTuple";
|
73
|
+
// Allow Unpack annotation for TypedDict.
|
74
|
+
EvalFlags[EvalFlags["AllowUnpackedTypedDict"] = 4194304] = "AllowUnpackedTypedDict";
|
73
75
|
// Even though an expression is enclosed in a string literal,
|
74
76
|
// the interpreter (within a source file, not a stub) still
|
75
77
|
// parses the expression and generates parse errors.
|
76
|
-
|
77
|
-
//
|
78
|
-
|
79
|
-
|
80
|
-
//
|
81
|
-
|
82
|
-
|
83
|
-
EvaluatorFlags[EvaluatorFlags["DisallowNonTypeSpecialForms"] = 67108864] = "DisallowNonTypeSpecialForms";
|
78
|
+
EvalFlags[EvalFlags["ParsesStringLiteral"] = 8388608] = "ParsesStringLiteral";
|
79
|
+
// Do not convert special forms to their corresponding runtime
|
80
|
+
// objects even when expecting a type expression.
|
81
|
+
EvalFlags[EvalFlags["NoConvertSpecialForm"] = 33554432] = "NoConvertSpecialForm";
|
82
|
+
// Certain special forms (Protocol, TypedDict, etc.) are not allowed
|
83
|
+
// in this context.
|
84
|
+
EvalFlags[EvalFlags["NoNonTypeSpecialForms"] = 67108864] = "NoNonTypeSpecialForms";
|
84
85
|
// Allow use of the Concatenate special form.
|
85
|
-
|
86
|
+
EvalFlags[EvalFlags["AllowConcatenate"] = 134217728] = "AllowConcatenate";
|
86
87
|
// Do not infer literal types within a tuple (used for tuples nested within
|
87
88
|
// other container classes).
|
88
|
-
|
89
|
+
EvalFlags[EvalFlags["StripTupleLiterals"] = 268435456] = "StripTupleLiterals";
|
90
|
+
// Interpret the expression using the specialized behaviors associated
|
91
|
+
// with the second argument to isinstance and issubclass calls.
|
92
|
+
EvalFlags[EvalFlags["IsinstanceParam"] = 536870912] = "IsinstanceParam";
|
89
93
|
// Defaults used for evaluating the LHS of a call expression.
|
90
|
-
|
94
|
+
EvalFlags[EvalFlags["CallBaseDefaults"] = 2] = "CallBaseDefaults";
|
91
95
|
// Defaults used for evaluating the LHS of a member access expression.
|
92
|
-
|
96
|
+
EvalFlags[EvalFlags["IndexBaseDefaults"] = 2] = "IndexBaseDefaults";
|
93
97
|
// Defaults used for evaluating the LHS of a member access expression.
|
94
|
-
|
95
|
-
})(
|
98
|
+
EvalFlags[EvalFlags["MemberAccessBaseDefaults"] = 2] = "MemberAccessBaseDefaults";
|
99
|
+
})(EvalFlags || (exports.EvalFlags = EvalFlags = {}));
|
96
100
|
//# sourceMappingURL=typeEvaluatorTypes.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"typeEvaluatorTypes.js","sourceRoot":"","sources":["../../../../../src/analyzer/typeEvaluatorTypes.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AA+CH,gEAAgE;AAChE,kDAAkD;AACrC,QAAA,0BAA0B,GAAG,EAAE,CAAC;AAE7C,IAAkB,
|
1
|
+
{"version":3,"file":"typeEvaluatorTypes.js","sourceRoot":"","sources":["../../../../../src/analyzer/typeEvaluatorTypes.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AA+CH,gEAAgE;AAChE,kDAAkD;AACrC,QAAA,0BAA0B,GAAG,EAAE,CAAC;AAE7C,IAAkB,SAkHjB;AAlHD,WAAkB,SAAS;IACvB,yCAAQ,CAAA;IAER,uDAAuD;IACvD,yEAA6B,CAAA;IAE7B,0DAA0D;IAC1D,gEAAgE;IAChE,SAAS;IACT,yDAAqB,CAAA;IAErB,yDAAyD;IACzD,uDAAoB,CAAA;IAEpB,kCAAkC;IAClC,iEAAyB,CAAA;IAEzB,0CAA0C;IAC1C,gDAAgB,CAAA;IAEhB,6CAA6C;IAC7C,wDAAoB,CAAA;IAEpB,gDAAgD;IAChD,8DAAuB,CAAA;IAEvB,2DAA2D;IAC3D,4BAA4B;IAC5B,mEAAyB,CAAA;IAEzB,kEAAkE;IAClE,gEAAgE;IAChE,qBAAqB;IACrB,+DAAuB,CAAA;IAEvB,qEAAqE;IACrE,2EAA6B,CAAA;IAE7B,2DAA2D;IAC3D,gDAAgD;IAChD,4DAAsB,CAAA;IAEtB,8DAA8D;IAC9D,0BAA0B;IAC1B,4EAA8B,CAAA;IAE9B,oEAAoE;IACpE,0BAA0B;IAC1B,wFAAoC,CAAA;IAEpC,yDAAyD;IACzD,2DAA2D;IAC3D,mCAAmC;IACnC,0EAA6B,CAAA;IAE7B,yDAAyD;IACzD,6DAA6D;IAC7D,uDAAuD;IACvD,yFAAoC,CAAA;IAEpC,mDAAmD;IACnD,uEAA2B,CAAA;IAE3B,6CAA6C;IAC7C,0DAAoB,CAAA;IAEpB,mEAAmE;IACnE,kEAAwB,CAAA;IAExB,iEAAiE;IACjE,iCAAiC;IACjC,wDAAmB,CAAA;IAEnB,wDAAwD;IACxD,iEAAuB,CAAA;IAEvB,uDAAuD;IACvD,2EAA4B,CAAA;IAE5B,yCAAyC;IACzC,mFAAgC,CAAA;IAEhC,6DAA6D;IAC7D,2DAA2D;IAC3D,oDAAoD;IACpD,6EAA6B,CAAA;IAE7B,8DAA8D;IAC9D,iDAAiD;IACjD,gFAA8B,CAAA;IAE9B,oEAAoE;IACpE,mBAAmB;IACnB,kFAA+B,CAAA;IAE/B,6CAA6C;IAC7C,yEAA0B,CAAA;IAE1B,2EAA2E;IAC3E,4BAA4B;IAC5B,6EAA4B,CAAA;IAE5B,sEAAsE;IACtE,+DAA+D;IAC/D,uEAAyB,CAAA;IAEzB,6DAA6D;IAC7D,iEAA+B,CAAA;IAE/B,sEAAsE;IACtE,mEAAgC,CAAA;IAEhC,sEAAsE;IACtE,iFAAuC,CAAA;AAC3C,CAAC,EAlHiB,SAAS,yBAAT,SAAS,QAkH1B"}
|
@@ -129,7 +129,7 @@ function getTypeNarrowingCallback(evaluator, reference, testExpression, isPositi
|
|
129
129
|
testExpression.leftExpression.arguments[0].argumentCategory === 0 /* ArgumentCategory.Simple */) {
|
130
130
|
const arg0Expr = testExpression.leftExpression.arguments[0].valueExpression;
|
131
131
|
if (ParseTreeUtils.isMatchingExpression(reference, arg0Expr)) {
|
132
|
-
const callType = evaluator.getTypeOfExpression(testExpression.leftExpression.leftExpression, 2 /*
|
132
|
+
const callType = evaluator.getTypeOfExpression(testExpression.leftExpression.leftExpression, 2 /* EvalFlags.CallBaseDefaults */).type;
|
133
133
|
if ((0, types_1.isInstantiableClass)(callType) && types_1.ClassType.isBuiltIn(callType, 'type')) {
|
134
134
|
const classTypeResult = evaluator.getTypeOfExpression(testExpression.rightExpression);
|
135
135
|
const classType = evaluator.makeTopLevelTypeVarsConcrete(classTypeResult.type);
|
@@ -325,7 +325,7 @@ function getTypeNarrowingCallback(evaluator, reference, testExpression, isPositi
|
|
325
325
|
testExpression.leftExpression.arguments.length === 1) {
|
326
326
|
const arg0Expr = testExpression.leftExpression.arguments[0].valueExpression;
|
327
327
|
if (ParseTreeUtils.isMatchingExpression(reference, arg0Expr)) {
|
328
|
-
const callTypeResult = evaluator.getTypeOfExpression(testExpression.leftExpression.leftExpression, 2 /*
|
328
|
+
const callTypeResult = evaluator.getTypeOfExpression(testExpression.leftExpression.leftExpression, 2 /* EvalFlags.CallBaseDefaults */);
|
329
329
|
const callType = callTypeResult.type;
|
330
330
|
if ((0, types_1.isFunction)(callType) && callType.details.fullName === 'builtins.len') {
|
331
331
|
const rightTypeResult = evaluator.getTypeOfExpression(testExpression.rightExpression);
|
@@ -396,19 +396,19 @@ function getTypeNarrowingCallback(evaluator, reference, testExpression, isPositi
|
|
396
396
|
const arg0Expr = testExpression.arguments[0].valueExpression;
|
397
397
|
const arg1Expr = testExpression.arguments[1].valueExpression;
|
398
398
|
if (ParseTreeUtils.isMatchingExpression(reference, arg0Expr)) {
|
399
|
-
const callTypeResult = evaluator.getTypeOfExpression(testExpression.leftExpression, 2 /*
|
399
|
+
const callTypeResult = evaluator.getTypeOfExpression(testExpression.leftExpression, 2 /* EvalFlags.CallBaseDefaults */);
|
400
400
|
const callType = callTypeResult.type;
|
401
401
|
if ((0, types_1.isFunction)(callType) &&
|
402
402
|
(callType.details.builtInName === 'isinstance' || callType.details.builtInName === 'issubclass')) {
|
403
403
|
const isInstanceCheck = callType.details.builtInName === 'isinstance';
|
404
|
-
const arg1TypeResult = evaluator.getTypeOfExpression(arg1Expr, 512 /*
|
405
|
-
8 /*
|
406
|
-
32 /*
|
407
|
-
64 /*
|
408
|
-
16 /*
|
409
|
-
2 /*
|
404
|
+
const arg1TypeResult = evaluator.getTypeOfExpression(arg1Expr, 512 /* EvalFlags.AllowMissingTypeArgs */ |
|
405
|
+
8 /* EvalFlags.StrLiteralAsType */ |
|
406
|
+
32 /* EvalFlags.NoParamSpec */ |
|
407
|
+
64 /* EvalFlags.NoTypeVarTuple */ |
|
408
|
+
16 /* EvalFlags.NoFinal */ |
|
409
|
+
2 /* EvalFlags.NoSpecialize */);
|
410
410
|
const arg1Type = arg1TypeResult.type;
|
411
|
-
const classTypeList = getIsInstanceClassTypes(arg1Type);
|
411
|
+
const classTypeList = getIsInstanceClassTypes(evaluator, arg1Type);
|
412
412
|
const isIncomplete = !!callTypeResult.isIncomplete || !!arg1TypeResult.isIncomplete;
|
413
413
|
if (classTypeList) {
|
414
414
|
return (type) => {
|
@@ -436,7 +436,7 @@ function getTypeNarrowingCallback(evaluator, reference, testExpression, isPositi
|
|
436
436
|
if (testExpression.arguments.length === 1) {
|
437
437
|
const arg0Expr = testExpression.arguments[0].valueExpression;
|
438
438
|
if (ParseTreeUtils.isMatchingExpression(reference, arg0Expr)) {
|
439
|
-
const callTypeResult = evaluator.getTypeOfExpression(testExpression.leftExpression, 2 /*
|
439
|
+
const callTypeResult = evaluator.getTypeOfExpression(testExpression.leftExpression, 2 /* EvalFlags.CallBaseDefaults */);
|
440
440
|
const callType = callTypeResult.type;
|
441
441
|
if ((0, types_1.isFunction)(callType) && callType.details.builtInName === 'callable') {
|
442
442
|
return (type) => {
|
@@ -455,7 +455,7 @@ function getTypeNarrowingCallback(evaluator, reference, testExpression, isPositi
|
|
455
455
|
// Look for "bool(X)"
|
456
456
|
if (testExpression.arguments.length === 1 && !testExpression.arguments[0].name) {
|
457
457
|
if (ParseTreeUtils.isMatchingExpression(reference, testExpression.arguments[0].valueExpression)) {
|
458
|
-
const callTypeResult = evaluator.getTypeOfExpression(testExpression.leftExpression, 2 /*
|
458
|
+
const callTypeResult = evaluator.getTypeOfExpression(testExpression.leftExpression, 2 /* EvalFlags.CallBaseDefaults */);
|
459
459
|
const callType = callTypeResult.type;
|
460
460
|
if ((0, types_1.isInstantiableClass)(callType) && types_1.ClassType.isBuiltIn(callType, 'bool')) {
|
461
461
|
return (type) => {
|
@@ -478,7 +478,7 @@ function getTypeNarrowingCallback(evaluator, reference, testExpression, isPositi
|
|
478
478
|
(0, types_1.isClassInstance)(type.details.declaredReturnType) &&
|
479
479
|
types_1.ClassType.isBuiltIn(type.details.declaredReturnType, ['TypeGuard', 'TypeIs']));
|
480
480
|
};
|
481
|
-
const callTypeResult = evaluator.getTypeOfExpression(testExpression.leftExpression, 2 /*
|
481
|
+
const callTypeResult = evaluator.getTypeOfExpression(testExpression.leftExpression, 2 /* EvalFlags.CallBaseDefaults */);
|
482
482
|
const callType = callTypeResult.type;
|
483
483
|
if ((0, types_1.isFunction)(callType) && isFunctionReturnTypeGuard(callType)) {
|
484
484
|
isPossiblyTypeGuard = true;
|
@@ -760,7 +760,7 @@ function narrowTypeForIsEllipsis(evaluator, type, isPositiveTest) {
|
|
760
760
|
// that accepts a single class, and a more complex form that accepts a tuple
|
761
761
|
// of classes (including arbitrarily-nested tuples). This method determines
|
762
762
|
// which form and returns a list of classes or undefined.
|
763
|
-
function getIsInstanceClassTypes(argType) {
|
763
|
+
function getIsInstanceClassTypes(evaluator, argType) {
|
764
764
|
let foundNonClassType = false;
|
765
765
|
const classTypeList = [];
|
766
766
|
// Create a helper function that returns a list of class types or
|
@@ -768,7 +768,7 @@ function getIsInstanceClassTypes(argType) {
|
|
768
768
|
const addClassTypesToList = (types) => {
|
769
769
|
types.forEach((subtype) => {
|
770
770
|
if ((0, types_1.isClass)(subtype)) {
|
771
|
-
subtype = (0, typeUtils_1.specializeWithUnknownTypeArgs)(subtype);
|
771
|
+
subtype = (0, typeUtils_1.specializeWithUnknownTypeArgs)(subtype, evaluator.getTupleClassType());
|
772
772
|
if ((0, types_1.isInstantiableClass)(subtype) && types_1.ClassType.isBuiltIn(subtype, 'Callable')) {
|
773
773
|
subtype = (0, typeUtils_1.convertToInstantiable)((0, typeUtils_1.getUnknownTypeForCallable)());
|
774
774
|
}
|
@@ -897,7 +897,7 @@ function narrowTypeForIsInstanceInternal(evaluator, type, filterTypes, isInstanc
|
|
897
897
|
if (concreteFilterType.typeArguments && !concreteFilterType.isTypeArgumentExplicit) {
|
898
898
|
concreteFilterType = (0, typeUtils_1.specializeWithUnknownTypeArgs)(types_1.ClassType.cloneForSpecialization(concreteFilterType,
|
899
899
|
/* typeArguments */ undefined,
|
900
|
-
/* isTypeArgumentExplicit */ false));
|
900
|
+
/* isTypeArgumentExplicit */ false), evaluator.getTupleClassType());
|
901
901
|
}
|
902
902
|
filterIsSuperclass = isIsinstanceFilterSuperclass(evaluator, varType, concreteVarType, filterType, concreteFilterType, isInstanceCheck);
|
903
903
|
filterIsSubclass = isIsinstanceFilterSubclass(evaluator, concreteVarType, concreteFilterType, isInstanceCheck);
|
@@ -955,9 +955,13 @@ function narrowTypeForIsInstanceInternal(evaluator, type, filterTypes, isInstanc
|
|
955
955
|
const unspecializedFilterType = types_1.ClassType.cloneForSpecialization(filterType,
|
956
956
|
/* typeArguments */ undefined,
|
957
957
|
/* isTypeArgumentExplicit */ false);
|
958
|
-
if ((0, constraintSolver_1.
|
958
|
+
if ((0, constraintSolver_1.addConstraintsForExpectedType)(evaluator, unspecializedFilterType, concreteVarType, typeVarContext,
|
959
959
|
/* liveTypeVarScopes */ undefined, errorNode.start)) {
|
960
|
-
specializedFilterType = (0, typeUtils_1.applySolvedTypeVars)(unspecializedFilterType, typeVarContext, {
|
960
|
+
specializedFilterType = (0, typeUtils_1.applySolvedTypeVars)(unspecializedFilterType, typeVarContext, {
|
961
|
+
unknownIfNotFound: true,
|
962
|
+
useUnknownOverDefault: true,
|
963
|
+
tupleClassType: evaluator.getTupleClassType(),
|
964
|
+
});
|
961
965
|
}
|
962
966
|
}
|
963
967
|
}
|