@zzzen/pyright-internal 1.2.0-dev.20230305 → 1.2.0-dev.20230312
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 +23 -3
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.js +3 -3
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/commentUtils.js +11 -1
- package/dist/analyzer/commentUtils.js.map +1 -1
- package/dist/analyzer/constructorTransform.d.ts +1 -0
- package/dist/analyzer/constructorTransform.js +19 -2
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.js +40 -40
- package/dist/analyzer/packageTypeVerifier.js.map +1 -1
- package/dist/analyzer/patternMatching.js +13 -11
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.js +5 -4
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/sourceFile.js +12 -1
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +156 -42
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +1 -0
- package/dist/analyzer/typePrinter.js +63 -55
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +1 -0
- package/dist/analyzer/typeUtils.js +9 -3
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typedDicts.d.ts +2 -1
- package/dist/analyzer/typedDicts.js +57 -40
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +1 -0
- package/dist/analyzer/types.js +8 -0
- package/dist/analyzer/types.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +78 -0
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/common/extensibility.js +25 -1
- package/dist/common/extensibility.js.map +1 -1
- package/dist/languageServerBase.js +3 -1
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/completionProvider.d.ts +4 -2
- package/dist/languageService/completionProvider.js +206 -151
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/renameModuleProvider.d.ts +1 -1
- package/dist/languageService/renameModuleProvider.js +8 -1
- package/dist/languageService/renameModuleProvider.js.map +1 -1
- package/dist/languageService/tooltipUtils.js +2 -1
- package/dist/languageService/tooltipUtils.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 +1 -0
- package/dist/parser/parser.js +22 -7
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/tokenizer.js +1 -1
- package/dist/tests/completions.test.js +445 -0
- package/dist/tests/completions.test.js.map +1 -1
- package/dist/tests/fourslash/completions.dictionary.keys.expression.fourslash.js +13 -3
- package/dist/tests/fourslash/completions.dictionary.keys.expression.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.dictionary.keys.stringLiterals.fourslash.js +7 -2
- package/dist/tests/fourslash/completions.dictionary.keys.stringLiterals.fourslash.js.map +1 -1
- package/dist/tests/hoverProvider.test.js +1 -1
- package/dist/tests/hoverProvider.test.js.map +1 -1
- package/dist/tests/moveSymbol.misc.test.js +27 -0
- package/dist/tests/moveSymbol.misc.test.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +4 -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/typeEvaluator4.test.js +4 -0
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/package.json +1 -1
@@ -253,6 +253,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
253
253
|
let strClassType;
|
254
254
|
let dictClassType;
|
255
255
|
let typedDictClassType;
|
256
|
+
let typedDictPrivateClassType;
|
256
257
|
let printExpressionSpaceCount = 0;
|
257
258
|
let incompleteGenerationCount = 0;
|
258
259
|
const returnTypeInferenceContextStack = [];
|
@@ -500,7 +501,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
500
501
|
intClassType = getBuiltInType(node, 'int');
|
501
502
|
strClassType = getBuiltInType(node, 'str');
|
502
503
|
dictClassType = getBuiltInType(node, 'dict');
|
503
|
-
typedDictClassType = getTypingType(node, '
|
504
|
+
typedDictClassType = getTypingType(node, 'TypedDict');
|
505
|
+
typedDictPrivateClassType = getTypingType(node, '_TypedDict');
|
504
506
|
}
|
505
507
|
}
|
506
508
|
function getTypeOfExpression(node, flags = 0 /* None */, inferenceContext) {
|
@@ -1842,7 +1844,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1842
1844
|
return isTypeHashable;
|
1843
1845
|
}
|
1844
1846
|
function getTypedDictClassType() {
|
1845
|
-
return
|
1847
|
+
return typedDictPrivateClassType;
|
1846
1848
|
}
|
1847
1849
|
function getTupleClassType() {
|
1848
1850
|
return tupleClassType;
|
@@ -4405,7 +4407,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4405
4407
|
if (param.details.isParamSpec && index < typeArgs.length) {
|
4406
4408
|
const typeArgType = typeArgs[index].type;
|
4407
4409
|
if (typeArgs[index].typeList) {
|
4408
|
-
const functionType = types_1.FunctionType.
|
4410
|
+
const functionType = types_1.FunctionType.createSynthesizedInstance('', 65536 /* ParamSpecValue */);
|
4409
4411
|
types_1.TypeBase.setSpecialForm(functionType);
|
4410
4412
|
typeArgs[index].typeList.forEach((paramType, paramIndex) => {
|
4411
4413
|
types_1.FunctionType.addParameter(functionType, {
|
@@ -4451,7 +4453,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4451
4453
|
(0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, param, functionType, diag, typeVarContext, 128 /* RetainLiteralsForTypeVar */);
|
4452
4454
|
}
|
4453
4455
|
else if ((0, typeUtils_1.isEllipsisType)(typeArgType)) {
|
4454
|
-
const functionType = types_1.FunctionType.
|
4456
|
+
const functionType = types_1.FunctionType.createSynthesizedInstance('', 65536 /* ParamSpecValue */ | 32768 /* SkipArgsKwargsCompatibilityCheck */);
|
4455
4457
|
types_1.TypeBase.setSpecialForm(functionType);
|
4456
4458
|
types_1.FunctionType.addDefaultParameters(functionType);
|
4457
4459
|
(0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, param, functionType, diag, typeVarContext);
|
@@ -4538,7 +4540,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4538
4540
|
type: printType(unexpandedSubtype),
|
4539
4541
|
}), node.baseExpression);
|
4540
4542
|
// Evaluate the index expressions as though they are type arguments for error-reporting.
|
4541
|
-
getTypeArgs(node, flags
|
4543
|
+
getTypeArgs(node, flags);
|
4542
4544
|
return types_1.UnknownType.create();
|
4543
4545
|
}
|
4544
4546
|
}
|
@@ -4593,7 +4595,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4593
4595
|
types_1.ClassType.isPartiallyEvaluated(concreteSubtype);
|
4594
4596
|
const isFinalAnnotation = (0, types_1.isInstantiableClass)(concreteSubtype) && types_1.ClassType.isBuiltIn(concreteSubtype, 'Final');
|
4595
4597
|
const isClassVarAnnotation = (0, types_1.isInstantiableClass)(concreteSubtype) && types_1.ClassType.isBuiltIn(concreteSubtype, 'ClassVar');
|
4596
|
-
|
4598
|
+
// Inlined TypedDicts are supported only for 'dict' (and not for 'Dict').
|
4599
|
+
const supportsTypedDictTypeArg = (0, types_1.isInstantiableClass)(concreteSubtype) &&
|
4600
|
+
types_1.ClassType.isBuiltIn(concreteSubtype, 'dict') &&
|
4601
|
+
!concreteSubtype.aliasName;
|
4602
|
+
let typeArgs = getTypeArgs(node, flags, {
|
4603
|
+
isAnnotatedClass,
|
4604
|
+
hasCustomClassGetItem: hasCustomClassGetItem || !isGenericClass,
|
4605
|
+
isFinalAnnotation,
|
4606
|
+
isClassVarAnnotation,
|
4607
|
+
supportsTypedDictTypeArg,
|
4608
|
+
});
|
4597
4609
|
if (!isAnnotatedClass) {
|
4598
4610
|
typeArgs = adjustTypeArgumentsForVariadicTypeVar(typeArgs, concreteSubtype.details.typeParameters, node);
|
4599
4611
|
}
|
@@ -4945,10 +4957,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4945
4957
|
isIncomplete: !!callResult.isTypeIncomplete,
|
4946
4958
|
};
|
4947
4959
|
}
|
4948
|
-
function getTypeArgs(node, flags,
|
4960
|
+
function getTypeArgs(node, flags, options) {
|
4949
4961
|
const typeArgs = [];
|
4950
4962
|
let adjFlags = flags;
|
4951
|
-
if (isFinalAnnotation || isClassVarAnnotation) {
|
4963
|
+
if ((options === null || options === void 0 ? void 0 : options.isFinalAnnotation) || (options === null || options === void 0 ? void 0 : options.isClassVarAnnotation)) {
|
4952
4964
|
adjFlags |= 131072 /* DisallowClassVar */ | 16 /* DisallowFinal */;
|
4953
4965
|
}
|
4954
4966
|
else {
|
@@ -4956,7 +4968,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4956
4968
|
32 /* DisallowParamSpec */ |
|
4957
4969
|
64 /* DisallowTypeVarTuple */ |
|
4958
4970
|
1048576 /* AllowRequired */);
|
4959
|
-
if (!isAnnotatedClass) {
|
4971
|
+
if (!(options === null || options === void 0 ? void 0 : options.isAnnotatedClass)) {
|
4960
4972
|
adjFlags |= 131072 /* DisallowClassVar */ | 16 /* DisallowFinal */;
|
4961
4973
|
}
|
4962
4974
|
adjFlags |= 2097152 /* AllowUnpackedTupleOrTypeVarTuple */;
|
@@ -4967,7 +4979,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4967
4979
|
// If it's a custom __class_getitem__, none of the arguments should be
|
4968
4980
|
// treated as types. If it's an Annotated[a, b, c], only the first index
|
4969
4981
|
// should be treated as a type. The others can be regular (non-type) objects.
|
4970
|
-
if (hasCustomClassGetItem || (isAnnotatedClass && argIndex > 0)) {
|
4982
|
+
if ((options === null || options === void 0 ? void 0 : options.hasCustomClassGetItem) || ((options === null || options === void 0 ? void 0 : options.isAnnotatedClass) && argIndex > 0)) {
|
4971
4983
|
typeResult = {
|
4972
4984
|
...getTypeOfExpression(expr, 32 /* DisallowParamSpec */ |
|
4973
4985
|
64 /* DisallowTypeVarTuple */ |
|
@@ -4977,7 +4989,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4977
4989
|
};
|
4978
4990
|
}
|
4979
4991
|
else {
|
4980
|
-
typeResult = getTypeArg(expr, adjFlags);
|
4992
|
+
typeResult = getTypeArg(expr, adjFlags, !!(options === null || options === void 0 ? void 0 : options.supportsTypedDictTypeArg) && argIndex === 0);
|
4981
4993
|
}
|
4982
4994
|
return typeResult;
|
4983
4995
|
};
|
@@ -5016,7 +5028,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5016
5028
|
}
|
5017
5029
|
return typeArgs;
|
5018
5030
|
}
|
5019
|
-
function getTypeArg(node, flags) {
|
5031
|
+
function getTypeArg(node, flags, supportsDictExpression) {
|
5020
5032
|
let typeResult;
|
5021
5033
|
let adjustedFlags = flags |
|
5022
5034
|
128 /* ExpectingType */ |
|
@@ -5037,8 +5049,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5037
5049
|
// Set the node's type so it isn't reevaluated later.
|
5038
5050
|
setTypeForNode(node, types_1.UnknownType.create());
|
5039
5051
|
}
|
5052
|
+
else if (node.nodeType === 15 /* Dictionary */ && supportsDictExpression) {
|
5053
|
+
const inlinedTypeDict = typedDictClassType && (0, types_1.isInstantiableClass)(typedDictClassType)
|
5054
|
+
? (0, typedDicts_1.createTypedDictTypeInlined)(evaluatorInterface, node, typedDictClassType)
|
5055
|
+
: undefined;
|
5056
|
+
const keyTypeFallback = strClassType && (0, types_1.isInstantiableClass)(strClassType) ? strClassType : types_1.UnknownType.create();
|
5057
|
+
typeResult = {
|
5058
|
+
type: keyTypeFallback,
|
5059
|
+
inlinedTypeDict,
|
5060
|
+
node,
|
5061
|
+
};
|
5062
|
+
}
|
5040
5063
|
else {
|
5041
5064
|
typeResult = { ...getTypeOfExpression(node, adjustedFlags), node };
|
5065
|
+
if (node.nodeType === 15 /* Dictionary */) {
|
5066
|
+
addError(localize_1.Localizer.Diagnostic.dictInAnnotation(), node);
|
5067
|
+
}
|
5042
5068
|
// "Protocol" is not allowed as a type argument.
|
5043
5069
|
if ((0, types_1.isClass)(typeResult.type) && types_1.ClassType.isBuiltIn(typeResult.type, 'Protocol')) {
|
5044
5070
|
addError(localize_1.Localizer.Diagnostic.protocolNotAllowedInTypeArgument(), node);
|
@@ -6023,7 +6049,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6023
6049
|
}
|
6024
6050
|
typeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(constructorMethodType));
|
6025
6051
|
// Skip the unknown argument check if we've already checked for __init__.
|
6026
|
-
|
6052
|
+
let callResult;
|
6053
|
+
if ((0, constructorTransform_1.hasConstructorTransform)(type)) {
|
6054
|
+
// Use speculative mode if we're going to later apply
|
6055
|
+
// a constructor transform. This allows us to use bidirectional
|
6056
|
+
// type inference for arguments in the transform.
|
6057
|
+
callResult = useSpeculativeMode(errorNode, () => {
|
6058
|
+
return validateCallArguments(errorNode, argList, constructorMethodInfo, typeVarContext, skipUnknownArgCheck);
|
6059
|
+
});
|
6060
|
+
}
|
6061
|
+
else {
|
6062
|
+
callResult = validateCallArguments(errorNode, argList, constructorMethodInfo, typeVarContext, skipUnknownArgCheck);
|
6063
|
+
}
|
6027
6064
|
if (callResult.isTypeIncomplete) {
|
6028
6065
|
isTypeIncomplete = true;
|
6029
6066
|
}
|
@@ -6238,7 +6275,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6238
6275
|
}), exprNode);
|
6239
6276
|
return { returnType: types_1.UnknownType.create(), argumentErrors: true, overloadsUsedForCall };
|
6240
6277
|
}
|
6241
|
-
|
6278
|
+
let returnType = mapSubtypesExpandTypeVars(callTypeResult.type,
|
6242
6279
|
/* conditionFilter */ undefined, (expandedSubtype, unexpandedSubtype) => {
|
6243
6280
|
var _a, _b, _c, _d, _e, _f;
|
6244
6281
|
switch (expandedSubtype.category) {
|
@@ -6257,6 +6294,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6257
6294
|
return expandedSubtype;
|
6258
6295
|
}
|
6259
6296
|
case 5 /* Function */: {
|
6297
|
+
if (types_1.TypeBase.isInstantiable(expandedSubtype)) {
|
6298
|
+
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.callableNotInstantiable().format({
|
6299
|
+
type: printType(expandedSubtype),
|
6300
|
+
}), errorNode);
|
6301
|
+
argumentErrors = true;
|
6302
|
+
return undefined;
|
6303
|
+
}
|
6260
6304
|
// The stdlib collections/__init__.pyi stub file defines namedtuple
|
6261
6305
|
// as a function rather than a class, so we need to check for it here.
|
6262
6306
|
if (expandedSubtype.details.builtInName === 'namedtuple') {
|
@@ -6378,6 +6422,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6378
6422
|
(0, types_1.isNoneInstance)(subtype)) {
|
6379
6423
|
return (0, typeUtils_1.convertToInstantiable)(stripLiteralValue(subtype));
|
6380
6424
|
}
|
6425
|
+
else if ((0, types_1.isFunction)(subtype) && types_1.TypeBase.isInstance(subtype)) {
|
6426
|
+
return types_1.FunctionType.cloneAsInstantiable(subtype);
|
6427
|
+
}
|
6381
6428
|
return types_1.AnyType.create();
|
6382
6429
|
});
|
6383
6430
|
}
|
@@ -6562,9 +6609,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6562
6609
|
}
|
6563
6610
|
return undefined;
|
6564
6611
|
});
|
6612
|
+
// If we ended up with a "Never" type because all code paths returned
|
6613
|
+
// undefined due to argument errors, transform the result into an Unknown
|
6614
|
+
// to avoid subsequent false positives.
|
6615
|
+
if (argumentErrors && (0, types_1.isNever)(returnType) && !returnType.isNoReturn) {
|
6616
|
+
returnType = types_1.UnknownType.create();
|
6617
|
+
}
|
6565
6618
|
return {
|
6566
6619
|
argumentErrors,
|
6567
|
-
returnType
|
6620
|
+
returnType,
|
6568
6621
|
isTypeIncomplete,
|
6569
6622
|
specializedInitSelfType,
|
6570
6623
|
overloadsUsedForCall,
|
@@ -8278,8 +8331,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8278
8331
|
types_1.FunctionType.addDefaultParameters(functionType);
|
8279
8332
|
return functionType;
|
8280
8333
|
}
|
8281
|
-
if (node.nodeType ===
|
8282
|
-
node.
|
8334
|
+
if (node.nodeType === 31 /* List */) {
|
8335
|
+
node.entries.forEach((paramExpr, index) => {
|
8283
8336
|
const typeResult = getTypeOfExpressionExpectingType(paramExpr);
|
8284
8337
|
types_1.FunctionType.addParameter(functionType, {
|
8285
8338
|
category: 0 /* Simple */,
|
@@ -10548,6 +10601,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10548
10601
|
if ((0, types_1.isParamSpec)(typeArg.type)) {
|
10549
10602
|
addError(localize_1.Localizer.Diagnostic.paramSpecContext(), typeArg.node);
|
10550
10603
|
}
|
10604
|
+
else if ((0, types_1.isUnpackedVariadicTypeVar)(typeArg.type)) {
|
10605
|
+
addError(localize_1.Localizer.Diagnostic.typeVarTupleContext(), typeArg.node);
|
10606
|
+
}
|
10607
|
+
else if ((0, types_1.isUnpackedClass)(typeArg.type)) {
|
10608
|
+
addError(localize_1.Localizer.Diagnostic.unpackedArgInTypeArgument(), typeArg.node);
|
10609
|
+
}
|
10551
10610
|
}
|
10552
10611
|
});
|
10553
10612
|
}
|
@@ -11296,7 +11355,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11296
11355
|
argType = (0, types_1.removeUnbound)(argType);
|
11297
11356
|
}
|
11298
11357
|
if (!(0, types_1.isAnyOrUnknown)(argType) && !(0, types_1.isUnbound)(argType)) {
|
11299
|
-
if ((0,
|
11358
|
+
if ((0, typeUtils_1.isMetaclassInstance)(argType)) {
|
11359
|
+
(0, debug_1.assert)((0, types_1.isClassInstance)(argType));
|
11300
11360
|
argType =
|
11301
11361
|
argType.typeArguments && argType.typeArguments.length > 0
|
11302
11362
|
? argType.typeArguments[0]
|
@@ -11883,6 +11943,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11883
11943
|
decoratorCallType.details.builtInName === 'dataclass_transform') {
|
11884
11944
|
originalClassType.details.classDataClassTransform = (0, dataClasses_1.validateDataClassTransformDecorator)(evaluatorInterface, decoratorNode.expression);
|
11885
11945
|
}
|
11946
|
+
else if (decoratorCallType.details.name === 'deprecated') {
|
11947
|
+
originalClassType.details.deprecatedMessage = getCustomDeprecationMessage(decoratorNode);
|
11948
|
+
return inputClassType;
|
11949
|
+
}
|
11886
11950
|
}
|
11887
11951
|
if ((0, types_1.isOverloadedFunction)(decoratorCallType)) {
|
11888
11952
|
if (decoratorCallType.overloads.length > 0 &&
|
@@ -11912,6 +11976,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11912
11976
|
// dependency between builtins, typing and _typeshed stubs.
|
11913
11977
|
return inputClassType;
|
11914
11978
|
}
|
11979
|
+
if (decoratorType.details.builtInName === 'deprecated') {
|
11980
|
+
originalClassType.details.deprecatedMessage = getCustomDeprecationMessage(decoratorNode);
|
11981
|
+
return inputClassType;
|
11982
|
+
}
|
11915
11983
|
if (decoratorType.details.builtInName === 'runtime_checkable') {
|
11916
11984
|
originalClassType.details.flags |= 32768 /* RuntimeCheckable */;
|
11917
11985
|
// Don't call getTypeOfDecorator for runtime_checkable. It appears
|
@@ -12704,6 +12772,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12704
12772
|
undecoratedType.details.decoratorDataClassBehaviors = (0, dataClasses_1.validateDataClassTransformDecorator)(evaluatorInterface, decoratorNode.expression);
|
12705
12773
|
return inputFunctionType;
|
12706
12774
|
}
|
12775
|
+
if (decoratorCallType.details.name === 'deprecated') {
|
12776
|
+
undecoratedType.details.deprecatedMessage = getCustomDeprecationMessage(decoratorNode);
|
12777
|
+
return inputFunctionType;
|
12778
|
+
}
|
12707
12779
|
}
|
12708
12780
|
if ((0, types_1.isOverloadedFunction)(decoratorCallType)) {
|
12709
12781
|
if (decoratorCallType.overloads.length > 0 &&
|
@@ -12719,6 +12791,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12719
12791
|
if (decoratorType.details.builtInName === 'abstractmethod') {
|
12720
12792
|
return inputFunctionType;
|
12721
12793
|
}
|
12794
|
+
if (decoratorType.details.builtInName === 'deprecated') {
|
12795
|
+
undecoratedType.details.deprecatedMessage = getCustomDeprecationMessage(decoratorNode);
|
12796
|
+
return inputFunctionType;
|
12797
|
+
}
|
12722
12798
|
// Handle property setters and deleters.
|
12723
12799
|
if (decoratorNode.expression.nodeType === 35 /* MemberAccess */) {
|
12724
12800
|
const baseType = getTypeOfExpression(decoratorNode.expression.leftExpression, evaluatorFlags | 2 /* DoNotSpecialize */).type;
|
@@ -12828,7 +12904,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12828
12904
|
getTypeOfFunction(decl.node);
|
12829
12905
|
}
|
12830
12906
|
}
|
12831
|
-
|
12907
|
+
let overloadedTypes = [];
|
12832
12908
|
// Look at the previous declaration's type.
|
12833
12909
|
const prevDecl = decls[declIndex - 1];
|
12834
12910
|
if (prevDecl.type === 5 /* Function */) {
|
@@ -12850,6 +12926,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12850
12926
|
if (overloadedTypes.length === 1) {
|
12851
12927
|
return overloadedTypes[0];
|
12852
12928
|
}
|
12929
|
+
// Apply the implementation's docstring to any overloads that don't
|
12930
|
+
// have their own docstrings.
|
12931
|
+
const implementation = overloadedTypes.find((signature) => !types_1.FunctionType.isOverloaded(signature));
|
12932
|
+
if (implementation === null || implementation === void 0 ? void 0 : implementation.details.docString) {
|
12933
|
+
overloadedTypes = overloadedTypes.map((overload) => {
|
12934
|
+
if (types_1.FunctionType.isOverloaded(overload) && !overload.details.docString) {
|
12935
|
+
return types_1.FunctionType.cloneWithDocString(overload, implementation.details.docString);
|
12936
|
+
}
|
12937
|
+
return overload;
|
12938
|
+
});
|
12939
|
+
}
|
12853
12940
|
// Create a new overloaded type that copies the contents of the previous
|
12854
12941
|
// one and adds a new function.
|
12855
12942
|
const newOverload = types_1.OverloadedFunctionType.create(overloadedTypes);
|
@@ -14063,7 +14150,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14063
14150
|
if (firstNonDefaultParam >= 0) {
|
14064
14151
|
minTypeArgCount = firstNonDefaultParam;
|
14065
14152
|
}
|
14066
|
-
|
14153
|
+
// Classes that accept inlined type dict type args allow only one.
|
14154
|
+
if (typeArgs[0].inlinedTypeDict) {
|
14155
|
+
if (typeArgs.length > 1) {
|
14156
|
+
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeArgsTooMany().format({
|
14157
|
+
name: classType.aliasName || classType.details.name,
|
14158
|
+
expected: 1,
|
14159
|
+
received: typeArgCount,
|
14160
|
+
}), typeArgs[1].node);
|
14161
|
+
}
|
14162
|
+
return { type: typeArgs[0].inlinedTypeDict };
|
14163
|
+
}
|
14164
|
+
else if (typeArgCount > typeParameters.length) {
|
14067
14165
|
if (!types_1.ClassType.isPartiallyEvaluated(classType) && !types_1.ClassType.isTupleClass(classType)) {
|
14068
14166
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
14069
14167
|
if (typeParameters.length === 0) {
|
@@ -14147,7 +14245,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14147
14245
|
if (typeArgs && index < typeArgs.length) {
|
14148
14246
|
if (typeParam.details.isParamSpec) {
|
14149
14247
|
const typeArg = typeArgs[index];
|
14150
|
-
const functionType = types_1.FunctionType.
|
14248
|
+
const functionType = types_1.FunctionType.createSynthesizedInstance('', 65536 /* ParamSpecValue */);
|
14151
14249
|
types_1.TypeBase.setSpecialForm(functionType);
|
14152
14250
|
if ((0, typeUtils_1.isEllipsisType)(typeArg.type)) {
|
14153
14251
|
types_1.FunctionType.addDefaultParameters(functionType);
|
@@ -14333,7 +14431,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14333
14431
|
const scopeTypeHonorsCodeFlow = scopeType !== 1 /* Function */ && scopeType !== 0 /* ListComprehension */;
|
14334
14432
|
if (symbolWithScope && honorCodeFlow && scopeTypeHonorsCodeFlow) {
|
14335
14433
|
// Filter the declarations based on flow reachability.
|
14336
|
-
const
|
14434
|
+
const reachableDecl = symbolWithScope.symbol.getDeclarations().find((decl) => {
|
14337
14435
|
if (decl.type !== 8 /* Alias */ && decl.type !== 0 /* Intrinsic */) {
|
14338
14436
|
// Is the declaration in the same execution scope as the "usageNode" node?
|
14339
14437
|
const usageScope = ParseTreeUtils.getExecutionScopeNode(node);
|
@@ -14361,7 +14459,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14361
14459
|
});
|
14362
14460
|
// If none of the declarations are reachable from the current node,
|
14363
14461
|
// search for the symbol in outer scopes.
|
14364
|
-
if (
|
14462
|
+
if (!reachableDecl) {
|
14365
14463
|
if (symbolWithScope.scope.type !== 1 /* Function */) {
|
14366
14464
|
let nextScopeToSearch = symbolWithScope.scope.parent;
|
14367
14465
|
const isOutsideCallerModule = symbolWithScope.isOutsideCallerModule || symbolWithScope.scope.type === 3 /* Module */;
|
@@ -14887,7 +14985,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14887
14985
|
return typeVar;
|
14888
14986
|
}
|
14889
14987
|
function getInferredTypeOfDeclaration(symbol, decl) {
|
14890
|
-
var _a, _b;
|
14988
|
+
var _a, _b, _c;
|
14891
14989
|
const resolvedDecl = resolveAliasDeclaration(decl,
|
14892
14990
|
/* resolveLocalNames */ true,
|
14893
14991
|
/* allowExternallyHiddenAccess */ AnalyzerNodeInfo.getFileInfo(decl.node).isStubFile);
|
@@ -14903,7 +15001,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14903
15001
|
moduleType.fields = lookupResults.symbolTable;
|
14904
15002
|
moduleType.docString = lookupResults.docString;
|
14905
15003
|
}
|
14906
|
-
else {
|
15004
|
+
else if (!loaderActions.implicitImports) {
|
14907
15005
|
return evaluatorOptions.evaluateUnknownImportsAsAny ? types_1.AnyType.create() : types_1.UnknownType.create();
|
14908
15006
|
}
|
14909
15007
|
}
|
@@ -14979,17 +15077,34 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14979
15077
|
isUnambiguousType = true;
|
14980
15078
|
}
|
14981
15079
|
}
|
15080
|
+
// Special-case constants, which are treated as unambiguous.
|
14982
15081
|
if (isFinalVariableDeclaration(resolvedDecl) || resolvedDecl.isConstant) {
|
14983
15082
|
isUnambiguousType = true;
|
14984
15083
|
}
|
15084
|
+
// Special-case calls to certain built-in type functions.
|
15085
|
+
if (((_a = resolvedDecl.inferredTypeSource) === null || _a === void 0 ? void 0 : _a.nodeType) === 9 /* Call */) {
|
15086
|
+
const baseTypeResult = getTypeOfExpression(resolvedDecl.inferredTypeSource.leftExpression, 2 /* DoNotSpecialize */);
|
15087
|
+
const callType = baseTypeResult.type;
|
15088
|
+
if ((0, types_1.isInstantiableClass)(callType) &&
|
15089
|
+
types_1.ClassType.isBuiltIn(callType, [
|
15090
|
+
'TypeVar',
|
15091
|
+
'ParamSpec',
|
15092
|
+
'TypeVarTuple',
|
15093
|
+
'TypedDict',
|
15094
|
+
'NamedTuple',
|
15095
|
+
'NewType',
|
15096
|
+
])) {
|
15097
|
+
isUnambiguousType = true;
|
15098
|
+
}
|
15099
|
+
}
|
14985
15100
|
}
|
14986
15101
|
}
|
14987
15102
|
// If the resolved declaration had no defined type, use the
|
14988
15103
|
// inferred type for this node.
|
14989
15104
|
if (resolvedDecl.type === 2 /* Parameter */) {
|
14990
|
-
return (
|
15105
|
+
return (_b = evaluateTypeForSubnode(resolvedDecl.node.name, () => {
|
14991
15106
|
evaluateTypeOfParameter(resolvedDecl.node);
|
14992
|
-
})) === null ||
|
15107
|
+
})) === null || _b === void 0 ? void 0 : _b.type;
|
14993
15108
|
}
|
14994
15109
|
if (resolvedDecl.type === 1 /* Variable */ && resolvedDecl.inferredTypeSource) {
|
14995
15110
|
const isTypeAlias = isExplicitTypeAliasDeclaration(resolvedDecl) || isPossibleTypeAliasOrTypedDict(resolvedDecl);
|
@@ -14998,9 +15113,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14998
15113
|
const typeSource = isTypeAlias && resolvedDecl.inferredTypeSource.parent
|
14999
15114
|
? resolvedDecl.inferredTypeSource.parent
|
15000
15115
|
: resolvedDecl.inferredTypeSource;
|
15001
|
-
let inferredType = (
|
15116
|
+
let inferredType = (_c = evaluateTypeForSubnode(resolvedDecl.node, () => {
|
15002
15117
|
evaluateTypesForStatement(typeSource);
|
15003
|
-
})) === null ||
|
15118
|
+
})) === null || _c === void 0 ? void 0 : _c.type;
|
15004
15119
|
if (inferredType && resolvedDecl.node.nodeType === 38 /* Name */) {
|
15005
15120
|
// See if this is an enum member. If so, we need to handle it as a special case.
|
15006
15121
|
const enumMemberType = (0, enums_1.transformTypeForPossibleEnumClass)(evaluatorInterface, resolvedDecl.node, () => {
|
@@ -15114,18 +15229,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15114
15229
|
}
|
15115
15230
|
function getEffectiveTypeOfSymbolForUsage(symbol, usageNode, useLastDecl = false) {
|
15116
15231
|
var _a, _b;
|
15117
|
-
// Look in the cache to see if we've computed this already.
|
15118
|
-
let cacheEntries = effectiveTypeCache.get(symbol.id);
|
15119
|
-
const usageNodeId = usageNode ? usageNode.id : undefined;
|
15120
|
-
const effectiveTypeCacheKey = `${usageNodeId === undefined ? '.' : usageNodeId.toString()}${useLastDecl ? '*' : ''}`;
|
15121
|
-
if (cacheEntries) {
|
15122
|
-
const result = cacheEntries.get(effectiveTypeCacheKey);
|
15123
|
-
if (result) {
|
15124
|
-
if (!result.isIncomplete) {
|
15125
|
-
return result;
|
15126
|
-
}
|
15127
|
-
}
|
15128
|
-
}
|
15129
15232
|
let declaredTypeInfo;
|
15130
15233
|
// If there's a declared type, it takes precedence over inferred types.
|
15131
15234
|
if (symbol.hasTypedDeclarations()) {
|
@@ -15150,10 +15253,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15150
15253
|
includesIllegalTypeAliasDecl: !typedDecls.every((decl) => isPossibleTypeAliasDeclaration(decl)),
|
15151
15254
|
isRecursiveDefinition: !declaredType,
|
15152
15255
|
};
|
15153
|
-
addToEffectiveTypeCache(result);
|
15154
15256
|
return result;
|
15155
15257
|
}
|
15156
15258
|
}
|
15259
|
+
// Look in the inferred type cache to see if we've computed this already.
|
15260
|
+
let cacheEntries = effectiveTypeCache.get(symbol.id);
|
15261
|
+
const usageNodeId = usageNode ? usageNode.id : undefined;
|
15262
|
+
const effectiveTypeCacheKey = `${usageNodeId === undefined ? '.' : usageNodeId.toString()}${useLastDecl ? '*' : ''}`;
|
15263
|
+
if (cacheEntries) {
|
15264
|
+
const result = cacheEntries.get(effectiveTypeCacheKey);
|
15265
|
+
if (result) {
|
15266
|
+
if (!result.isIncomplete) {
|
15267
|
+
return result;
|
15268
|
+
}
|
15269
|
+
}
|
15270
|
+
}
|
15157
15271
|
// Infer the type.
|
15158
15272
|
const typesToCombine = [];
|
15159
15273
|
const decls = symbol.getDeclarations();
|