@zzzen/pyright-internal 1.2.0-dev.20240114 → 1.2.0-dev.20240121
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.d.ts +1 -3
- package/dist/analyzer/binder.js +27 -37
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.d.ts +1 -3
- package/dist/analyzer/checker.js +325 -381
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/commentUtils.js +7 -7
- package/dist/analyzer/commentUtils.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +23 -30
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructorTransform.js +10 -11
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/constructors.d.ts +3 -3
- package/dist/analyzer/constructors.js +12 -14
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +15 -15
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/decorators.d.ts +1 -2
- package/dist/analyzer/decorators.js +4 -1
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/enums.d.ts +4 -2
- package/dist/analyzer/enums.js +109 -50
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/functionTransform.js +1 -2
- package/dist/analyzer/functionTransform.js.map +1 -1
- package/dist/analyzer/importResolver.js +3 -3
- package/dist/analyzer/namedTuples.js +8 -7
- package/dist/analyzer/namedTuples.js.map +1 -1
- package/dist/analyzer/operations.js +15 -18
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.d.ts +1 -1
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/patternMatching.js +22 -19
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.js +17 -3
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/properties.js +8 -8
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.js +14 -14
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/service.js +14 -14
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.js +12 -12
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +820 -748
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +8 -8
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +2 -2
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.js +3 -4
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +4 -2
- package/dist/analyzer/typeUtils.js +6 -0
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typedDicts.js +30 -34
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +5 -10
- package/dist/analyzer/types.js +12 -39
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundThreadBase.js +4 -4
- package/dist/backgroundThreadBase.js.map +1 -1
- package/dist/common/commandLineOptions.d.ts +1 -0
- package/dist/common/commandLineOptions.js.map +1 -1
- package/dist/common/configOptions.d.ts +1 -0
- package/dist/common/configOptions.js +13 -11
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/core.d.ts +1 -1
- package/dist/common/core.js.map +1 -1
- package/dist/common/uri/baseUri.d.ts +7 -2
- package/dist/common/uri/baseUri.js +47 -24
- package/dist/common/uri/baseUri.js.map +1 -1
- package/dist/common/uri/emptyUri.d.ts +6 -4
- package/dist/common/uri/emptyUri.js +14 -9
- package/dist/common/uri/emptyUri.js.map +1 -1
- package/dist/common/uri/fileUri.d.ts +12 -4
- package/dist/common/uri/fileUri.js +59 -9
- package/dist/common/uri/fileUri.js.map +1 -1
- package/dist/common/uri/uri.d.ts +5 -1
- package/dist/common/uri/uri.js.map +1 -1
- package/dist/common/uri/uriUtils.js +3 -3
- package/dist/common/uri/webUri.d.ts +6 -1
- package/dist/common/uri/webUri.js +52 -12
- package/dist/common/uri/webUri.js.map +1 -1
- package/dist/languageServerBase.d.ts +1 -0
- package/dist/languageServerBase.js +1 -0
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/analyzerServiceExecutor.js +2 -0
- package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +5 -5
- package/dist/localization/localize.js +6 -3
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +34 -8
- package/dist/localization/package.nls.de.json +34 -8
- package/dist/localization/package.nls.en-us.json +8 -7
- package/dist/localization/package.nls.es.json +34 -8
- package/dist/localization/package.nls.fr.json +34 -8
- package/dist/localization/package.nls.it.json +34 -8
- package/dist/localization/package.nls.ja.json +34 -8
- package/dist/localization/package.nls.ko.json +34 -8
- package/dist/localization/package.nls.pl.json +34 -8
- package/dist/localization/package.nls.pt-br.json +34 -8
- package/dist/localization/package.nls.qps-ploc.json +32 -6
- package/dist/localization/package.nls.ru.json +34 -8
- package/dist/localization/package.nls.tr.json +34 -8
- package/dist/localization/package.nls.zh-cn.json +34 -8
- package/dist/localization/package.nls.zh-tw.json +34 -8
- package/dist/parser/parser.d.ts +1 -1
- package/dist/parser/parser.js +201 -201
- package/dist/parser/parser.js.map +1 -1
- package/dist/pyright.js +13 -11
- package/dist/pyright.js.map +1 -1
- package/dist/pyrightFileSystem.js +2 -2
- package/dist/server.js +7 -5
- package/dist/server.js.map +1 -1
- package/dist/tests/config.test.js +4 -4
- package/dist/tests/filesystem.test.js +2 -2
- package/dist/tests/fourSlashParser.test.js +1 -1
- package/dist/tests/harness/fourslash/testLanguageService.js +2 -0
- package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.js +1 -0
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/ipythonMode.test.js +10 -10
- package/dist/tests/ipythonMode.test.js.map +1 -1
- package/dist/tests/localizer.test.js +2 -2
- package/dist/tests/localizer.test.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +3 -3
- package/dist/tests/typeEvaluator2.test.js +8 -4
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +18 -6
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +2 -2
- package/dist/tests/typeEvaluator5.test.js +4 -0
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/dist/tests/uri.test.js +65 -8
- package/dist/tests/uri.test.js.map +1 -1
- package/dist/workspaceFactory.d.ts +1 -0
- package/dist/workspaceFactory.js +1 -0
- package/dist/workspaceFactory.js.map +1 -1
- package/package.json +1 -1
@@ -162,7 +162,7 @@ const maxRecursiveTypeAliasRecursionCount = 10;
|
|
162
162
|
// This switch enables a special debug mode that attempts to catch
|
163
163
|
// bugs due to inconsistent evaluation flags used when reading types
|
164
164
|
// from the type cache.
|
165
|
-
const verifyTypeCacheEvaluatorFlags =
|
165
|
+
const verifyTypeCacheEvaluatorFlags = false;
|
166
166
|
// This debugging option prints each expression and its evaluated type.
|
167
167
|
const printExpressionTypes = false;
|
168
168
|
// The following number is chosen somewhat arbitrarily. We need to cut
|
@@ -175,6 +175,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
175
175
|
const asymmetricAccessorAssignmentCache = new Set();
|
176
176
|
const speculativeTypeTracker = new typeCacheUtils_1.SpeculativeTypeTracker();
|
177
177
|
const suppressedNodeStack = [];
|
178
|
+
const assignClassToSelfStack = [];
|
178
179
|
let functionRecursionMap = new Set();
|
179
180
|
let codeFlowAnalyzerCache = new Map();
|
180
181
|
let typeCache = new Map();
|
@@ -546,6 +547,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
546
547
|
initializedBasicTypes(node);
|
547
548
|
let typeResult;
|
548
549
|
let expectingInstantiable = (flags & 128 /* EvaluatorFlags.ExpectingInstantiableType */) !== 0;
|
550
|
+
let allowSpeculativeCaching = true;
|
549
551
|
switch (node.nodeType) {
|
550
552
|
case 38 /* ParseNodeType.Name */: {
|
551
553
|
typeResult = getTypeOfName(node, flags);
|
@@ -645,11 +647,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
645
647
|
}
|
646
648
|
case 4 /* ParseNodeType.AssignmentExpression */: {
|
647
649
|
if ((flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0) {
|
648
|
-
addError(localize_1.
|
650
|
+
addError(localize_1.LocMessage.walrusNotAllowed(), node);
|
649
651
|
}
|
650
652
|
typeResult = getTypeOfExpression(node.rightExpression, flags, inferenceContext);
|
651
653
|
assignTypeToExpression(node.name, typeResult.type, !!typeResult.isIncomplete, node.rightExpression,
|
652
654
|
/* ignoreEmptyContainers */ true);
|
655
|
+
// Don't allow speculative caching for assignment expressions because
|
656
|
+
// the target name node won't have a corresponding type cached speculatively.
|
657
|
+
allowSpeculativeCaching = false;
|
653
658
|
break;
|
654
659
|
}
|
655
660
|
case 60 /* ParseNodeType.Yield */: {
|
@@ -712,7 +717,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
712
717
|
};
|
713
718
|
}
|
714
719
|
}
|
715
|
-
writeTypeCache(node, typeResult, flags, inferenceContext,
|
720
|
+
writeTypeCache(node, typeResult, flags, inferenceContext, allowSpeculativeCaching);
|
716
721
|
// If there was an expected type, make sure that the result type is compatible.
|
717
722
|
if (inferenceContext &&
|
718
723
|
!(0, types_1.isAnyOrUnknown)(inferenceContext.expectedType) &&
|
@@ -757,7 +762,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
757
762
|
if (isTypeCheckingOnly) {
|
758
763
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
759
764
|
if (!fileInfo.isStubFile) {
|
760
|
-
addDiagnostic(
|
765
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeCheckOnly().format({ name }), node);
|
761
766
|
}
|
762
767
|
}
|
763
768
|
}
|
@@ -769,7 +774,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
769
774
|
}
|
770
775
|
if (flags & 64 /* EvaluatorFlags.DisallowTypeVarTuple */) {
|
771
776
|
if ((0, types_1.isVariadicTypeVar)(typeResult.type) && !typeResult.type.isVariadicInUnion) {
|
772
|
-
addError(localize_1.
|
777
|
+
addError(localize_1.LocMessage.typeVarTupleContext(), node);
|
773
778
|
typeResult.type = types_1.UnknownType.create();
|
774
779
|
}
|
775
780
|
}
|
@@ -787,7 +792,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
787
792
|
}
|
788
793
|
function getTypeOfAwaitOperator(node, flags, inferenceContext) {
|
789
794
|
if ((flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0) {
|
790
|
-
addError(localize_1.
|
795
|
+
addError(localize_1.LocMessage.awaitNotAllowed(), node);
|
791
796
|
return { type: types_1.UnknownType.create() };
|
792
797
|
}
|
793
798
|
const effectiveExpectedType = inferenceContext
|
@@ -851,7 +856,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
851
856
|
typeResult = { type: types_1.ClassType.cloneForUnpacked(iterType) };
|
852
857
|
}
|
853
858
|
else if ((flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0) {
|
854
|
-
addError(localize_1.
|
859
|
+
addError(localize_1.LocMessage.unpackInAnnotation(), node, node.starToken);
|
855
860
|
typeResult = { type: types_1.UnknownType.create() };
|
856
861
|
}
|
857
862
|
else {
|
@@ -890,8 +895,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
890
895
|
}
|
891
896
|
}
|
892
897
|
if (!typeResult) {
|
893
|
-
|
894
|
-
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.expectedTypeNotString(), node);
|
898
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.expectedTypeNotString(), node);
|
895
899
|
typeResult = { type: types_1.UnknownType.create() };
|
896
900
|
}
|
897
901
|
}
|
@@ -1101,7 +1105,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1101
1105
|
}
|
1102
1106
|
const annotationType = getTypeOfExpression(node, evaluatorFlags).type;
|
1103
1107
|
if ((0, types_1.isModule)(annotationType)) {
|
1104
|
-
addDiagnostic(
|
1108
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.moduleAsType(), node);
|
1105
1109
|
}
|
1106
1110
|
return (0, typeUtils_1.convertToInstance)(annotationType);
|
1107
1111
|
}
|
@@ -1330,7 +1334,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1330
1334
|
function getTypeOfBoundMember(errorNode, objectType, memberName, usage = { method: 'get' }, diag = undefined, flags = 0 /* MemberAccessFlags.Default */, selfType, recursionCount = 0) {
|
1331
1335
|
if (types_1.ClassType.isPartiallyEvaluated(objectType)) {
|
1332
1336
|
if (errorNode) {
|
1333
|
-
addDiagnostic(
|
1337
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.classDefinitionCycle().format({ name: objectType.details.name }), errorNode);
|
1334
1338
|
}
|
1335
1339
|
return { type: types_1.UnknownType.create() };
|
1336
1340
|
}
|
@@ -1368,7 +1372,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1368
1372
|
if (!skipObjectTypeLookup) {
|
1369
1373
|
let effectiveFlags = flags;
|
1370
1374
|
if (objectTypeIsInstantiable) {
|
1371
|
-
effectiveFlags |=
|
1375
|
+
effectiveFlags |=
|
1376
|
+
16 /* MemberAccessFlags.SkipInstanceMembers */ |
|
1377
|
+
512 /* MemberAccessFlags.SkipAttributeAccessOverride */ |
|
1378
|
+
1024 /* MemberAccessFlags.DisallowGenericInstanceVariableAccess */;
|
1372
1379
|
effectiveFlags &= ~32 /* MemberAccessFlags.SkipClassMembers */;
|
1373
1380
|
}
|
1374
1381
|
else {
|
@@ -1520,8 +1527,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1520
1527
|
let constructorType;
|
1521
1528
|
// Try to get the `__init__` method first because it typically has more
|
1522
1529
|
// type information than `__new__`.
|
1523
|
-
const initMethodResult = (0, constructors_1.getBoundInitMethod)(evaluatorInterface, callNode, types_1.ClassType.cloneAsInstance(subtype),
|
1524
|
-
/* skipObjectBase */ false);
|
1530
|
+
const initMethodResult = (0, constructors_1.getBoundInitMethod)(evaluatorInterface, callNode, types_1.ClassType.cloneAsInstance(subtype), 0 /* MemberAccessFlags.Default */);
|
1525
1531
|
if (initMethodResult && !initMethodResult.typeErrors) {
|
1526
1532
|
if ((0, types_1.isFunction)(initMethodResult.type) || (0, types_1.isOverloadedFunction)(initMethodResult.type)) {
|
1527
1533
|
constructorType = initMethodResult.type;
|
@@ -1537,8 +1543,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1537
1543
|
// the `object` class or accepts only default parameters(* args, ** kwargs),
|
1538
1544
|
// see if we can find a better signature from the `__new__` method.
|
1539
1545
|
if (!constructorType || isObjectInit || isDefaultParams) {
|
1540
|
-
const newMethodResult = (0, constructors_1.getBoundNewMethod)(evaluatorInterface, callNode, subtype,
|
1541
|
-
/* skipObjectBase */ false);
|
1546
|
+
const newMethodResult = (0, constructors_1.getBoundNewMethod)(evaluatorInterface, callNode, subtype, 0 /* MemberAccessFlags.Default */);
|
1542
1547
|
if (newMethodResult && !newMethodResult.typeErrors && (0, types_1.isFunction)(newMethodResult.type)) {
|
1543
1548
|
if ((0, types_1.isFunction)(newMethodResult.type) &&
|
1544
1549
|
newMethodResult.type.details.fullName !== 'builtins.object.__new__') {
|
@@ -1761,8 +1766,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1761
1766
|
}
|
1762
1767
|
}
|
1763
1768
|
if (errorNode) {
|
1764
|
-
|
1765
|
-
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeNotAwaitable().format({ type: printType(subtype) }) + (diag === null || diag === void 0 ? void 0 : diag.getString()), errorNode);
|
1769
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeNotAwaitable().format({ type: printType(subtype) }) + (diag === null || diag === void 0 ? void 0 : diag.getString()), errorNode);
|
1766
1770
|
}
|
1767
1771
|
return types_1.UnknownType.create();
|
1768
1772
|
});
|
@@ -1777,7 +1781,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1777
1781
|
type = makeTopLevelTypeVarsConcrete(type);
|
1778
1782
|
if ((0, typeUtils_1.isOptionalType)(type)) {
|
1779
1783
|
if (!typeResult.isIncomplete && emitNotIterableError) {
|
1780
|
-
addDiagnostic(
|
1784
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportOptionalIterable, localize_1.LocMessage.noneNotIterable(), errorNode);
|
1781
1785
|
}
|
1782
1786
|
type = (0, typeUtils_1.removeNoneFromUnion)(type);
|
1783
1787
|
}
|
@@ -1811,7 +1815,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1811
1815
|
return getItemReturnType;
|
1812
1816
|
}
|
1813
1817
|
}
|
1814
|
-
diag.addMessage(localize_1.
|
1818
|
+
diag.addMessage(localize_1.LocMessage.methodNotDefined().format({ name: iterMethodName }));
|
1815
1819
|
}
|
1816
1820
|
else {
|
1817
1821
|
const iterReturnTypeDiag = new diagnostic_1.DiagnosticAddendum();
|
@@ -1823,7 +1827,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1823
1827
|
if ((0, types_1.isClassInstance)(subtype)) {
|
1824
1828
|
let nextReturnType = getTypeOfMagicMethodCall(subtype, nextMethodName, [], errorNode);
|
1825
1829
|
if (!nextReturnType) {
|
1826
|
-
iterReturnTypeDiag.addMessage(localize_1.
|
1830
|
+
iterReturnTypeDiag.addMessage(localize_1.LocMessage.methodNotDefinedOnType().format({
|
1827
1831
|
name: nextMethodName,
|
1828
1832
|
type: printType(subtype),
|
1829
1833
|
}));
|
@@ -1846,7 +1850,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1846
1850
|
}
|
1847
1851
|
}
|
1848
1852
|
else {
|
1849
|
-
iterReturnTypeDiag.addMessage(localize_1.
|
1853
|
+
iterReturnTypeDiag.addMessage(localize_1.LocMessage.methodReturnsNonObject().format({ name: iterMethodName }));
|
1850
1854
|
}
|
1851
1855
|
return undefined;
|
1852
1856
|
});
|
@@ -1857,7 +1861,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1857
1861
|
}
|
1858
1862
|
}
|
1859
1863
|
if (!typeResult.isIncomplete && emitNotIterableError) {
|
1860
|
-
addDiagnostic(
|
1864
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeNotIterable().format({ type: printType(subtype) }) + diag.getString(), errorNode);
|
1861
1865
|
}
|
1862
1866
|
isValidIterator = false;
|
1863
1867
|
return undefined;
|
@@ -1871,7 +1875,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1871
1875
|
let type = makeTopLevelTypeVarsConcrete(typeResult.type);
|
1872
1876
|
if ((0, typeUtils_1.isOptionalType)(type)) {
|
1873
1877
|
if (!typeResult.isIncomplete && emitNotIterableError) {
|
1874
|
-
addDiagnostic(
|
1878
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportOptionalIterable, localize_1.LocMessage.noneNotIterable(), errorNode);
|
1875
1879
|
}
|
1876
1880
|
type = (0, typeUtils_1.removeNoneFromUnion)(type);
|
1877
1881
|
}
|
@@ -1886,7 +1890,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1886
1890
|
}
|
1887
1891
|
}
|
1888
1892
|
if (emitNotIterableError) {
|
1889
|
-
addDiagnostic(
|
1893
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeNotIterable().format({ type: printType(subtype) }), errorNode);
|
1890
1894
|
}
|
1891
1895
|
isValidIterable = false;
|
1892
1896
|
return undefined;
|
@@ -1984,7 +1988,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1984
1988
|
errorRange = { start: 0, length: 0 };
|
1985
1989
|
}
|
1986
1990
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
1987
|
-
addDiagnosticForTextRange(fileInfo, fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.
|
1991
|
+
addDiagnosticForTextRange(fileInfo, fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.codeTooComplexToAnalyze(), errorRange);
|
1988
1992
|
return true;
|
1989
1993
|
}
|
1990
1994
|
return false;
|
@@ -2064,22 +2068,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2064
2068
|
function addInformation(message, node, range) {
|
2065
2069
|
return addDiagnosticWithSuppressionCheck('information', message, node, range);
|
2066
2070
|
}
|
2067
|
-
function addWarning(message, node, range) {
|
2068
|
-
return addDiagnosticWithSuppressionCheck('warning', message, node, range);
|
2069
|
-
}
|
2070
2071
|
function addError(message, node, range) {
|
2071
2072
|
return addDiagnosticWithSuppressionCheck('error', message, node, range);
|
2072
2073
|
}
|
2073
2074
|
function addUnusedCode(node, textRange) {
|
2074
2075
|
if (!isDiagnosticSuppressedForNode(node)) {
|
2075
2076
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
2076
|
-
fileInfo.diagnosticSink.addUnusedCodeWithTextRange(localize_1.
|
2077
|
+
fileInfo.diagnosticSink.addUnusedCodeWithTextRange(localize_1.LocMessage.unreachableCode(), textRange);
|
2077
2078
|
}
|
2078
2079
|
}
|
2079
2080
|
function addUnreachableCode(node, textRange) {
|
2080
2081
|
if (!isDiagnosticSuppressedForNode(node)) {
|
2081
2082
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
2082
|
-
fileInfo.diagnosticSink.addUnreachableCodeWithTextRange(localize_1.
|
2083
|
+
fileInfo.diagnosticSink.addUnreachableCodeWithTextRange(localize_1.LocMessage.unreachableCode(), textRange);
|
2083
2084
|
}
|
2084
2085
|
}
|
2085
2086
|
function addDeprecated(message, node) {
|
@@ -2099,18 +2100,27 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2099
2100
|
return (suppressedNodeStack.some((suppressedNode) => ParseTreeUtils.isNodeContainedWithin(node, suppressedNode)) ||
|
2100
2101
|
speculativeTypeTracker.isSpeculative(node, /* ignoreIfDiagnosticsAllowed */ true));
|
2101
2102
|
}
|
2102
|
-
function addDiagnostic(
|
2103
|
+
function addDiagnostic(rule, message, node, range) {
|
2104
|
+
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
2105
|
+
const diagLevel = fileInfo.diagnosticRuleSet[rule];
|
2103
2106
|
if (diagLevel === 'none') {
|
2104
2107
|
return undefined;
|
2105
2108
|
}
|
2106
|
-
|
2107
|
-
|
2108
|
-
|
2109
|
-
const
|
2110
|
-
|
2111
|
-
|
2112
|
-
ParseTreeUtils.isUnannotatedFunction(containingFunction) &&
|
2113
|
-
|
2109
|
+
const containingFunction = ParseTreeUtils.getEnclosingFunction(node);
|
2110
|
+
if (containingFunction) {
|
2111
|
+
// Should we suppress this diagnostic because it's within an unannotated function?
|
2112
|
+
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
2113
|
+
if (!fileInfo.diagnosticRuleSet.analyzeUnannotatedFunctions) {
|
2114
|
+
// Is the target node within the body of the function? If so, suppress the diagnostic.
|
2115
|
+
if (ParseTreeUtils.isUnannotatedFunction(containingFunction) &&
|
2116
|
+
ParseTreeUtils.isNodeContainedWithin(node, containingFunction.suite)) {
|
2117
|
+
return undefined;
|
2118
|
+
}
|
2119
|
+
}
|
2120
|
+
// Should we suppress this diagnostic because it's within a no_type_check function?
|
2121
|
+
const containingClassNode = ParseTreeUtils.getEnclosingClass(containingFunction, /* stopAtFunction */ true);
|
2122
|
+
const functionInfo = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, containingFunction, !!containingClassNode);
|
2123
|
+
if ((functionInfo.flags & 524288 /* FunctionTypeFlags.NoTypeCheck */) !== 0) {
|
2114
2124
|
return undefined;
|
2115
2125
|
}
|
2116
2126
|
}
|
@@ -2131,16 +2141,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2131
2141
|
return diagnostic;
|
2132
2142
|
}
|
2133
2143
|
function addExpectedClassDiagnostic(type, node) {
|
2134
|
-
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
2135
2144
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
2136
2145
|
if ((0, types_1.isUnion)(type)) {
|
2137
2146
|
(0, typeUtils_1.doForEachSubtype)(type, (subtype) => {
|
2138
2147
|
if (!(0, typeUtils_1.isEffectivelyInstantiable)(subtype)) {
|
2139
|
-
diag.addMessage(localize_1.
|
2148
|
+
diag.addMessage(localize_1.LocAddendum.typeNotClass().format({ type: printType(subtype) }));
|
2140
2149
|
}
|
2141
2150
|
});
|
2142
2151
|
}
|
2143
|
-
addDiagnostic(
|
2152
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeExpectedClass().format({ type: printType(type) }) + diag.getString(), node);
|
2144
2153
|
}
|
2145
2154
|
function assignTypeToNameNode(nameNode, type, isTypeIncomplete, ignoreEmptyContainers, srcExpression, allowAssignmentToFinalVar = false, expectedTypeDiagAddendum) {
|
2146
2155
|
var _a, _b, _c;
|
@@ -2179,7 +2188,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2179
2188
|
if (expectedTypeDiagAddendum) {
|
2180
2189
|
diagAddendum = expectedTypeDiagAddendum;
|
2181
2190
|
}
|
2182
|
-
addDiagnostic(
|
2191
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAssignmentMismatch().format(printSrcDestTypes(type, declaredType)) +
|
2183
2192
|
diagAddendum.getString(), srcExpression !== null && srcExpression !== void 0 ? srcExpression : nameNode, (_c = (_b = diagAddendum.getEffectiveTextRange()) !== null && _b !== void 0 ? _b : srcExpression) !== null && _c !== void 0 ? _c : nameNode);
|
2184
2193
|
// Replace the assigned type with the (unnarrowed) declared type.
|
2185
2194
|
destType = declaredType;
|
@@ -2209,11 +2218,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2209
2218
|
// A constant variable can be assigned only once. If this
|
2210
2219
|
// isn't the first assignment, generate an error.
|
2211
2220
|
if (nameNode !== (0, declarationUtils_1.getNameNodeForDeclaration)(declarations[0])) {
|
2212
|
-
addDiagnostic(
|
2221
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportConstantRedefinition, localize_1.LocMessage.constantRedefinition().format({ name: nameValue }), nameNode);
|
2213
2222
|
}
|
2214
2223
|
}
|
2215
2224
|
else if (isFinalVariableDeclaration(varDecl) && !allowAssignmentToFinalVar) {
|
2216
|
-
addDiagnostic(
|
2225
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.finalReassigned().format({ name: nameValue }), nameNode);
|
2217
2226
|
}
|
2218
2227
|
}
|
2219
2228
|
if (!isTypeIncomplete) {
|
@@ -2252,7 +2261,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2252
2261
|
return !ParseTreeUtils.getEnclosingFunction(decl.node);
|
2253
2262
|
});
|
2254
2263
|
if (classLevelDecls.length === 0) {
|
2255
|
-
addError(localize_1.
|
2264
|
+
addError(localize_1.LocMessage.assignmentInProtocol(), target.memberName);
|
2256
2265
|
}
|
2257
2266
|
}
|
2258
2267
|
}
|
@@ -2315,7 +2324,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2315
2324
|
}
|
2316
2325
|
}
|
2317
2326
|
if (!isPotentiallyDescriptor) {
|
2318
|
-
addDiagnostic(
|
2327
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.slotsAttributeError().format({ name: memberName }), node.memberName);
|
2319
2328
|
}
|
2320
2329
|
}
|
2321
2330
|
}
|
@@ -2330,7 +2339,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2330
2339
|
srcExprNode &&
|
2331
2340
|
node.memberName !== typedDecls[0].node) {
|
2332
2341
|
if (typedDecls[0].isConstant) {
|
2333
|
-
addDiagnostic(
|
2342
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportConstantRedefinition, localize_1.LocMessage.constantRedefinition().format({ name: node.memberName.value }), node.memberName);
|
2334
2343
|
}
|
2335
2344
|
}
|
2336
2345
|
}
|
@@ -2412,11 +2421,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2412
2421
|
const expectedEntryCount = unpackIndex >= 0 ? targetExpressions.length - 1 : targetExpressions.length;
|
2413
2422
|
const subDiag = diagAddendum.createAddendum();
|
2414
2423
|
subDiag.addMessage((target.nodeType === 31 /* ParseNodeType.List */
|
2415
|
-
? localize_1.
|
2416
|
-
: localize_1.
|
2424
|
+
? localize_1.LocAddendum.listAssignmentMismatch()
|
2425
|
+
: localize_1.LocAddendum.tupleAssignmentMismatch()).format({
|
2417
2426
|
type: printType(subtype),
|
2418
2427
|
}));
|
2419
|
-
subDiag.createAddendum().addMessage(localize_1.
|
2428
|
+
subDiag.createAddendum().addMessage(localize_1.LocAddendum.tupleSizeMismatch().format({
|
2420
2429
|
expected: expectedEntryCount,
|
2421
2430
|
received: sourceEntryTypes.length,
|
2422
2431
|
}));
|
@@ -2432,10 +2441,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2432
2441
|
}
|
2433
2442
|
});
|
2434
2443
|
if (!diagAddendum.isEmpty()) {
|
2435
|
-
|
2436
|
-
|
2437
|
-
|
2438
|
-
: localize_1.Localizer.Diagnostic.tupleAssignmentMismatch()).format({
|
2444
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, (target.nodeType === 31 /* ParseNodeType.List */
|
2445
|
+
? localize_1.LocMessage.listAssignmentMismatch()
|
2446
|
+
: localize_1.LocMessage.tupleAssignmentMismatch()).format({
|
2439
2447
|
type: printType(type),
|
2440
2448
|
}) + diagAddendum.getString(), target);
|
2441
2449
|
}
|
@@ -2690,10 +2698,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2690
2698
|
const typeVarTarget = target.nodeType === 54 /* ParseNodeType.TypeAnnotation */ ? target.valueExpression : target;
|
2691
2699
|
if (typeVarTarget.nodeType !== 38 /* ParseNodeType.Name */ || typeVarTarget.value !== type.details.name) {
|
2692
2700
|
addError(type.details.isParamSpec
|
2693
|
-
? localize_1.
|
2701
|
+
? localize_1.LocMessage.paramSpecAssignedName().format({
|
2694
2702
|
name: types_1.TypeVarType.getReadableName(type),
|
2695
2703
|
})
|
2696
|
-
: localize_1.
|
2704
|
+
: localize_1.LocMessage.typeVarAssignedName().format({
|
2697
2705
|
name: types_1.TypeVarType.getReadableName(type),
|
2698
2706
|
}), typeVarTarget);
|
2699
2707
|
}
|
@@ -2772,7 +2780,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2772
2780
|
break;
|
2773
2781
|
}
|
2774
2782
|
default: {
|
2775
|
-
addError(localize_1.
|
2783
|
+
addError(localize_1.LocMessage.assignmentTargetExpr(), target);
|
2776
2784
|
break;
|
2777
2785
|
}
|
2778
2786
|
}
|
@@ -2792,7 +2800,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2792
2800
|
if ((0, types_1.isInstantiableClass)(concreteSubtype) && concreteSubtype.literalValue === undefined) {
|
2793
2801
|
if (!(0, typeUtils_1.derivesFromClassRecursive)(concreteSubtype, baseExceptionType,
|
2794
2802
|
/* ignoreUnknown */ false)) {
|
2795
|
-
diagAddendum.addMessage(localize_1.
|
2803
|
+
diagAddendum.addMessage(localize_1.LocMessage.exceptionTypeIncorrect().format({
|
2796
2804
|
type: printType(subtype),
|
2797
2805
|
}));
|
2798
2806
|
}
|
@@ -2804,7 +2812,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2804
2812
|
/* inferenceContext */ undefined);
|
2805
2813
|
});
|
2806
2814
|
if (callResult && callResult.argumentErrors) {
|
2807
|
-
diagAddendum.addMessage(localize_1.
|
2815
|
+
diagAddendum.addMessage(localize_1.LocMessage.exceptionTypeNotInstantiable().format({
|
2808
2816
|
type: printType(subtype),
|
2809
2817
|
}));
|
2810
2818
|
}
|
@@ -2813,21 +2821,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2813
2821
|
else if ((0, types_1.isClassInstance)(concreteSubtype)) {
|
2814
2822
|
if (!(0, typeUtils_1.derivesFromClassRecursive)(types_1.ClassType.cloneAsInstantiable(concreteSubtype), baseExceptionType,
|
2815
2823
|
/* ignoreUnknown */ false)) {
|
2816
|
-
diagAddendum.addMessage(localize_1.
|
2824
|
+
diagAddendum.addMessage(localize_1.LocMessage.exceptionTypeIncorrect().format({
|
2817
2825
|
type: printType(subtype),
|
2818
2826
|
}));
|
2819
2827
|
}
|
2820
2828
|
}
|
2821
2829
|
else {
|
2822
|
-
diagAddendum.addMessage(localize_1.
|
2830
|
+
diagAddendum.addMessage(localize_1.LocMessage.exceptionTypeIncorrect().format({
|
2823
2831
|
type: printType(subtype),
|
2824
2832
|
}));
|
2825
2833
|
}
|
2826
2834
|
}
|
2827
2835
|
});
|
2828
2836
|
if (!diagAddendum.isEmpty()) {
|
2829
|
-
|
2830
|
-
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.expectedExceptionClass() + diagAddendum.getString(), node.typeExpression);
|
2837
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.expectedExceptionClass() + diagAddendum.getString(), node.typeExpression);
|
2831
2838
|
}
|
2832
2839
|
}
|
2833
2840
|
}
|
@@ -2874,8 +2881,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2874
2881
|
break;
|
2875
2882
|
}
|
2876
2883
|
default: {
|
2877
|
-
|
2878
|
-
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.delTargetExpr(), node);
|
2884
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.delTargetExpr(), node);
|
2879
2885
|
break;
|
2880
2886
|
}
|
2881
2887
|
}
|
@@ -2947,7 +2953,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2947
2953
|
isIncomplete = true;
|
2948
2954
|
}
|
2949
2955
|
if (effectiveTypeInfo.isRecursiveDefinition && isNodeReachable(node)) {
|
2950
|
-
addDiagnostic(
|
2956
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.recursiveDefinition().format({ name }), node);
|
2951
2957
|
}
|
2952
2958
|
const isSpecialBuiltIn = !!effectiveType && (0, types_1.isInstantiableClass)(effectiveType) && types_1.ClassType.isSpecialBuiltIn(effectiveType);
|
2953
2959
|
type = effectiveType;
|
@@ -3012,7 +3018,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3012
3018
|
if (effectiveTypeInfo.includesIllegalTypeAliasDecl ||
|
3013
3019
|
!types_1.TypeBase.isInstantiable(type) ||
|
3014
3020
|
(flags & 2 /* EvaluatorFlags.DoNotSpecialize */) !== 0) {
|
3015
|
-
addDiagnostic(
|
3021
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAnnotationVariable(), node);
|
3016
3022
|
type = types_1.UnknownType.create();
|
3017
3023
|
}
|
3018
3024
|
}
|
@@ -3025,14 +3031,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3025
3031
|
type = types_1.AnyType.create();
|
3026
3032
|
}
|
3027
3033
|
else {
|
3028
|
-
addDiagnostic(
|
3034
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUndefinedVariable, localize_1.LocMessage.symbolIsUndefined().format({ name }), node);
|
3029
3035
|
type = types_1.UnknownType.create();
|
3030
3036
|
}
|
3031
3037
|
}
|
3032
3038
|
}
|
3033
3039
|
if ((0, types_1.isParamSpec)(type)) {
|
3034
3040
|
if (flags & 32 /* EvaluatorFlags.DisallowParamSpec */) {
|
3035
|
-
addError(localize_1.
|
3041
|
+
addError(localize_1.LocMessage.paramSpecContext(), node);
|
3036
3042
|
type = types_1.UnknownType.create();
|
3037
3043
|
}
|
3038
3044
|
}
|
@@ -3043,7 +3049,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3043
3049
|
if ((flags & 128 /* EvaluatorFlags.ExpectingInstantiableType */) !== 0) {
|
3044
3050
|
if ((flags & 1024 /* EvaluatorFlags.AllowGenericClassType */) === 0) {
|
3045
3051
|
if ((0, types_1.isInstantiableClass)(type) && types_1.ClassType.isBuiltIn(type, 'Generic')) {
|
3046
|
-
addDiagnostic(
|
3052
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.genericNotAllowed(), node);
|
3047
3053
|
}
|
3048
3054
|
}
|
3049
3055
|
}
|
@@ -3053,35 +3059,25 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3053
3059
|
return { type, isIncomplete };
|
3054
3060
|
}
|
3055
3061
|
// If the type is a TypeVar and we're not expecting a type, convert
|
3056
|
-
// a TypeVar or
|
3057
|
-
// do this for ParamSpec (although we arguably should) because it's
|
3058
|
-
// problematic for handling P.args and P.kwargs.
|
3062
|
+
// a TypeVar, TypeVarTuple or ParamSpec into a runtime type.
|
3059
3063
|
function convertTypeVarToRuntimeInstance(node, type, flags) {
|
3060
3064
|
var _a;
|
3061
|
-
if (
|
3062
|
-
|
3063
|
-
node.value === type.details.name &&
|
3064
|
-
!type.isVariadicInUnion &&
|
3065
|
-
(flags & 128 /* EvaluatorFlags.ExpectingInstantiableType */) === 0) {
|
3066
|
-
if ((flags & 33554432 /* EvaluatorFlags.SkipConvertParamSpecToRuntimeObject */) !== 0 && type.details.isParamSpec) {
|
3067
|
-
return type;
|
3068
|
-
}
|
3069
|
-
// Handle the special case of a PEP 604 union. These can appear within
|
3070
|
-
// an implied type alias where we are not expecting a type.
|
3071
|
-
const isPep604Union = ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 7 /* ParseNodeType.BinaryOperation */ &&
|
3072
|
-
node.parent.operator === 6 /* OperatorType.BitwiseOr */;
|
3073
|
-
if (!isPep604Union) {
|
3074
|
-
// A TypeVar in contexts where we're not expecting a type is
|
3075
|
-
// simply a runtime object.
|
3076
|
-
if (type.details.runtimeClass) {
|
3077
|
-
type = types_1.ClassType.cloneAsInstance(type.details.runtimeClass);
|
3078
|
-
}
|
3079
|
-
else {
|
3080
|
-
type = types_1.UnknownType.create();
|
3081
|
-
}
|
3082
|
-
}
|
3065
|
+
if (!type.specialForm || type.typeAliasInfo) {
|
3066
|
+
return type;
|
3083
3067
|
}
|
3084
|
-
|
3068
|
+
if (!(0, types_1.isTypeVar)(type) || type.isVariadicInUnion || (flags & 128 /* EvaluatorFlags.ExpectingInstantiableType */) !== 0) {
|
3069
|
+
return type;
|
3070
|
+
}
|
3071
|
+
if ((flags & 33554432 /* EvaluatorFlags.SkipConvertParamSpecToRuntimeObject */) !== 0 && type.details.isParamSpec) {
|
3072
|
+
return types_1.TypeBase.cloneAsSpecialForm(type, undefined);
|
3073
|
+
}
|
3074
|
+
// Handle the special case of a PEP 604 union. These can appear within
|
3075
|
+
// an implied type alias where we are not expecting a type.
|
3076
|
+
const isPep604Union = ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 7 /* ParseNodeType.BinaryOperation */ && node.parent.operator === 6 /* OperatorType.BitwiseOr */;
|
3077
|
+
if (isPep604Union) {
|
3078
|
+
return types_1.TypeBase.cloneAsSpecialForm(type, undefined);
|
3079
|
+
}
|
3080
|
+
return types_1.ClassType.cloneAsInstance(type.specialForm);
|
3085
3081
|
}
|
3086
3082
|
// Handles the case where a variable or parameter is defined in an outer
|
3087
3083
|
// scope and captured by an inner scope (a function, lambda, or comprehension).
|
@@ -3165,7 +3161,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3165
3161
|
!typeVarScopeNode.typeParameters.parameters.some((t) => t.name === node)) {
|
3166
3162
|
return type;
|
3167
3163
|
}
|
3168
|
-
addDiagnostic(
|
3164
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarUsedByOuterScope().format({ name: type.details.name }), node);
|
3169
3165
|
}
|
3170
3166
|
}
|
3171
3167
|
else if ((flags & 8192 /* EvaluatorFlags.AssociateTypeVarsWithCurrentScope */) !== 0) {
|
@@ -3181,8 +3177,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3181
3177
|
const outerFunctionScope = ParseTreeUtils.getEnclosingClassOrFunction(enclosingScope);
|
3182
3178
|
if ((outerFunctionScope === null || outerFunctionScope === void 0 ? void 0 : outerFunctionScope.nodeType) === 28 /* ParseNodeType.Function */) {
|
3183
3179
|
if (scopedTypeVarInfo.isRescoped) {
|
3184
|
-
addDiagnostic(
|
3185
|
-
.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.paramSpecScopedToReturnType().format({
|
3180
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.paramSpecScopedToReturnType().format({
|
3186
3181
|
name: type.details.name,
|
3187
3182
|
}), node);
|
3188
3183
|
}
|
@@ -3191,7 +3186,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3191
3186
|
}
|
3192
3187
|
}
|
3193
3188
|
else if (!scopedTypeVarInfo.type.scopeId) {
|
3194
|
-
addDiagnostic(
|
3189
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.paramSpecNotUsedByOuterScope().format({
|
3195
3190
|
name: type.details.name,
|
3196
3191
|
}), node);
|
3197
3192
|
}
|
@@ -3202,7 +3197,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3202
3197
|
// type variables can't be used in this context.
|
3203
3198
|
if (enclosingScope.typeParameters &&
|
3204
3199
|
!enclosingScope.typeParameters.parameters.some((param) => param.name.value === type.details.name)) {
|
3205
|
-
addDiagnostic(
|
3200
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeParameterNotDeclared().format({
|
3206
3201
|
name: type.details.name,
|
3207
3202
|
container: enclosingScope.name.value,
|
3208
3203
|
}), node);
|
@@ -3216,7 +3211,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3216
3211
|
}
|
3217
3212
|
}
|
3218
3213
|
else {
|
3219
|
-
addDiagnostic(
|
3214
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarUsedByOuterScope().format({ name: type.details.name }), node);
|
3220
3215
|
}
|
3221
3216
|
}
|
3222
3217
|
}
|
@@ -3226,15 +3221,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3226
3221
|
let message;
|
3227
3222
|
if (scopedTypeVarInfo.isRescoped) {
|
3228
3223
|
message = (0, types_1.isParamSpec)(type)
|
3229
|
-
? localize_1.
|
3230
|
-
: localize_1.
|
3224
|
+
? localize_1.LocMessage.paramSpecScopedToReturnType()
|
3225
|
+
: localize_1.LocMessage.typeVarScopedToReturnType();
|
3231
3226
|
}
|
3232
3227
|
else {
|
3233
3228
|
message = (0, types_1.isParamSpec)(type)
|
3234
|
-
? localize_1.
|
3235
|
-
: localize_1.
|
3229
|
+
? localize_1.LocMessage.paramSpecNotUsedByOuterScope()
|
3230
|
+
: localize_1.LocMessage.typeVarNotUsedByOuterScope();
|
3236
3231
|
}
|
3237
|
-
addDiagnostic(
|
3232
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, message.format({ name: type.details.name }), node);
|
3238
3233
|
}
|
3239
3234
|
}
|
3240
3235
|
}
|
@@ -3259,7 +3254,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3259
3254
|
(flags & 512 /* EvaluatorFlags.AllowMissingTypeArgs */) === 0) {
|
3260
3255
|
if (!type.typeAliasInfo && (0, typeUtils_1.requiresTypeArguments)(type)) {
|
3261
3256
|
if (!type.typeArguments || !type.isTypeArgumentExplicit) {
|
3262
|
-
addDiagnostic(
|
3257
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportMissingTypeArgument, localize_1.LocMessage.typeArgsMissingForClass().format({
|
3263
3258
|
name: type.aliasName || type.details.name,
|
3264
3259
|
}), node);
|
3265
3260
|
}
|
@@ -3298,7 +3293,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3298
3293
|
typeVarContext.setTypeVarType(param, defaultType);
|
3299
3294
|
});
|
3300
3295
|
if (reportMissingTypeArguments) {
|
3301
|
-
addDiagnostic(
|
3296
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportMissingTypeArgument, localize_1.LocMessage.typeArgsMissingForAlias().format({
|
3302
3297
|
name: type.typeAliasInfo.name,
|
3303
3298
|
}), node);
|
3304
3299
|
}
|
@@ -3380,7 +3375,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3380
3375
|
leftType.details.recursiveTypeAliasName) {
|
3381
3376
|
// Type alias statements cannot be used with old-style type variables.
|
3382
3377
|
if (typeAliasNode && !type.details.isTypeParamSyntax) {
|
3383
|
-
addDiagnostic(
|
3378
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeParameterNotDeclared().format({
|
3384
3379
|
name: type.details.name,
|
3385
3380
|
container: typeAliasNode.name.value,
|
3386
3381
|
}), node);
|
@@ -3499,7 +3494,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3499
3494
|
return typeResult;
|
3500
3495
|
}
|
3501
3496
|
function getTypeOfMemberAccessWithBaseType(node, baseTypeResult, usage, flags) {
|
3502
|
-
var _a
|
3497
|
+
var _a;
|
3503
3498
|
let baseType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(baseTypeResult.type);
|
3504
3499
|
const memberName = node.memberName.value;
|
3505
3500
|
let diag = new diagnostic_1.DiagnosticAddendum();
|
@@ -3540,8 +3535,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3540
3535
|
const expectedCategory = isArgs ? 1 /* ParameterCategory.ArgsList */ : 2 /* ParameterCategory.KwargsDict */;
|
3541
3536
|
if (!paramNode || paramNode.category !== expectedCategory) {
|
3542
3537
|
const errorMessage = isArgs
|
3543
|
-
? localize_1.
|
3544
|
-
: localize_1.
|
3538
|
+
? localize_1.LocMessage.paramSpecArgsUsage()
|
3539
|
+
: localize_1.LocMessage.paramSpecKwargsUsage();
|
3545
3540
|
addError(errorMessage, node);
|
3546
3541
|
type = types_1.UnknownType.create(isIncomplete);
|
3547
3542
|
break;
|
@@ -3550,7 +3545,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3550
3545
|
break;
|
3551
3546
|
}
|
3552
3547
|
if (!isIncomplete) {
|
3553
|
-
addDiagnostic(
|
3548
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.paramSpecUnknownMember().format({ name: memberName }), node);
|
3554
3549
|
}
|
3555
3550
|
type = types_1.UnknownType.create(isIncomplete);
|
3556
3551
|
break;
|
@@ -3558,7 +3553,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3558
3553
|
// It's illegal to reference a member from a type variable.
|
3559
3554
|
if ((flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0) {
|
3560
3555
|
if (!isIncomplete) {
|
3561
|
-
addDiagnostic(
|
3556
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarNoMember().format({
|
3562
3557
|
type: printType(baseType),
|
3563
3558
|
name: memberName,
|
3564
3559
|
}), node.leftExpression);
|
@@ -3581,8 +3576,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3581
3576
|
}, usage, 0 /* EvaluatorFlags.None */);
|
3582
3577
|
}
|
3583
3578
|
case 6 /* TypeCategory.Class */: {
|
3584
|
-
|
3585
|
-
|
3579
|
+
let typeResult;
|
3580
|
+
if (usage.method === 'get') {
|
3581
|
+
typeResult = (0, enums_1.getTypeOfEnumMember)(evaluatorInterface, node, baseType, memberName, isIncomplete);
|
3582
|
+
}
|
3583
|
+
if (!typeResult) {
|
3584
|
+
typeResult = getTypeOfBoundMember(node.memberName, baseType, memberName, usage, diag,
|
3585
|
+
/* memberAccessFlags */ undefined, baseTypeResult.bindToSelfType);
|
3586
|
+
}
|
3586
3587
|
if (typeResult) {
|
3587
3588
|
type = (0, typeUtils_1.addConditionToType)(typeResult.type, (0, typeUtils_1.getTypeCondition)(baseType),
|
3588
3589
|
/* skipSelfCondition */ true);
|
@@ -3618,12 +3619,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3618
3619
|
type = types_1.UnknownType.create(/* isIncomplete */ true);
|
3619
3620
|
}
|
3620
3621
|
if (symbol.isPrivateMember()) {
|
3621
|
-
addDiagnostic(
|
3622
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportPrivateUsage, localize_1.LocMessage.privateUsedOutsideOfModule().format({
|
3622
3623
|
name: memberName,
|
3623
3624
|
}), node.memberName);
|
3624
3625
|
}
|
3625
3626
|
if (symbol.isPrivatePyTypedImport()) {
|
3626
|
-
addDiagnostic(
|
3627
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportPrivateImportUsage, localize_1.LocMessage.privateImportFromPyTypedModule().format({
|
3627
3628
|
name: memberName,
|
3628
3629
|
module: baseType.moduleName,
|
3629
3630
|
}), node.memberName);
|
@@ -3654,7 +3655,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3654
3655
|
}
|
3655
3656
|
if (!type) {
|
3656
3657
|
if (!isIncomplete) {
|
3657
|
-
addDiagnostic(
|
3658
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.moduleUnknownMember().format({
|
3658
3659
|
memberName,
|
3659
3660
|
moduleName: baseType.moduleName,
|
3660
3661
|
}), node.memberName);
|
@@ -3681,7 +3682,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3681
3682
|
return type;
|
3682
3683
|
}
|
3683
3684
|
if (!isIncomplete) {
|
3684
|
-
addDiagnostic(
|
3685
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportOptionalMemberAccess, localize_1.LocMessage.noneUnknownMember().format({ name: memberName }), node.memberName);
|
3685
3686
|
}
|
3686
3687
|
return undefined;
|
3687
3688
|
}
|
@@ -3725,12 +3726,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3725
3726
|
(0, types_1.isOverloadedFunction)(baseType) ||
|
3726
3727
|
((0, types_1.isClassInstance)(baseType) && types_1.ClassType.isBuiltIn(baseType, 'function'));
|
3727
3728
|
if (!baseTypeResult.isIncomplete) {
|
3728
|
-
let diagMessage = localize_1.
|
3729
|
+
let diagMessage = localize_1.LocMessage.memberAccess();
|
3729
3730
|
if (usage.method === 'set') {
|
3730
|
-
diagMessage = localize_1.
|
3731
|
+
diagMessage = localize_1.LocMessage.memberSet();
|
3731
3732
|
}
|
3732
3733
|
else if (usage.method === 'del') {
|
3733
|
-
diagMessage = localize_1.
|
3734
|
+
diagMessage = localize_1.LocMessage.memberDelete();
|
3734
3735
|
}
|
3735
3736
|
// If there is an expected type diagnostic addendum (used for assignments),
|
3736
3737
|
// use that rather than the local diagnostic addendum because it will be
|
@@ -3738,10 +3739,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3738
3739
|
if (usage.setExpectedTypeDiag) {
|
3739
3740
|
diag = usage.setExpectedTypeDiag;
|
3740
3741
|
}
|
3741
|
-
const
|
3742
|
-
?
|
3743
|
-
:
|
3744
|
-
addDiagnostic(
|
3742
|
+
const rule = isFunctionRule
|
3743
|
+
? diagnosticRules_1.DiagnosticRule.reportFunctionMemberAccess
|
3744
|
+
: diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues;
|
3745
|
+
addDiagnostic(rule, diagMessage.format({ name: memberName, type: printType(baseType) }) + diag.getString(), node.memberName, (_a = diag.getEffectiveTextRange()) !== null && _a !== void 0 ? _a : node.memberName);
|
3745
3746
|
}
|
3746
3747
|
// If this is member access on a function, use "Any" so if the
|
3747
3748
|
// reportFunctionMemberAccess rule is disabled, we don't trigger
|
@@ -3782,13 +3783,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3782
3783
|
}
|
3783
3784
|
}
|
3784
3785
|
// Report that the member could not be accessed.
|
3785
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
3786
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.memberUnknown().format({ name: memberName }));
|
3786
3787
|
return undefined;
|
3787
3788
|
}
|
3788
3789
|
let type;
|
3789
3790
|
let isTypeIncomplete = false;
|
3790
3791
|
if (memberInfo.symbol.isInitVar()) {
|
3791
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
3792
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.memberIsInitVar().format({ name: memberName }));
|
3792
3793
|
return undefined;
|
3793
3794
|
}
|
3794
3795
|
if (usage.method !== 'get' && errorNode) {
|
@@ -3811,7 +3812,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3811
3812
|
// clear the flag that causes an error to be generated.
|
3812
3813
|
if (usage.method === 'set' && memberInfo.symbol.isClassVar() && isAccessedThroughObject) {
|
3813
3814
|
const selfClass = (selfType !== null && selfType !== void 0 ? selfType : memberName === '__new__') ? undefined : classType;
|
3814
|
-
const typeResult = getTypeOfMemberInternal(memberInfo, selfClass);
|
3815
|
+
const typeResult = getTypeOfMemberInternal(errorNode, memberInfo, selfClass, flags);
|
3815
3816
|
if (typeResult) {
|
3816
3817
|
if ((0, typeUtils_1.isDescriptorInstance)(typeResult.type, /* requireSetter */ true)) {
|
3817
3818
|
type = typeResult.type;
|
@@ -3837,7 +3838,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3837
3838
|
selfClass = classType;
|
3838
3839
|
}
|
3839
3840
|
}
|
3840
|
-
const typeResult = getTypeOfMemberInternal(memberInfo, selfClass);
|
3841
|
+
const typeResult = getTypeOfMemberInternal(errorNode, memberInfo, selfClass, flags);
|
3841
3842
|
type = (_c = typeResult === null || typeResult === void 0 ? void 0 : typeResult.type) !== null && _c !== void 0 ? _c : types_1.UnknownType.create();
|
3842
3843
|
if (typeResult === null || typeResult === void 0 ? void 0 : typeResult.isIncomplete) {
|
3843
3844
|
isTypeIncomplete = true;
|
@@ -3847,7 +3848,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3847
3848
|
if ((0, types_1.isClass)(memberInfo.classType) && types_1.ClassType.isTypedDictClass(memberInfo.classType)) {
|
3848
3849
|
const typedDecls = memberInfo.symbol.getTypedDeclarations();
|
3849
3850
|
if (typedDecls.length > 0 && typedDecls[0].type === 1 /* DeclarationType.Variable */) {
|
3850
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
3851
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.memberUnknown().format({ name: memberName }));
|
3851
3852
|
return undefined;
|
3852
3853
|
}
|
3853
3854
|
}
|
@@ -3911,7 +3912,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3911
3912
|
if (!isDescriptorApplied &&
|
3912
3913
|
(memberInfo === null || memberInfo === void 0 ? void 0 : memberInfo.symbol.isClassVar()) &&
|
3913
3914
|
(flags & 128 /* MemberAccessFlags.DisallowClassVarWrites */) !== 0) {
|
3914
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
3915
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.memberSetClassVar().format({ name: memberName }));
|
3915
3916
|
isDescriptorError = true;
|
3916
3917
|
}
|
3917
3918
|
// Check for an attempt to overwrite a final member variable.
|
@@ -3923,7 +3924,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3923
3924
|
// being assigned within an __init__ method, it's allowed.
|
3924
3925
|
const enclosingFunctionNode = ParseTreeUtils.getEnclosingFunction(errorNode);
|
3925
3926
|
if (!enclosingFunctionNode || enclosingFunctionNode.name.value !== '__init__') {
|
3926
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
3927
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocMessage.finalReassigned().format({ name: memberName }));
|
3927
3928
|
isDescriptorError = true;
|
3928
3929
|
}
|
3929
3930
|
}
|
@@ -3932,7 +3933,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3932
3933
|
if ((memberInfo === null || memberInfo === void 0 ? void 0 : memberInfo.isInstanceMember) &&
|
3933
3934
|
(0, types_1.isClass)(memberInfo.classType) &&
|
3934
3935
|
types_1.ClassType.isReadOnlyInstanceVariables(memberInfo.classType)) {
|
3935
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
3936
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.readOnlyAttribute().format({ name: memberName }));
|
3936
3937
|
isDescriptorError = true;
|
3937
3938
|
}
|
3938
3939
|
return resultType;
|
@@ -3941,7 +3942,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3941
3942
|
// Verify that the assigned type is compatible.
|
3942
3943
|
if (!assignType(type, usage.setType.type, diag === null || diag === void 0 ? void 0 : diag.createAddendum())) {
|
3943
3944
|
if (!usage.setType.isIncomplete) {
|
3944
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
3945
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.memberAssignment().format({
|
3945
3946
|
type: printType(usage.setType.type),
|
3946
3947
|
name: memberName,
|
3947
3948
|
classType: printObjectTypeForClass(classType),
|
@@ -3952,7 +3953,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3952
3953
|
if ((0, types_1.isInstantiableClass)(memberInfo.classType) &&
|
3953
3954
|
types_1.ClassType.isFrozenDataClass(memberInfo.classType) &&
|
3954
3955
|
isAccessedThroughObject) {
|
3955
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
3956
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.dataClassFrozen().format({
|
3956
3957
|
name: printType(types_1.ClassType.cloneAsInstance(memberInfo.classType)),
|
3957
3958
|
}));
|
3958
3959
|
isDescriptorError = true;
|
@@ -3992,8 +3993,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3992
3993
|
if (types_1.ClassType.isPropertyClass(concreteMemberType)) {
|
3993
3994
|
if (usage.method !== 'get') {
|
3994
3995
|
const message = usage.method === 'set'
|
3995
|
-
? localize_1.
|
3996
|
-
: localize_1.
|
3996
|
+
? localize_1.LocAddendum.propertyMissingSetter()
|
3997
|
+
: localize_1.LocAddendum.propertyMissingDeleter();
|
3997
3998
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(message.format({ name: memberName }));
|
3998
3999
|
return { type: types_1.AnyType.create(), typeErrors: true };
|
3999
4000
|
}
|
@@ -4022,7 +4023,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4022
4023
|
// interpreted as a read-only attribute rather than a protocol, so accessing
|
4023
4024
|
// it directly from the class has an ambiguous meaning.
|
4024
4025
|
if ((flags & 16 /* MemberAccessFlags.SkipInstanceMembers */) !== 0 && types_1.ClassType.isProtocolClass(classType)) {
|
4025
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
4026
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.propertyAccessFromProtocolClass());
|
4026
4027
|
return { type: memberType, typeErrors: true };
|
4027
4028
|
}
|
4028
4029
|
// Infer return types before specializing. Otherwise a generic inferred
|
@@ -4062,7 +4063,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4062
4063
|
}
|
4063
4064
|
}
|
4064
4065
|
if (!methodType) {
|
4065
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
4066
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.descriptorAccessBindingFailed().format({
|
4066
4067
|
name: accessMethodName,
|
4067
4068
|
className: printType((0, typeUtils_1.convertToInstance)(methodClassType)),
|
4068
4069
|
}));
|
@@ -4150,17 +4151,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4150
4151
|
methodType.details.parameters.length >= 2 &&
|
4151
4152
|
!usage.setType.isIncomplete) {
|
4152
4153
|
const setterType = types_1.FunctionType.getEffectiveParameterType(methodType, 1);
|
4153
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
4154
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeIncompatible().format({
|
4154
4155
|
destType: printType(setterType),
|
4155
4156
|
sourceType: printType(usage.setType.type),
|
4156
4157
|
}));
|
4157
4158
|
}
|
4158
4159
|
else if ((0, types_1.isOverloadedFunction)(methodType)) {
|
4159
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
4160
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocMessage.noOverload().format({ name: accessMethodName }));
|
4160
4161
|
}
|
4161
4162
|
}
|
4162
4163
|
else {
|
4163
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
4164
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.descriptorAccessCallFailed().format({
|
4164
4165
|
name: accessMethodName,
|
4165
4166
|
className: printType((0, typeUtils_1.convertToInstance)(methodClassType)),
|
4166
4167
|
}));
|
@@ -4180,7 +4181,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4180
4181
|
? concreteType
|
4181
4182
|
: types_1.OverloadedFunctionType.getImplementation(concreteType);
|
4182
4183
|
if (impl && types_1.FunctionType.isFinal(impl) && memberInfo && (0, types_1.isClass)(memberInfo.classType)) {
|
4183
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
4184
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocMessage.finalMethodOverride().format({
|
4184
4185
|
name: memberName,
|
4185
4186
|
className: memberInfo.classType.details.name,
|
4186
4187
|
}));
|
@@ -4335,7 +4336,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4335
4336
|
// runtime exception.
|
4336
4337
|
if (flags & 128 /* EvaluatorFlags.ExpectingInstantiableType */) {
|
4337
4338
|
if (node.baseExpression.nodeType === 48 /* ParseNodeType.StringList */) {
|
4338
|
-
addError(localize_1.
|
4339
|
+
addError(localize_1.LocMessage.stringNotSubscriptable(), node.baseExpression);
|
4339
4340
|
}
|
4340
4341
|
}
|
4341
4342
|
// Check for builtin classes that will generate runtime exceptions if subscripted.
|
@@ -4359,7 +4360,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4359
4360
|
if (minPythonVersion !== undefined &&
|
4360
4361
|
fileInfo.executionEnvironment.pythonVersion < minPythonVersion &&
|
4361
4362
|
!fileInfo.isStubFile) {
|
4362
|
-
addError(localize_1.
|
4363
|
+
addError(localize_1.LocMessage.classNotRuntimeSubscriptable().format({
|
4363
4364
|
name: baseTypeResult.type.aliasName || baseTypeResult.type.details.name,
|
4364
4365
|
}), node.baseExpression);
|
4365
4366
|
}
|
@@ -4498,7 +4499,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4498
4499
|
// If the variadic type variable is not unpacked, report an error.
|
4499
4500
|
function validateVariadicTypeVarIsUnpacked(type, node) {
|
4500
4501
|
if (!type.isVariadicUnpacked) {
|
4501
|
-
addError(localize_1.
|
4502
|
+
addError(localize_1.LocMessage.unpackedTypeVarTupleExpected().format({
|
4502
4503
|
name1: type.details.name,
|
4503
4504
|
name2: type.details.name,
|
4504
4505
|
}), node);
|
@@ -4545,14 +4546,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4545
4546
|
minTypeArgCount = firstDefaultParamIndex;
|
4546
4547
|
}
|
4547
4548
|
if (typeArgs.length > typeParameters.length) {
|
4548
|
-
addError(localize_1.
|
4549
|
+
addError(localize_1.LocMessage.typeArgsTooMany().format({
|
4549
4550
|
name: printType(baseType),
|
4550
4551
|
expected: typeParameters.length,
|
4551
4552
|
received: typeArgs.length,
|
4552
4553
|
}), typeArgs[typeParameters.length].node);
|
4553
4554
|
}
|
4554
4555
|
else if (typeArgs.length < minTypeArgCount) {
|
4555
|
-
addError(localize_1.
|
4556
|
+
addError(localize_1.LocMessage.typeArgsTooFew().format({
|
4556
4557
|
name: printType(baseType),
|
4557
4558
|
expected: typeParameters.length,
|
4558
4559
|
received: typeArgs.length,
|
@@ -4623,12 +4624,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4623
4624
|
(0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, param, functionType, diag, typeVarContext);
|
4624
4625
|
}
|
4625
4626
|
else {
|
4626
|
-
addError(localize_1.
|
4627
|
+
addError(localize_1.LocMessage.typeArgListExpected(), typeArgs[index].node);
|
4627
4628
|
}
|
4628
4629
|
}
|
4629
4630
|
else {
|
4630
4631
|
if (index < typeArgs.length && typeArgs[index].typeList) {
|
4631
|
-
addError(localize_1.
|
4632
|
+
addError(localize_1.LocMessage.typeArgListNotAllowed(), typeArgs[index].node);
|
4632
4633
|
}
|
4633
4634
|
let typeArgType;
|
4634
4635
|
if (index < typeArgs.length) {
|
@@ -4646,7 +4647,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4646
4647
|
const usageVariance = usageVariances[index];
|
4647
4648
|
if (!(0, typeUtils_1.isVarianceOfTypeArgumentCompatible)(typeArgType, usageVariance)) {
|
4648
4649
|
const messageDiag = diag.createAddendum();
|
4649
|
-
messageDiag.addMessage(localize_1.
|
4650
|
+
messageDiag.addMessage(localize_1.LocAddendum.varianceMismatchForTypeAlias().format({
|
4650
4651
|
typeVarName: printType(typeArgType),
|
4651
4652
|
typeAliasParam: printType(typeParameters[index]),
|
4652
4653
|
}));
|
@@ -4656,7 +4657,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4656
4657
|
}
|
4657
4658
|
if ((0, types_1.isUnpacked)(typeArgType) && !(0, types_1.isVariadicTypeVar)(param)) {
|
4658
4659
|
const messageDiag = diag.createAddendum();
|
4659
|
-
messageDiag.addMessage(localize_1.
|
4660
|
+
messageDiag.addMessage(localize_1.LocMessage.unpackedArgInTypeArgument());
|
4660
4661
|
messageDiag.addTextRange(typeArgs[index].node);
|
4661
4662
|
typeArgType = types_1.UnknownType.create();
|
4662
4663
|
}
|
@@ -4664,7 +4665,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4664
4665
|
}
|
4665
4666
|
});
|
4666
4667
|
if (!diag.isEmpty()) {
|
4667
|
-
addError(localize_1.
|
4668
|
+
addError(localize_1.LocMessage.typeNotSpecializable().format({ type: printType(baseType) }) + diag.getString(), node, (_b = diag.getEffectiveTextRange()) !== null && _b !== void 0 ? _b : node);
|
4668
4669
|
}
|
4669
4670
|
const primarySignatureContext = typeVarContext.getPrimarySignature();
|
4670
4671
|
const aliasTypeArgs = [];
|
@@ -4714,7 +4715,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4714
4715
|
}
|
4715
4716
|
if (flags & 128 /* EvaluatorFlags.ExpectingInstantiableType */) {
|
4716
4717
|
if ((0, types_1.isTypeVar)(unexpandedSubtype)) {
|
4717
|
-
addDiagnostic(
|
4718
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarNotSubscriptable().format({
|
4718
4719
|
type: printType(unexpandedSubtype),
|
4719
4720
|
}), node.baseExpression);
|
4720
4721
|
// Evaluate the index expressions as though they are type arguments for error-reporting.
|
@@ -4731,7 +4732,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4731
4732
|
const itemMethodType = getBoundMagicMethod(concreteSubtype, getIndexAccessMagicMethodName(usage));
|
4732
4733
|
if ((flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0) {
|
4733
4734
|
// If the class doesn't derive from Generic, a type argument should not be allowed.
|
4734
|
-
addDiagnostic(
|
4735
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeArgsExpectingNone().format({
|
4735
4736
|
name: printType(types_1.ClassType.cloneAsInstance(concreteSubtype)),
|
4736
4737
|
}), node);
|
4737
4738
|
}
|
@@ -4742,10 +4743,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4742
4743
|
// Setting the value of an indexed class will always result
|
4743
4744
|
// in an exception.
|
4744
4745
|
if (usage.method === 'set') {
|
4745
|
-
addDiagnostic(
|
4746
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.genericClassAssigned(), node.baseExpression);
|
4746
4747
|
}
|
4747
4748
|
else if (usage.method === 'del') {
|
4748
|
-
addDiagnostic(
|
4749
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.genericClassDeleted(), node.baseExpression);
|
4749
4750
|
}
|
4750
4751
|
if (types_1.ClassType.isSpecialBuiltIn(concreteSubtype, 'Literal')) {
|
4751
4752
|
// Special-case Literal types.
|
@@ -4758,7 +4759,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4758
4759
|
return typeArgs[0].type;
|
4759
4760
|
}
|
4760
4761
|
else {
|
4761
|
-
addError(localize_1.
|
4762
|
+
addError(localize_1.LocMessage.typeArgsMismatchOne().format({ received: typeArgs.length }), node.baseExpression);
|
4762
4763
|
return types_1.UnknownType.create();
|
4763
4764
|
}
|
4764
4765
|
}
|
@@ -4799,7 +4800,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4799
4800
|
return concreteSubtype;
|
4800
4801
|
}
|
4801
4802
|
if (concreteSubtype.typeArguments) {
|
4802
|
-
addDiagnostic(
|
4803
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.classAlreadySpecialized().format({
|
4803
4804
|
type: printType((0, typeUtils_1.convertToInstance)(concreteSubtype), { expandTypeAlias: true }),
|
4804
4805
|
}), node.baseExpression);
|
4805
4806
|
return concreteSubtype;
|
@@ -4818,7 +4819,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4818
4819
|
}
|
4819
4820
|
if ((0, typeUtils_1.isNoneInstance)(concreteSubtype)) {
|
4820
4821
|
if (!isIncomplete) {
|
4821
|
-
addDiagnostic(
|
4822
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportOptionalSubscript, localize_1.LocMessage.noneNotSubscriptable(), node.baseExpression);
|
4822
4823
|
}
|
4823
4824
|
return types_1.UnknownType.create();
|
4824
4825
|
}
|
@@ -4836,8 +4837,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4836
4837
|
return types_1.UnknownType.create();
|
4837
4838
|
}
|
4838
4839
|
if (!isIncomplete) {
|
4839
|
-
|
4840
|
-
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeNotSubscriptable().format({ type: printType(concreteSubtype) }), node.baseExpression);
|
4840
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeNotSubscriptable().format({ type: printType(concreteSubtype) }), node.baseExpression);
|
4841
4841
|
}
|
4842
4842
|
return types_1.UnknownType.create();
|
4843
4843
|
});
|
@@ -4968,8 +4968,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4968
4968
|
const magicMethodName = getIndexAccessMagicMethodName(usage);
|
4969
4969
|
const itemMethodType = getBoundMagicMethod(baseType, magicMethodName, selfType);
|
4970
4970
|
if (!itemMethodType) {
|
4971
|
-
|
4972
|
-
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.methodNotDefinedOnType().format({
|
4971
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.methodNotDefinedOnType().format({
|
4973
4972
|
name: magicMethodName,
|
4974
4973
|
type: printType(baseType),
|
4975
4974
|
}), node.baseExpression);
|
@@ -5257,13 +5256,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5257
5256
|
typeResult.type = types_1.ClassType.cloneForUnpacked(typeResult.type);
|
5258
5257
|
}
|
5259
5258
|
else {
|
5260
|
-
addError(localize_1.
|
5259
|
+
addError(localize_1.LocMessage.unpackNotAllowed(), arg.valueExpression);
|
5261
5260
|
}
|
5262
5261
|
}
|
5263
5262
|
}
|
5264
5263
|
}
|
5265
5264
|
if (arg.name) {
|
5266
|
-
addError(localize_1.
|
5265
|
+
addError(localize_1.LocMessage.keywordArgInTypeArgument(), arg.valueExpression);
|
5267
5266
|
}
|
5268
5267
|
typeArgs.push(typeResult);
|
5269
5268
|
});
|
@@ -5305,12 +5304,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5305
5304
|
else {
|
5306
5305
|
typeResult = { ...getTypeOfExpression(node, adjustedFlags), node };
|
5307
5306
|
if (node.nodeType === 15 /* ParseNodeType.Dictionary */) {
|
5308
|
-
addError(localize_1.
|
5307
|
+
addError(localize_1.LocMessage.dictInAnnotation(), node);
|
5309
5308
|
}
|
5310
5309
|
if ((flags & 131072 /* EvaluatorFlags.DisallowClassVar */) !== 0) {
|
5311
5310
|
// "ClassVar" is not allowed as a type argument.
|
5312
5311
|
if ((0, types_1.isClass)(typeResult.type) && types_1.ClassType.isBuiltIn(typeResult.type, 'ClassVar')) {
|
5313
|
-
addError(localize_1.
|
5312
|
+
addError(localize_1.LocMessage.classVarNotAllowed(), node);
|
5314
5313
|
}
|
5315
5314
|
}
|
5316
5315
|
}
|
@@ -5324,8 +5323,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5324
5323
|
// to support Tuple[()], which is the documented way to annotate
|
5325
5324
|
// a zero-length tuple.
|
5326
5325
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
5327
|
-
diag.addMessage(localize_1.
|
5328
|
-
addDiagnostic(
|
5326
|
+
diag.addMessage(localize_1.LocAddendum.useTupleInstead());
|
5327
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.tupleInAnnotation() + diag.getString(), node);
|
5329
5328
|
return { type: types_1.UnknownType.create() };
|
5330
5329
|
}
|
5331
5330
|
if ((flags & 128 /* EvaluatorFlags.ExpectingInstantiableType */) !== 0 &&
|
@@ -5493,8 +5492,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5493
5492
|
node.leftExpression.nodeType === 38 /* ParseNodeType.Name */ &&
|
5494
5493
|
node.leftExpression.value === 'type') {
|
5495
5494
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
5496
|
-
diag.addMessage(localize_1.
|
5497
|
-
addDiagnostic(
|
5495
|
+
diag.addMessage(localize_1.LocAddendum.useTypeInstead());
|
5496
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeCallNotAllowed() + diag.getString(), node);
|
5498
5497
|
}
|
5499
5498
|
// Handle immediate calls of lambdas specially.
|
5500
5499
|
if (node.leftExpression.nodeType === 30 /* ParseNodeType.Lambda */) {
|
@@ -5546,7 +5545,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5546
5545
|
typeResult.type = getTypeOfRevealLocals(node);
|
5547
5546
|
}
|
5548
5547
|
else {
|
5549
|
-
addError(localize_1.
|
5548
|
+
addError(localize_1.LocMessage.revealLocalsArgs(), node);
|
5550
5549
|
}
|
5551
5550
|
}
|
5552
5551
|
else {
|
@@ -5594,7 +5593,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5594
5593
|
}
|
5595
5594
|
}
|
5596
5595
|
if ((flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0) {
|
5597
|
-
addDiagnostic(
|
5596
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAnnotationCall(), node);
|
5598
5597
|
typeResult = { type: types_1.UnknownType.create() };
|
5599
5598
|
}
|
5600
5599
|
return typeResult;
|
@@ -5652,7 +5651,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5652
5651
|
node.arguments[0].name !== undefined ||
|
5653
5652
|
node.arguments[0].argumentCategory !== 0 /* ArgumentCategory.Simple */ ||
|
5654
5653
|
node.arguments[1].name !== undefined) {
|
5655
|
-
addError(localize_1.
|
5654
|
+
addError(localize_1.LocMessage.assertTypeArgs(), node);
|
5656
5655
|
return { type: types_1.UnknownType.create() };
|
5657
5656
|
}
|
5658
5657
|
const arg0TypeResult = getTypeOfExpression(node.arguments[0].valueExpression,
|
@@ -5663,7 +5662,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5663
5662
|
const assertedType = (0, typeUtils_1.convertToInstance)(getTypeOfArgumentExpectingType(node.arguments[1]).type);
|
5664
5663
|
if (!(0, types_1.isTypeSame)(assertedType, arg0TypeResult.type, { treatAnySameAsUnknown: true, ignorePseudoGeneric: true })) {
|
5665
5664
|
const srcDestTypes = printSrcDestTypes(arg0TypeResult.type, assertedType, { expandTypeAlias: true });
|
5666
|
-
addDiagnostic(
|
5665
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.assertTypeTypeMismatch().format({
|
5667
5666
|
expected: srcDestTypes.destType,
|
5668
5667
|
received: srcDestTypes.sourceType,
|
5669
5668
|
}), node.arguments[0].valueExpression);
|
@@ -5692,7 +5691,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5692
5691
|
if (!(0, types_1.isClassInstance)(expectedTextType) ||
|
5693
5692
|
!types_1.ClassType.isBuiltIn(expectedTextType, 'str') ||
|
5694
5693
|
typeof expectedTextType.literalValue !== 'string') {
|
5695
|
-
addError(localize_1.
|
5694
|
+
addError(localize_1.LocMessage.revealTypeExpectedTextArg(), arg.valueExpression);
|
5696
5695
|
}
|
5697
5696
|
else {
|
5698
5697
|
expectedText = expectedTextType.literalValue;
|
@@ -5704,7 +5703,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5704
5703
|
}
|
5705
5704
|
});
|
5706
5705
|
if (!arg0Value) {
|
5707
|
-
addError(localize_1.
|
5706
|
+
addError(localize_1.LocMessage.revealTypeArgs(), node);
|
5708
5707
|
return { type: types_1.UnknownType.create() };
|
5709
5708
|
}
|
5710
5709
|
const typeResult = getTypeOfExpression(arg0Value, /* flags */ undefined, inferenceContext);
|
@@ -5713,7 +5712,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5713
5712
|
const typeString = printType(type, { expandTypeAlias: true });
|
5714
5713
|
if (expectedText !== undefined) {
|
5715
5714
|
if (expectedText !== typeString) {
|
5716
|
-
addError(localize_1.
|
5715
|
+
addError(localize_1.LocMessage.revealTypeExpectedTextMismatch().format({
|
5717
5716
|
expected: expectedText,
|
5718
5717
|
received: typeString,
|
5719
5718
|
}), expectedTextNode !== null && expectedTextNode !== void 0 ? expectedTextNode : arg0Value);
|
@@ -5722,13 +5721,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5722
5721
|
if (expectedRevealType) {
|
5723
5722
|
if (!(0, types_1.isTypeSame)(expectedRevealType, type, { ignorePseudoGeneric: true })) {
|
5724
5723
|
const expectedRevealTypeText = printType(expectedRevealType);
|
5725
|
-
addError(localize_1.
|
5724
|
+
addError(localize_1.LocMessage.revealTypeExpectedTypeMismatch().format({
|
5726
5725
|
expected: expectedRevealTypeText,
|
5727
5726
|
received: typeString,
|
5728
5727
|
}), expectedRevealTypeNode !== null && expectedRevealTypeNode !== void 0 ? expectedRevealTypeNode : arg0Value);
|
5729
5728
|
}
|
5730
5729
|
}
|
5731
|
-
addInformation(localize_1.
|
5730
|
+
addInformation(localize_1.LocAddendum.typeOfSymbol().format({ name: exprString, type: typeString }), node.arguments[0]);
|
5732
5731
|
return { type, isIncomplete: typeResult.isIncomplete };
|
5733
5732
|
}
|
5734
5733
|
function getTypeOfRevealLocals(node) {
|
@@ -5748,7 +5747,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5748
5747
|
scope.symbolTable.forEach((symbol, name) => {
|
5749
5748
|
if (!symbol.isIgnoredForProtocolMatch()) {
|
5750
5749
|
const typeOfSymbol = getEffectiveTypeOfSymbol(symbol);
|
5751
|
-
infoMessages.push(localize_1.
|
5750
|
+
infoMessages.push(localize_1.LocAddendum.typeOfSymbol().format({
|
5752
5751
|
name,
|
5753
5752
|
type: printType(typeOfSymbol, { expandTypeAlias: true }),
|
5754
5753
|
}));
|
@@ -5759,14 +5758,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5759
5758
|
addInformation(infoMessages.join('\n'), node);
|
5760
5759
|
}
|
5761
5760
|
else {
|
5762
|
-
addInformation(localize_1.
|
5761
|
+
addInformation(localize_1.LocMessage.revealLocalsNone(), node);
|
5763
5762
|
}
|
5764
5763
|
return getNoneType();
|
5765
5764
|
}
|
5766
5765
|
function getTypeOfSuperCall(node) {
|
5767
5766
|
var _a;
|
5768
5767
|
if (node.arguments.length > 2) {
|
5769
|
-
addError(localize_1.
|
5768
|
+
addError(localize_1.LocMessage.superCallArgCount(), node.arguments[2]);
|
5770
5769
|
}
|
5771
5770
|
const enclosingFunction = ParseTreeUtils.getEnclosingFunctionEvaluationScope(node);
|
5772
5771
|
const enclosingClass = enclosingFunction ? ParseTreeUtils.getEnclosingClass(enclosingFunction) : undefined;
|
@@ -5778,7 +5777,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5778
5777
|
targetClassType = getTypeOfExpression(node.arguments[0].valueExpression).type;
|
5779
5778
|
const concreteTargetClassType = makeTopLevelTypeVarsConcrete(targetClassType);
|
5780
5779
|
if (!(0, types_1.isAnyOrUnknown)(concreteTargetClassType) && !(0, types_1.isInstantiableClass)(concreteTargetClassType)) {
|
5781
|
-
addDiagnostic(
|
5780
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.superCallFirstArg().format({ type: printType(targetClassType) }), node.arguments[0].valueExpression);
|
5782
5781
|
}
|
5783
5782
|
}
|
5784
5783
|
else {
|
@@ -5790,13 +5789,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5790
5789
|
const functionInfo = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, enclosingFunction,
|
5791
5790
|
/* isInClass */ true);
|
5792
5791
|
if (((functionInfo === null || functionInfo === void 0 ? void 0 : functionInfo.flags) & 4 /* FunctionTypeFlags.StaticMethod */) !== 0) {
|
5793
|
-
addError(localize_1.
|
5792
|
+
addError(localize_1.LocMessage.superCallZeroArgFormStaticMethod(), node.leftExpression);
|
5794
5793
|
targetClassType = types_1.UnknownType.create();
|
5795
5794
|
}
|
5796
5795
|
}
|
5797
5796
|
}
|
5798
5797
|
else {
|
5799
|
-
addError(localize_1.
|
5798
|
+
addError(localize_1.LocMessage.superCallZeroArgForm(), node.leftExpression);
|
5800
5799
|
targetClassType = types_1.UnknownType.create();
|
5801
5800
|
}
|
5802
5801
|
}
|
@@ -5830,8 +5829,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5830
5829
|
reportError = true;
|
5831
5830
|
}
|
5832
5831
|
if (reportError) {
|
5833
|
-
|
5834
|
-
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.superCallSecondArg().format({ type: printType(targetClassType) }), node.arguments[1].valueExpression);
|
5832
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.superCallSecondArg().format({ type: printType(targetClassType) }), node.arguments[1].valueExpression);
|
5835
5833
|
return { type: types_1.UnknownType.create() };
|
5836
5834
|
}
|
5837
5835
|
}
|
@@ -6265,8 +6263,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6265
6263
|
}
|
6266
6264
|
return typeString;
|
6267
6265
|
});
|
6268
|
-
diagAddendum.addMessage(localize_1.
|
6269
|
-
addDiagnostic(
|
6266
|
+
diagAddendum.addMessage(localize_1.LocAddendum.argumentTypes().format({ types: argTypes.join(', ') }));
|
6267
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.noOverload().format({ name: functionName }) + diagAddendum.getString(), errorNode);
|
6270
6268
|
}
|
6271
6269
|
return { argumentErrors: true, isTypeIncomplete, overloadsUsedForCall: [] };
|
6272
6270
|
}
|
@@ -6286,10 +6284,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6286
6284
|
// was possible and emit a diagnostic that provides the most likely.
|
6287
6285
|
if (emitNoOverloadFoundError) {
|
6288
6286
|
const functionName = bestMatch.overload.details.name || '<anonymous function>';
|
6289
|
-
const diagnostic = addDiagnostic(
|
6287
|
+
const diagnostic = addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.noOverload().format({ name: functionName }), errorNode);
|
6290
6288
|
const overrideDecl = bestMatch.overload.details.declaration;
|
6291
6289
|
if (diagnostic && overrideDecl) {
|
6292
|
-
diagnostic.addRelatedInfo(localize_1.
|
6290
|
+
diagnostic.addRelatedInfo(localize_1.LocAddendum.overloadIndex().format({ index: bestMatch.overloadIndex + 1 }), overrideDecl.uri, overrideDecl.range);
|
6293
6291
|
}
|
6294
6292
|
}
|
6295
6293
|
const effectiveTypeVarContext = typeVarContext !== null && typeVarContext !== void 0 ? typeVarContext : new typeVarContext_1.TypeVarContext();
|
@@ -6417,7 +6415,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6417
6415
|
// Special forms are not callable.
|
6418
6416
|
if (callTypeResult.type.specialForm) {
|
6419
6417
|
const exprNode = errorNode.nodeType === 9 /* ParseNodeType.Call */ ? errorNode.leftExpression : errorNode;
|
6420
|
-
addDiagnostic(
|
6418
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.objectNotCallable().format({
|
6421
6419
|
type: printType(callTypeResult.type, { expandTypeAlias: true }),
|
6422
6420
|
}), exprNode);
|
6423
6421
|
return { returnType: types_1.UnknownType.create(), argumentErrors: true, overloadsUsedForCall };
|
@@ -6481,7 +6479,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6481
6479
|
}
|
6482
6480
|
case 6 /* TypeCategory.Class */: {
|
6483
6481
|
if ((0, typeUtils_1.isNoneInstance)(expandedCallType)) {
|
6484
|
-
addDiagnostic(
|
6482
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportOptionalCall, localize_1.LocMessage.noneNotCallable(), errorNode);
|
6485
6483
|
return { argumentErrors: true };
|
6486
6484
|
}
|
6487
6485
|
if (types_1.TypeBase.isInstantiable(expandedCallType)) {
|
@@ -6497,7 +6495,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6497
6495
|
return validateCallArguments(errorNode, argList, { type: (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(expandedCallType), isIncomplete: isCallTypeIncomplete }, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount);
|
6498
6496
|
}
|
6499
6497
|
case 7 /* TypeCategory.Module */: {
|
6500
|
-
addDiagnostic(
|
6498
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.moduleNotCallable(), errorNode);
|
6501
6499
|
return { argumentErrors: true };
|
6502
6500
|
}
|
6503
6501
|
}
|
@@ -6506,7 +6504,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6506
6504
|
function validateCallForFunction(errorNode, argList, expandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext) {
|
6507
6505
|
var _a;
|
6508
6506
|
if (types_1.TypeBase.isInstantiable(expandedCallType)) {
|
6509
|
-
addDiagnostic(
|
6507
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.callableNotInstantiable().format({
|
6510
6508
|
type: printType(expandedCallType),
|
6511
6509
|
}), errorNode);
|
6512
6510
|
return { returnType: undefined, argumentErrors: true };
|
@@ -6519,7 +6517,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6519
6517
|
// The stdlib collections/__init__.pyi stub file defines namedtuple
|
6520
6518
|
// as a function rather than a class, so we need to check for it here.
|
6521
6519
|
if (expandedCallType.details.builtInName === 'namedtuple') {
|
6522
|
-
addDiagnostic(
|
6520
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUntypedNamedTuple, localize_1.LocMessage.namedTupleNoTypes(), errorNode);
|
6523
6521
|
const result = {
|
6524
6522
|
returnType: (0, namedTuples_1.createNamedTupleType)(evaluatorInterface, errorNode, argList, /* includesTypes */ false),
|
6525
6523
|
};
|
@@ -6563,40 +6561,79 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6563
6561
|
specializedInitSelfType: functionResult.specializedInitSelfType,
|
6564
6562
|
};
|
6565
6563
|
}
|
6566
|
-
|
6564
|
+
// Determines whether a symbol is abstract. In an ABC class, this means a function
|
6565
|
+
// is specifically decorated with @abstractmethod. In a protocol class, the rules
|
6566
|
+
// are more complicated and depend on whether the method is defined in a stub file.
|
6567
|
+
function getAbstractSymbolInfo(classType, symbolName) {
|
6568
|
+
const isProtocolClass = types_1.ClassType.isProtocolClass(classType);
|
6569
|
+
const symbol = classType.details.fields.get(symbolName);
|
6570
|
+
if (!symbol) {
|
6571
|
+
return undefined;
|
6572
|
+
}
|
6573
|
+
// Ignore instance variables. Also, ignore named tuple members, which are
|
6574
|
+
// modeled in pyright as instance variables, but their runtime implementation
|
6575
|
+
// uses a descriptor object.
|
6576
|
+
if (!symbol.isClassMember() && !symbol.isNamedTupleMemberMember()) {
|
6577
|
+
return undefined;
|
6578
|
+
}
|
6579
|
+
const lastDecl = (0, symbolUtils_1.getLastTypedDeclaredForSymbol)(symbol);
|
6580
|
+
if (!lastDecl) {
|
6581
|
+
return undefined;
|
6582
|
+
}
|
6583
|
+
// Handle protocol variables specially.
|
6584
|
+
if (isProtocolClass && lastDecl.type === 1 /* DeclarationType.Variable */) {
|
6585
|
+
// If none of the declarations involve assignments, assume it's
|
6586
|
+
// not implemented in the protocol.
|
6587
|
+
const allDecls = symbol.getDeclarations();
|
6588
|
+
if (!allDecls.some((decl) => decl.type === 1 /* DeclarationType.Variable */ && !!decl.inferredTypeSource)) {
|
6589
|
+
return { symbol, symbolName, classType, hasImplementation: false };
|
6590
|
+
}
|
6591
|
+
}
|
6592
|
+
if (lastDecl.type !== 5 /* DeclarationType.Function */) {
|
6593
|
+
return undefined;
|
6594
|
+
}
|
6567
6595
|
let isAbstract = false;
|
6568
|
-
|
6569
|
-
|
6570
|
-
// abstract.
|
6571
|
-
if (types_1.FunctionType.isAbstractMethod(functionType)) {
|
6596
|
+
const lastFunctionInfo = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, lastDecl.node, /* isInClass */ true);
|
6597
|
+
if ((lastFunctionInfo.flags & 8 /* FunctionTypeFlags.AbstractMethod */) !== 0) {
|
6572
6598
|
isAbstract = true;
|
6573
6599
|
}
|
6574
|
-
|
6575
|
-
|
6576
|
-
|
6577
|
-
|
6578
|
-
|
6600
|
+
const isStubFile = AnalyzerNodeInfo.getFileInfo(lastDecl.node).isStubFile;
|
6601
|
+
// In an overloaded method, the first overload can also be marked abstract.
|
6602
|
+
// In stub files, there is no implementation, so this is the only way to mark
|
6603
|
+
// an overloaded method as abstract.
|
6604
|
+
const firstDecl = symbol.getDeclarations()[0];
|
6605
|
+
let firstFunctionInfo;
|
6606
|
+
if (firstDecl !== lastDecl && firstDecl.type === 5 /* DeclarationType.Function */) {
|
6607
|
+
firstFunctionInfo = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, firstDecl.node, /* isInClass */ true);
|
6608
|
+
if ((firstFunctionInfo.flags & 8 /* FunctionTypeFlags.AbstractMethod */) !== 0) {
|
6609
|
+
isAbstract = true;
|
6610
|
+
}
|
6611
|
+
// If there's no implementation, assume it's unimplemented.
|
6612
|
+
if (isProtocolClass && (lastFunctionInfo.flags & 256 /* FunctionTypeFlags.Overloaded */) !== 0) {
|
6613
|
+
// If this is a protocol class method defined in a stub file and
|
6614
|
+
// it's not marked abstract, assume it's not abstract and implemented.
|
6615
|
+
if (isProtocolClass && !isAbstract && isStubFile) {
|
6616
|
+
return undefined;
|
6617
|
+
}
|
6618
|
+
return { symbol, symbolName, classType, hasImplementation: false };
|
6619
|
+
}
|
6579
6620
|
}
|
6580
|
-
if
|
6581
|
-
|
6621
|
+
// In a non-protocol class, if the method isn't explicitly marked abstract,
|
6622
|
+
// then it's not abstract.
|
6623
|
+
if (!isProtocolClass && !isAbstract) {
|
6624
|
+
return undefined;
|
6582
6625
|
}
|
6583
|
-
|
6584
|
-
//
|
6585
|
-
|
6586
|
-
//
|
6587
|
-
|
6588
|
-
|
6589
|
-
|
6590
|
-
|
6591
|
-
return (functionType.details.declaration !== undefined &&
|
6592
|
-
!AnalyzerNodeInfo.getFileInfo(functionType.details.declaration.node).isStubFile);
|
6626
|
+
const hasImplementation = !ParseTreeUtils.isSuiteEmpty(lastDecl.node.suite) && !methodAlwaysRaisesNotImplemented(lastDecl);
|
6627
|
+
// If this is a protocol class, the method isn't explicitly marked
|
6628
|
+
// as abstract, and there is an implementation, then it's a default
|
6629
|
+
// implementation, and it's not considered abstract. If it's in a stub
|
6630
|
+
// file, assume it's implemented in this case.
|
6631
|
+
if (isProtocolClass && !isAbstract) {
|
6632
|
+
if (hasImplementation || isStubFile) {
|
6633
|
+
return undefined;
|
6593
6634
|
}
|
6594
6635
|
}
|
6595
|
-
|
6596
|
-
return false;
|
6597
|
-
}
|
6598
|
-
const decl = implementation.details.declaration;
|
6599
|
-
return ParseTreeUtils.isSuiteEmpty(decl.node.suite) || methodAlwaysRaisesNotImplemented(decl);
|
6636
|
+
return { symbol, symbolName, classType, hasImplementation };
|
6600
6637
|
}
|
6601
6638
|
function validateCallForOverloadedFunction(errorNode, argList, expandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext) {
|
6602
6639
|
var _a, _b;
|
@@ -6634,7 +6671,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6634
6671
|
function validateCallForInstantiableClass(errorNode, argList, expandedCallType, unexpandedCallType, skipUnknownArgCheck, inferenceContext) {
|
6635
6672
|
var _a, _b;
|
6636
6673
|
if (expandedCallType.literalValue !== undefined) {
|
6637
|
-
addDiagnostic(
|
6674
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.literalNotCallable(), errorNode);
|
6638
6675
|
return { returnType: types_1.UnknownType.create(), argumentErrors: true };
|
6639
6676
|
}
|
6640
6677
|
if (types_1.ClassType.isBuiltIn(expandedCallType)) {
|
@@ -6642,7 +6679,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6642
6679
|
// Handle a call to a metaclass explicitly.
|
6643
6680
|
if ((0, typeUtils_1.isInstantiableMetaclass)(expandedCallType)) {
|
6644
6681
|
if (expandedCallType.typeArguments && expandedCallType.isTypeArgumentExplicit) {
|
6645
|
-
addDiagnostic(
|
6682
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.objectNotCallable().format({
|
6646
6683
|
type: printType(expandedCallType),
|
6647
6684
|
}), errorNode);
|
6648
6685
|
return { returnType: types_1.UnknownType.create(), argumentErrors: true };
|
@@ -6702,8 +6739,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6702
6739
|
const result = {
|
6703
6740
|
returnType: (0, namedTuples_1.createNamedTupleType)(evaluatorInterface, errorNode, argList, /* includesTypes */ true),
|
6704
6741
|
};
|
6705
|
-
const initTypeResult = (0, constructors_1.getBoundInitMethod)(evaluatorInterface, errorNode, types_1.ClassType.cloneAsInstance(expandedCallType),
|
6706
|
-
/* skipObjectBase */ false);
|
6742
|
+
const initTypeResult = (0, constructors_1.getBoundInitMethod)(evaluatorInterface, errorNode, types_1.ClassType.cloneAsInstance(expandedCallType), 0 /* MemberAccessFlags.Default */);
|
6707
6743
|
if (initTypeResult && (0, types_1.isOverloadedFunction)(initTypeResult.type)) {
|
6708
6744
|
validateOverloadedFunctionArguments(errorNode, argList, { type: initTypeResult.type },
|
6709
6745
|
/* typeVarContext */ undefined, skipUnknownArgCheck,
|
@@ -6715,15 +6751,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6715
6751
|
return { returnType: createNewType(errorNode, argList) };
|
6716
6752
|
}
|
6717
6753
|
if (types_1.ClassType.isSpecialFormClass(expandedCallType)) {
|
6718
|
-
|
6719
|
-
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeNotIntantiable().format({ type: className }), errorNode);
|
6754
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeNotIntantiable().format({ type: className }), errorNode);
|
6720
6755
|
return { returnType: types_1.UnknownType.create(), argumentErrors: true };
|
6721
6756
|
}
|
6722
|
-
if ((0, types_1.isClass)(unexpandedCallType) && (0, enums_1.isKnownEnumType)(className)) {
|
6723
|
-
return {
|
6724
|
-
returnType: (_b = (0, enums_1.createEnumType)(evaluatorInterface, errorNode, expandedCallType, argList)) !== null && _b !== void 0 ? _b : types_1.UnknownType.create(),
|
6725
|
-
};
|
6726
|
-
}
|
6727
6757
|
if (className === 'TypedDict') {
|
6728
6758
|
return { returnType: (0, typedDicts_1.createTypedDictType)(evaluatorInterface, errorNode, expandedCallType, argList) };
|
6729
6759
|
}
|
@@ -6731,36 +6761,46 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6731
6761
|
return { returnType: (0, enums_1.getEnumAutoValueType)(evaluatorInterface, errorNode) };
|
6732
6762
|
}
|
6733
6763
|
}
|
6764
|
+
// Is it a call to an Enum class factory?
|
6765
|
+
if ((0, types_1.isClass)(expandedCallType) &&
|
6766
|
+
expandedCallType.details.effectiveMetaclass &&
|
6767
|
+
(0, types_1.isClass)(expandedCallType.details.effectiveMetaclass) &&
|
6768
|
+
(0, enums_1.isEnumMetaclass)(expandedCallType.details.effectiveMetaclass) &&
|
6769
|
+
!(0, enums_1.isEnumClassWithMembers)(evaluatorInterface, expandedCallType)) {
|
6770
|
+
return {
|
6771
|
+
returnType: (_b = (0, enums_1.createEnumType)(evaluatorInterface, errorNode, expandedCallType, argList)) !== null && _b !== void 0 ? _b : (0, typeUtils_1.convertToInstance)(unexpandedCallType),
|
6772
|
+
};
|
6773
|
+
}
|
6734
6774
|
if (types_1.ClassType.supportsAbstractMethods(expandedCallType)) {
|
6735
|
-
const
|
6736
|
-
if (
|
6775
|
+
const abstractSymbols = getAbstractSymbols(expandedCallType);
|
6776
|
+
if (abstractSymbols.length > 0 && !expandedCallType.includeSubclasses && !(0, types_1.isTypeVar)(unexpandedCallType)) {
|
6737
6777
|
// If the class is abstract, it can't be instantiated.
|
6738
6778
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
6739
6779
|
const errorsToDisplay = 2;
|
6740
|
-
|
6780
|
+
abstractSymbols.forEach((abstractMethod, index) => {
|
6741
6781
|
if (index === errorsToDisplay) {
|
6742
|
-
diagAddendum.addMessage(localize_1.
|
6743
|
-
count:
|
6782
|
+
diagAddendum.addMessage(localize_1.LocAddendum.memberIsAbstractMore().format({
|
6783
|
+
count: abstractSymbols.length - errorsToDisplay,
|
6744
6784
|
}));
|
6745
6785
|
}
|
6746
6786
|
else if (index < errorsToDisplay) {
|
6747
6787
|
if ((0, types_1.isInstantiableClass)(abstractMethod.classType)) {
|
6748
6788
|
const className = abstractMethod.classType.details.name;
|
6749
|
-
diagAddendum.addMessage(localize_1.
|
6789
|
+
diagAddendum.addMessage(localize_1.LocAddendum.memberIsAbstract().format({
|
6750
6790
|
type: className,
|
6751
6791
|
name: abstractMethod.symbolName,
|
6752
6792
|
}));
|
6753
6793
|
}
|
6754
6794
|
}
|
6755
6795
|
});
|
6756
|
-
addDiagnostic(
|
6796
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.instantiateAbstract().format({
|
6757
6797
|
type: expandedCallType.details.name,
|
6758
6798
|
}) + diagAddendum.getString(), errorNode);
|
6759
6799
|
}
|
6760
6800
|
}
|
6761
6801
|
if (types_1.ClassType.isProtocolClass(expandedCallType) && !expandedCallType.includeSubclasses) {
|
6762
6802
|
// If the class is a protocol, it can't be instantiated.
|
6763
|
-
addDiagnostic(
|
6803
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.instantiateProtocol().format({
|
6764
6804
|
type: expandedCallType.details.name,
|
6765
6805
|
}), errorNode);
|
6766
6806
|
}
|
@@ -6808,7 +6848,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6808
6848
|
/* selfType */ undefined, recursionCount);
|
6809
6849
|
const callMethodType = callMethodResult === null || callMethodResult === void 0 ? void 0 : callMethodResult.type;
|
6810
6850
|
if (!callMethodType) {
|
6811
|
-
addDiagnostic(
|
6851
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.objectNotCallable().format({
|
6812
6852
|
type: printType(expandedCallType),
|
6813
6853
|
}), errorNode);
|
6814
6854
|
return { returnType: types_1.UnknownType.create(), argumentErrors: true };
|
@@ -6838,7 +6878,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6838
6878
|
if ((0, types_1.isTypeSame)((0, typeUtils_1.convertToInstance)(castToType), castFromType, {
|
6839
6879
|
ignorePseudoGeneric: true,
|
6840
6880
|
})) {
|
6841
|
-
addDiagnostic(
|
6881
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnnecessaryCast, localize_1.LocMessage.unnecessaryCast().format({
|
6842
6882
|
type: printType(castFromType),
|
6843
6883
|
}), errorNode);
|
6844
6884
|
}
|
@@ -7009,8 +7049,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7009
7049
|
if (argIndex < positionalOnlyLimitIndex && argList[argIndex].name) {
|
7010
7050
|
const nameNode = argList[argIndex].name;
|
7011
7051
|
if (nameNode) {
|
7012
|
-
|
7013
|
-
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.argPositional(), nameNode);
|
7052
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.argPositional(), nameNode);
|
7014
7053
|
reportedArgError = true;
|
7015
7054
|
}
|
7016
7055
|
}
|
@@ -7044,9 +7083,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7044
7083
|
}
|
7045
7084
|
if (tooManyPositionals) {
|
7046
7085
|
if (!isDiagnosticSuppressedForNode(errorNode) && !isTypeIncomplete) {
|
7047
|
-
addDiagnostic(
|
7048
|
-
? localize_1.
|
7049
|
-
: localize_1.
|
7086
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, positionParamLimitIndex === 1
|
7087
|
+
? localize_1.LocMessage.argPositionalExpectedOne()
|
7088
|
+
: localize_1.LocMessage.argPositionalExpectedCount().format({
|
7050
7089
|
expected: positionParamLimitIndex,
|
7051
7090
|
}), (_b = argList[argIndex].valueExpression) !== null && _b !== void 0 ? _b : errorNode);
|
7052
7091
|
}
|
@@ -7077,9 +7116,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7077
7116
|
argTypeResult.type.paramSpecAccess === 'args' &&
|
7078
7117
|
paramDetails.params[paramIndex].param.category !== 1 /* ParameterCategory.ArgsList */) {
|
7079
7118
|
if (!isDiagnosticSuppressedForNode(errorNode) && !isTypeIncomplete) {
|
7080
|
-
addDiagnostic(
|
7081
|
-
? localize_1.
|
7082
|
-
: localize_1.
|
7119
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, positionParamLimitIndex === 1
|
7120
|
+
? localize_1.LocMessage.argPositionalExpectedOne()
|
7121
|
+
: localize_1.LocMessage.argPositionalExpectedCount().format({
|
7083
7122
|
expected: positionParamLimitIndex,
|
7084
7123
|
}), (_c = argList[argIndex].valueExpression) !== null && _c !== void 0 ? _c : errorNode);
|
7085
7124
|
}
|
@@ -7144,7 +7183,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7144
7183
|
// parameter unless the argument is a variadic arg as well.
|
7145
7184
|
if (isParamVariadic && !isArgCompatibleWithVariadic) {
|
7146
7185
|
if (!isDiagnosticSuppressedForNode(errorNode) && !isTypeIncomplete) {
|
7147
|
-
addDiagnostic(
|
7186
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.unpackedArgWithVariadicParam(), argList[argIndex].valueExpression || errorNode);
|
7148
7187
|
}
|
7149
7188
|
reportedArgError = true;
|
7150
7189
|
}
|
@@ -7202,9 +7241,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7202
7241
|
if (remainingArgCount < remainingParamCount) {
|
7203
7242
|
if (!isDiagnosticSuppressedForNode(errorNode) && !isTypeIncomplete) {
|
7204
7243
|
// Have we run out of arguments and still have parameters left to fill?
|
7205
|
-
addDiagnostic(
|
7206
|
-
? localize_1.
|
7207
|
-
: localize_1.
|
7244
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, remainingArgCount === 1
|
7245
|
+
? localize_1.LocMessage.argMorePositionalExpectedOne()
|
7246
|
+
: localize_1.LocMessage.argMorePositionalExpectedCount().format({
|
7208
7247
|
expected: remainingArgCount,
|
7209
7248
|
}), argList[argIndex].valueExpression || errorNode);
|
7210
7249
|
}
|
@@ -7284,9 +7323,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7284
7323
|
}
|
7285
7324
|
if (argsRemainingCount > 0) {
|
7286
7325
|
if (!isDiagnosticSuppressedForNode(errorNode) && !isTypeIncomplete) {
|
7287
|
-
addDiagnostic(
|
7288
|
-
? localize_1.
|
7289
|
-
: localize_1.
|
7326
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, argsRemainingCount === 1
|
7327
|
+
? localize_1.LocMessage.argMorePositionalExpectedOne()
|
7328
|
+
: localize_1.LocMessage.argMorePositionalExpectedCount().format({
|
7290
7329
|
expected: argsRemainingCount,
|
7291
7330
|
}), argList.length > positionalArgCount
|
7292
7331
|
? argList[positionalArgCount].valueExpression || errorNode
|
@@ -7314,7 +7353,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7314
7353
|
const paramEntry = paramMap.get(name);
|
7315
7354
|
if (paramEntry && !paramEntry.isPositionalOnly) {
|
7316
7355
|
if (paramEntry.argsReceived > 0) {
|
7317
|
-
diag.addMessage(localize_1.
|
7356
|
+
diag.addMessage(localize_1.LocMessage.paramAlreadyAssigned().format({ name }));
|
7318
7357
|
}
|
7319
7358
|
else {
|
7320
7359
|
paramEntry.argsReceived++;
|
@@ -7360,13 +7399,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7360
7399
|
// getParameterListDetails because it was associated with an unpacked TypedDict.
|
7361
7400
|
// In this case, we can skip the error.
|
7362
7401
|
if (!paramDetails.hasUnpackedTypedDict) {
|
7363
|
-
diag.addMessage(localize_1.
|
7402
|
+
diag.addMessage(localize_1.LocMessage.paramNameMissing().format({ name }));
|
7364
7403
|
}
|
7365
7404
|
}
|
7366
7405
|
});
|
7367
7406
|
if (!diag.isEmpty()) {
|
7368
7407
|
if (!isDiagnosticSuppressedForNode(errorNode) && !isTypeIncomplete) {
|
7369
|
-
addDiagnostic(
|
7408
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.unpackedTypedDictArgument() + diag.getString(), argList[argIndex].valueExpression || errorNode);
|
7370
7409
|
}
|
7371
7410
|
reportedArgError = true;
|
7372
7411
|
}
|
@@ -7427,8 +7466,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7427
7466
|
}
|
7428
7467
|
if (!isValidMappingType) {
|
7429
7468
|
if (!isDiagnosticSuppressedForNode(errorNode) && !isTypeIncomplete) {
|
7430
|
-
addDiagnostic(
|
7431
|
-
.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.unpackedDictArgumentNotMapping(), argList[argIndex].valueExpression || errorNode);
|
7469
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.unpackedDictArgumentNotMapping(), argList[argIndex].valueExpression || errorNode);
|
7432
7470
|
}
|
7433
7471
|
reportedArgError = true;
|
7434
7472
|
}
|
@@ -7449,8 +7487,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7449
7487
|
if (paramEntry && !paramEntry.isPositionalOnly) {
|
7450
7488
|
if (paramEntry.argsReceived > 0) {
|
7451
7489
|
if (!isDiagnosticSuppressedForNode(errorNode) && !isTypeIncomplete) {
|
7452
|
-
addDiagnostic(
|
7453
|
-
.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.paramAlreadyAssigned().format({ name: paramNameValue }), paramName);
|
7490
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.paramAlreadyAssigned().format({ name: paramNameValue }), paramName);
|
7454
7491
|
}
|
7455
7492
|
reportedArgError = true;
|
7456
7493
|
}
|
@@ -7494,7 +7531,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7494
7531
|
}
|
7495
7532
|
else {
|
7496
7533
|
if (!isDiagnosticSuppressedForNode(errorNode) && !isTypeIncomplete) {
|
7497
|
-
addDiagnostic(
|
7534
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.paramNameMissing().format({ name: paramName.value }), paramName);
|
7498
7535
|
}
|
7499
7536
|
reportedArgError = true;
|
7500
7537
|
}
|
@@ -7505,9 +7542,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7505
7542
|
}
|
7506
7543
|
else {
|
7507
7544
|
if (!isDiagnosticSuppressedForNode(errorNode) && !isTypeIncomplete) {
|
7508
|
-
addDiagnostic(
|
7509
|
-
? localize_1.
|
7510
|
-
: localize_1.
|
7545
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, positionParamLimitIndex === 1
|
7546
|
+
? localize_1.LocMessage.argPositionalExpectedOne()
|
7547
|
+
: localize_1.LocMessage.argPositionalExpectedCount().format({
|
7511
7548
|
expected: positionParamLimitIndex,
|
7512
7549
|
}), argList[argIndex].valueExpression || errorNode);
|
7513
7550
|
}
|
@@ -7582,9 +7619,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7582
7619
|
if (!isDiagnosticSuppressedForNode(errorNode)) {
|
7583
7620
|
const missingParamNames = unassignedParams.map((p) => `"${p}"`).join(', ');
|
7584
7621
|
if (!isDiagnosticSuppressedForNode(errorNode) && !isTypeIncomplete) {
|
7585
|
-
addDiagnostic(
|
7586
|
-
? localize_1.
|
7587
|
-
: localize_1.
|
7622
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, unassignedParams.length === 1
|
7623
|
+
? localize_1.LocMessage.argMissingForParam().format({ name: missingParamNames })
|
7624
|
+
: localize_1.LocMessage.argMissingForParams().format({ names: missingParamNames }), errorNode);
|
7588
7625
|
}
|
7589
7626
|
}
|
7590
7627
|
reportedArgError = true;
|
@@ -7652,8 +7689,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7652
7689
|
argParam.argument.argumentCategory !== 1 /* ArgumentCategory.UnpackedList */ &&
|
7653
7690
|
!argParam.mapsToVarArgList) {
|
7654
7691
|
if (!isDiagnosticSuppressedForNode(errorNode) && !isTypeIncomplete) {
|
7655
|
-
addDiagnostic(
|
7656
|
-
.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeVarTupleMustBeUnpacked(), (_a = argParam.argument.valueExpression) !== null && _a !== void 0 ? _a : errorNode);
|
7692
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarTupleMustBeUnpacked(), (_a = argParam.argument.valueExpression) !== null && _a !== void 0 ? _a : errorNode);
|
7657
7693
|
}
|
7658
7694
|
reportedArgError = true;
|
7659
7695
|
}
|
@@ -7828,10 +7864,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7828
7864
|
let anyOrUnknownArgument;
|
7829
7865
|
const typeCondition = (0, typeUtils_1.getTypeCondition)(type);
|
7830
7866
|
// Check for an attempt to invoke an unimplemented abstract method.
|
7831
|
-
if (type.boundToType && !type.boundToType.includeSubclasses &&
|
7832
|
-
|
7833
|
-
|
7834
|
-
|
7867
|
+
if (type.boundToType && !type.boundToType.includeSubclasses && type.details.methodClass) {
|
7868
|
+
const abstractSymbolInfo = getAbstractSymbolInfo(type.details.methodClass, type.details.name);
|
7869
|
+
if (abstractSymbolInfo && !abstractSymbolInfo.hasImplementation) {
|
7870
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.abstractMethodInvocation().format({
|
7871
|
+
method: type.details.name,
|
7872
|
+
}), errorNode.nodeType === 9 /* ParseNodeType.Call */ ? errorNode.leftExpression : errorNode);
|
7873
|
+
}
|
7835
7874
|
}
|
7836
7875
|
if (type.boundTypeVarScopeId) {
|
7837
7876
|
// If the function was bound to a class or object and was a constructor, a
|
@@ -7982,7 +8021,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7982
8021
|
else if (type.details.paramSpec) {
|
7983
8022
|
if (!sawParamSpecArgs || !sawParamSpecKwargs) {
|
7984
8023
|
if (!isTypeIncomplete) {
|
7985
|
-
addDiagnostic(
|
8024
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.paramSpecArgsMissing().format({ type: printType(type.details.paramSpec) }), errorNode);
|
7986
8025
|
}
|
7987
8026
|
argumentErrors = true;
|
7988
8027
|
argumentMatchScore += 1;
|
@@ -8252,7 +8291,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8252
8291
|
argumentErrors = true;
|
8253
8292
|
}
|
8254
8293
|
if (argumentErrors) {
|
8255
|
-
addDiagnostic(
|
8294
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.paramSpecArgsMissing().format({
|
8256
8295
|
type: printType(functionType.details.paramSpec),
|
8257
8296
|
}), argErrorNode !== null && argErrorNode !== void 0 ? argErrorNode : errorNode);
|
8258
8297
|
}
|
@@ -8448,13 +8487,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8448
8487
|
if (fileInfo.diagnosticRuleSet.reportGeneralTypeIssues !== 'none' &&
|
8449
8488
|
!isDiagnosticSuppressedForNode(argParam.errorNode) &&
|
8450
8489
|
!isTypeIncomplete) {
|
8451
|
-
const fileInfo = AnalyzerNodeInfo.getFileInfo(argParam.errorNode);
|
8452
8490
|
const argTypeText = printType(argType);
|
8453
8491
|
const paramTypeText = printType(argParam.paramType);
|
8454
8492
|
let message;
|
8455
8493
|
if (argParam.paramName && !argParam.isParamNameSynthesized) {
|
8456
8494
|
if (functionName) {
|
8457
|
-
message = localize_1.
|
8495
|
+
message = localize_1.LocMessage.argAssignmentParamFunction().format({
|
8458
8496
|
argType: argTypeText,
|
8459
8497
|
paramType: paramTypeText,
|
8460
8498
|
functionName,
|
@@ -8462,7 +8500,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8462
8500
|
});
|
8463
8501
|
}
|
8464
8502
|
else {
|
8465
|
-
message = localize_1.
|
8503
|
+
message = localize_1.LocMessage.argAssignmentParam().format({
|
8466
8504
|
argType: argTypeText,
|
8467
8505
|
paramType: paramTypeText,
|
8468
8506
|
paramName: argParam.paramName,
|
@@ -8471,14 +8509,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8471
8509
|
}
|
8472
8510
|
else {
|
8473
8511
|
if (functionName) {
|
8474
|
-
message = localize_1.
|
8512
|
+
message = localize_1.LocMessage.argAssignmentFunction().format({
|
8475
8513
|
argType: argTypeText,
|
8476
8514
|
paramType: paramTypeText,
|
8477
8515
|
functionName,
|
8478
8516
|
});
|
8479
8517
|
}
|
8480
8518
|
else {
|
8481
|
-
message = localize_1.
|
8519
|
+
message = localize_1.LocMessage.argAssignment().format({
|
8482
8520
|
argType: argTypeText,
|
8483
8521
|
paramType: paramTypeText,
|
8484
8522
|
});
|
@@ -8490,7 +8528,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8490
8528
|
if (expectedTypeDiag) {
|
8491
8529
|
diag = expectedTypeDiag;
|
8492
8530
|
}
|
8493
|
-
addDiagnostic(
|
8531
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, message + diag.getString(), argParam.errorNode, (_a = diag.getEffectiveTextRange()) !== null && _a !== void 0 ? _a : argParam.errorNode);
|
8494
8532
|
}
|
8495
8533
|
return { isCompatible: false, argType, isTypeIncomplete, skippedBareTypeVarExpectedType, condition };
|
8496
8534
|
}
|
@@ -8501,11 +8539,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8501
8539
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
8502
8540
|
if (argParam.paramName) {
|
8503
8541
|
diagAddendum.addMessage((functionName
|
8504
|
-
? localize_1.
|
8542
|
+
? localize_1.LocAddendum.argParamFunction().format({
|
8505
8543
|
paramName: argParam.paramName,
|
8506
8544
|
functionName,
|
8507
8545
|
})
|
8508
|
-
: localize_1.
|
8546
|
+
: localize_1.LocAddendum.argParam().format({ paramName: argParam.paramName })) +
|
8509
8547
|
diagAddendum.getString());
|
8510
8548
|
}
|
8511
8549
|
return diagAddendum;
|
@@ -8517,7 +8555,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8517
8555
|
!isTypeIncomplete) {
|
8518
8556
|
if ((0, types_1.isUnknown)(simplifiedType)) {
|
8519
8557
|
const diagAddendum = getDiagAddendum();
|
8520
|
-
addDiagnostic(
|
8558
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownArgumentType, localize_1.LocMessage.argTypeUnknown() + diagAddendum.getString(), argParam.errorNode);
|
8521
8559
|
}
|
8522
8560
|
else if ((0, typeUtils_1.isPartlyUnknown)(simplifiedType)) {
|
8523
8561
|
// If the parameter type is also partially unknown, don't report
|
@@ -8525,10 +8563,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8525
8563
|
// arose due to bidirectional type matching.
|
8526
8564
|
if (!(0, typeUtils_1.isPartlyUnknown)(argParam.paramType)) {
|
8527
8565
|
const diagAddendum = getDiagAddendum();
|
8528
|
-
diagAddendum.addMessage(localize_1.
|
8566
|
+
diagAddendum.addMessage(localize_1.LocAddendum.argumentType().format({
|
8529
8567
|
type: printType(simplifiedType, { expandTypeAlias: true }),
|
8530
8568
|
}));
|
8531
|
-
addDiagnostic(
|
8569
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownArgumentType, localize_1.LocMessage.argTypePartiallyUnknown() + diagAddendum.getString(), argParam.errorNode);
|
8532
8570
|
}
|
8533
8571
|
}
|
8534
8572
|
}
|
@@ -8541,7 +8579,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8541
8579
|
let firstConstraintArg;
|
8542
8580
|
let defaultValueNode;
|
8543
8581
|
if (argList.length === 0) {
|
8544
|
-
addError(localize_1.
|
8582
|
+
addError(localize_1.LocMessage.typeVarFirstArg(), errorNode);
|
8545
8583
|
return undefined;
|
8546
8584
|
}
|
8547
8585
|
const firstArg = argList[0];
|
@@ -8549,9 +8587,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8549
8587
|
typeVarName = firstArg.valueExpression.strings.map((s) => s.value).join('');
|
8550
8588
|
}
|
8551
8589
|
else {
|
8552
|
-
addError(localize_1.
|
8590
|
+
addError(localize_1.LocMessage.typeVarFirstArg(), firstArg.valueExpression || errorNode);
|
8553
8591
|
}
|
8554
|
-
const typeVar = types_1.TypeVarType.createInstantiable(typeVarName, /* isParamSpec */ false, classType);
|
8592
|
+
const typeVar = types_1.TypeBase.cloneAsSpecialForm(types_1.TypeVarType.createInstantiable(typeVarName, /* isParamSpec */ false), types_1.ClassType.cloneAsInstance(classType));
|
8555
8593
|
// Parse the remaining parameters.
|
8556
8594
|
const paramNameMap = new Map();
|
8557
8595
|
for (let i = 1; i < argList.length; i++) {
|
@@ -8559,18 +8597,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8559
8597
|
const paramName = paramNameNode ? paramNameNode.value : undefined;
|
8560
8598
|
if (paramName) {
|
8561
8599
|
if (paramNameMap.get(paramName)) {
|
8562
|
-
addError(localize_1.
|
8600
|
+
addError(localize_1.LocMessage.duplicateParam().format({ name: paramName }), argList[i].valueExpression || errorNode);
|
8563
8601
|
}
|
8564
8602
|
if (paramName === 'bound') {
|
8565
8603
|
if (typeVar.details.constraints.length > 0) {
|
8566
|
-
addError(localize_1.
|
8604
|
+
addError(localize_1.LocMessage.typeVarBoundAndConstrained(), argList[i].valueExpression || errorNode);
|
8567
8605
|
}
|
8568
8606
|
else {
|
8569
8607
|
const argType = (_b = (_a = argList[i].typeResult) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : getTypeOfExpressionExpectingType(argList[i].valueExpression, {
|
8570
8608
|
disallowProtocolAndTypedDict: true,
|
8571
8609
|
}).type;
|
8572
8610
|
if ((0, typeUtils_1.requiresSpecialization)(argType, { ignorePseudoGeneric: true, ignoreImplicitTypeArgs: true })) {
|
8573
|
-
addError(localize_1.
|
8611
|
+
addError(localize_1.LocMessage.typeVarBoundGeneric(), argList[i].valueExpression || errorNode);
|
8574
8612
|
}
|
8575
8613
|
typeVar.details.boundType = (0, typeUtils_1.convertToInstance)(argType);
|
8576
8614
|
}
|
@@ -8579,7 +8617,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8579
8617
|
if (argList[i].valueExpression && getBooleanValue(argList[i].valueExpression)) {
|
8580
8618
|
if (typeVar.details.declaredVariance === 4 /* Variance.Contravariant */ ||
|
8581
8619
|
typeVar.details.declaredVariance === 0 /* Variance.Auto */) {
|
8582
|
-
addError(localize_1.
|
8620
|
+
addError(localize_1.LocMessage.typeVarVariance(), argList[i].valueExpression);
|
8583
8621
|
}
|
8584
8622
|
else {
|
8585
8623
|
typeVar.details.declaredVariance = 3 /* Variance.Covariant */;
|
@@ -8590,7 +8628,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8590
8628
|
if (argList[i].valueExpression && getBooleanValue(argList[i].valueExpression)) {
|
8591
8629
|
if (typeVar.details.declaredVariance === 3 /* Variance.Covariant */ ||
|
8592
8630
|
typeVar.details.declaredVariance === 0 /* Variance.Auto */) {
|
8593
|
-
addError(localize_1.
|
8631
|
+
addError(localize_1.LocMessage.typeVarVariance(), argList[i].valueExpression);
|
8594
8632
|
}
|
8595
8633
|
else {
|
8596
8634
|
typeVar.details.declaredVariance = 4 /* Variance.Contravariant */;
|
@@ -8601,7 +8639,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8601
8639
|
if (argList[i].valueExpression && getBooleanValue(argList[i].valueExpression)) {
|
8602
8640
|
if (typeVar.details.declaredVariance === 3 /* Variance.Covariant */ ||
|
8603
8641
|
typeVar.details.declaredVariance === 4 /* Variance.Contravariant */) {
|
8604
|
-
addError(localize_1.
|
8642
|
+
addError(localize_1.LocMessage.typeVarVariance(), argList[i].valueExpression);
|
8605
8643
|
}
|
8606
8644
|
else {
|
8607
8645
|
typeVar.details.declaredVariance = 0 /* Variance.Auto */;
|
@@ -8618,22 +8656,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8618
8656
|
if (!fileInfo.isStubFile &&
|
8619
8657
|
fileInfo.executionEnvironment.pythonVersion < pythonVersion_1.PythonVersion.V3_13 &&
|
8620
8658
|
classType.details.moduleName !== 'typing_extensions') {
|
8621
|
-
addError(localize_1.
|
8659
|
+
addError(localize_1.LocMessage.typeVarDefaultIllegal(), defaultValueNode);
|
8622
8660
|
}
|
8623
8661
|
}
|
8624
8662
|
else {
|
8625
|
-
addError(localize_1.
|
8663
|
+
addError(localize_1.LocMessage.typeVarUnknownParam().format({ name: paramName }), ((_e = argList[i].node) === null || _e === void 0 ? void 0 : _e.name) || argList[i].valueExpression || errorNode);
|
8626
8664
|
}
|
8627
8665
|
paramNameMap.set(paramName, paramName);
|
8628
8666
|
}
|
8629
8667
|
else {
|
8630
8668
|
if (typeVar.details.boundType) {
|
8631
|
-
addError(localize_1.
|
8669
|
+
addError(localize_1.LocMessage.typeVarBoundAndConstrained(), argList[i].valueExpression || errorNode);
|
8632
8670
|
}
|
8633
8671
|
else {
|
8634
8672
|
const argType = (_g = (_f = argList[i].typeResult) === null || _f === void 0 ? void 0 : _f.type) !== null && _g !== void 0 ? _g : getTypeOfExpressionExpectingType(argList[i].valueExpression).type;
|
8635
8673
|
if ((0, typeUtils_1.requiresSpecialization)(argType, { ignorePseudoGeneric: true })) {
|
8636
|
-
addError(localize_1.
|
8674
|
+
addError(localize_1.LocMessage.typeVarConstraintGeneric(), argList[i].valueExpression || errorNode);
|
8637
8675
|
}
|
8638
8676
|
types_1.TypeVarType.addConstraint(typeVar, (0, typeUtils_1.convertToInstance)(argType));
|
8639
8677
|
if (firstConstraintArg === undefined) {
|
@@ -8643,7 +8681,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8643
8681
|
}
|
8644
8682
|
}
|
8645
8683
|
if (typeVar.details.constraints.length === 1 && firstConstraintArg) {
|
8646
|
-
addDiagnostic(
|
8684
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarSingleConstraint(), firstConstraintArg.valueExpression || errorNode);
|
8647
8685
|
}
|
8648
8686
|
// If a default is provided, make sure it is compatible with the bound
|
8649
8687
|
// or constraint.
|
@@ -8654,12 +8692,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8654
8692
|
}));
|
8655
8693
|
if (typeVar.details.boundType) {
|
8656
8694
|
if (!assignType(typeVar.details.boundType, concreteDefaultType)) {
|
8657
|
-
addDiagnostic(
|
8695
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarDefaultBoundMismatch(), defaultValueNode);
|
8658
8696
|
}
|
8659
8697
|
}
|
8660
8698
|
else if (typeVar.details.constraints.length > 0) {
|
8661
8699
|
if (!typeVar.details.constraints.some((constraint) => (0, types_1.isTypeSame)(constraint, concreteDefaultType))) {
|
8662
|
-
addDiagnostic(
|
8700
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarDefaultConstraintMismatch(), defaultValueNode);
|
8663
8701
|
}
|
8664
8702
|
}
|
8665
8703
|
}
|
@@ -8669,7 +8707,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8669
8707
|
var _a, _b;
|
8670
8708
|
let typeVarName = '';
|
8671
8709
|
if (argList.length === 0) {
|
8672
|
-
addError(localize_1.
|
8710
|
+
addError(localize_1.LocMessage.typeVarFirstArg(), errorNode);
|
8673
8711
|
return undefined;
|
8674
8712
|
}
|
8675
8713
|
const firstArg = argList[0];
|
@@ -8677,9 +8715,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8677
8715
|
typeVarName = firstArg.valueExpression.strings.map((s) => s.value).join('');
|
8678
8716
|
}
|
8679
8717
|
else {
|
8680
|
-
addError(localize_1.
|
8718
|
+
addError(localize_1.LocMessage.typeVarFirstArg(), firstArg.valueExpression || errorNode);
|
8681
8719
|
}
|
8682
|
-
const typeVar = types_1.TypeVarType.createInstantiable(typeVarName, /* isParamSpec */ false, classType);
|
8720
|
+
const typeVar = types_1.TypeBase.cloneAsSpecialForm(types_1.TypeVarType.createInstantiable(typeVarName, /* isParamSpec */ false), types_1.ClassType.cloneAsInstance(classType));
|
8683
8721
|
typeVar.details.isVariadic = true;
|
8684
8722
|
// Parse the remaining parameters.
|
8685
8723
|
for (let i = 1; i < argList.length; i++) {
|
@@ -8695,15 +8733,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8695
8733
|
if (!fileInfo.isStubFile &&
|
8696
8734
|
fileInfo.executionEnvironment.pythonVersion < pythonVersion_1.PythonVersion.V3_13 &&
|
8697
8735
|
classType.details.moduleName !== 'typing_extensions') {
|
8698
|
-
addError(localize_1.
|
8736
|
+
addError(localize_1.LocMessage.typeVarDefaultIllegal(), expr);
|
8699
8737
|
}
|
8700
8738
|
}
|
8701
8739
|
else {
|
8702
|
-
addError(localize_1.
|
8740
|
+
addError(localize_1.LocMessage.typeVarTupleUnknownParam().format({ name: ((_a = argList[i].name) === null || _a === void 0 ? void 0 : _a.value) || '?' }), ((_b = argList[i].node) === null || _b === void 0 ? void 0 : _b.name) || argList[i].valueExpression || errorNode);
|
8703
8741
|
}
|
8704
8742
|
}
|
8705
8743
|
else {
|
8706
|
-
addError(localize_1.
|
8744
|
+
addError(localize_1.LocMessage.typeVarTupleConstraints(), argList[i].valueExpression || errorNode);
|
8707
8745
|
}
|
8708
8746
|
}
|
8709
8747
|
return typeVar;
|
@@ -8716,14 +8754,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8716
8754
|
const isUnpackedTuple = (0, types_1.isClass)(argType) && (0, typeUtils_1.isTupleClass)(argType) && argType.isUnpacked;
|
8717
8755
|
const isUnpackedTypeVarTuple = (0, types_1.isUnpackedVariadicTypeVar)(argType);
|
8718
8756
|
if (!isUnpackedTuple && !isUnpackedTypeVarTuple) {
|
8719
|
-
addDiagnostic(
|
8757
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarTupleDefaultNotUnpacked(), node);
|
8720
8758
|
return undefined;
|
8721
8759
|
}
|
8722
8760
|
return (0, typeUtils_1.convertToInstance)(argType);
|
8723
8761
|
}
|
8724
8762
|
function createParamSpecType(errorNode, classType, argList) {
|
8725
8763
|
if (argList.length === 0) {
|
8726
|
-
addError(localize_1.
|
8764
|
+
addError(localize_1.LocMessage.paramSpecFirstArg(), errorNode);
|
8727
8765
|
return undefined;
|
8728
8766
|
}
|
8729
8767
|
const firstArg = argList[0];
|
@@ -8732,9 +8770,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8732
8770
|
paramSpecName = firstArg.valueExpression.strings.map((s) => s.value).join('');
|
8733
8771
|
}
|
8734
8772
|
else {
|
8735
|
-
addError(localize_1.
|
8773
|
+
addError(localize_1.LocMessage.paramSpecFirstArg(), firstArg.valueExpression || errorNode);
|
8736
8774
|
}
|
8737
|
-
const paramSpec = types_1.TypeVarType.createInstantiable(paramSpecName, /* isParamSpec */ true, classType);
|
8775
|
+
const paramSpec = types_1.TypeBase.cloneAsSpecialForm(types_1.TypeVarType.createInstantiable(paramSpecName, /* isParamSpec */ true), types_1.ClassType.cloneAsInstance(classType));
|
8738
8776
|
// Parse the remaining parameters.
|
8739
8777
|
for (let i = 1; i < argList.length; i++) {
|
8740
8778
|
const paramNameNode = argList[i].name;
|
@@ -8749,15 +8787,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8749
8787
|
if (!fileInfo.isStubFile &&
|
8750
8788
|
fileInfo.executionEnvironment.pythonVersion < pythonVersion_1.PythonVersion.V3_13 &&
|
8751
8789
|
classType.details.moduleName !== 'typing_extensions') {
|
8752
|
-
addError(localize_1.
|
8790
|
+
addError(localize_1.LocMessage.typeVarDefaultIllegal(), expr);
|
8753
8791
|
}
|
8754
8792
|
}
|
8755
8793
|
else {
|
8756
|
-
addError(localize_1.
|
8794
|
+
addError(localize_1.LocMessage.paramSpecUnknownParam().format({ name: paramName }), paramNameNode || argList[i].valueExpression || errorNode);
|
8757
8795
|
}
|
8758
8796
|
}
|
8759
8797
|
else {
|
8760
|
-
addError(localize_1.
|
8798
|
+
addError(localize_1.LocMessage.paramSpecUnknownArg(), argList[i].valueExpression || errorNode);
|
8761
8799
|
break;
|
8762
8800
|
}
|
8763
8801
|
}
|
@@ -8806,7 +8844,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8806
8844
|
return functionType;
|
8807
8845
|
}
|
8808
8846
|
}
|
8809
|
-
addDiagnostic(
|
8847
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.paramSpecDefaultNotTuple(), node);
|
8810
8848
|
return undefined;
|
8811
8849
|
}
|
8812
8850
|
// Handles a call to TypeAliasType(). This special form allows a caller to programmatically
|
@@ -8820,7 +8858,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8820
8858
|
if (errorNode.parent.nodeType !== 3 /* ParseNodeType.Assignment */ ||
|
8821
8859
|
errorNode.parent.rightExpression !== errorNode ||
|
8822
8860
|
errorNode.parent.leftExpression.nodeType !== 38 /* ParseNodeType.Name */) {
|
8823
|
-
addDiagnostic(
|
8861
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAliasTypeMustBeAssigned(), errorNode);
|
8824
8862
|
return undefined;
|
8825
8863
|
}
|
8826
8864
|
const nameNode = errorNode.parent.leftExpression;
|
@@ -8828,11 +8866,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8828
8866
|
if (firstArg.valueExpression && firstArg.valueExpression.nodeType === 48 /* ParseNodeType.StringList */) {
|
8829
8867
|
const typeAliasName = firstArg.valueExpression.strings.map((s) => s.value).join('');
|
8830
8868
|
if (typeAliasName !== nameNode.value) {
|
8831
|
-
addDiagnostic(
|
8869
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAliasTypeNameMismatch(), firstArg.valueExpression);
|
8832
8870
|
}
|
8833
8871
|
}
|
8834
8872
|
else {
|
8835
|
-
addDiagnostic(
|
8873
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAliasTypeNameArg(), firstArg.valueExpression || errorNode);
|
8836
8874
|
return undefined;
|
8837
8875
|
}
|
8838
8876
|
let valueExpr;
|
@@ -8866,7 +8904,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8866
8904
|
let typeParameters;
|
8867
8905
|
if (typeParamsExpr) {
|
8868
8906
|
if (typeParamsExpr.nodeType !== 52 /* ParseNodeType.Tuple */) {
|
8869
|
-
addError(localize_1.
|
8907
|
+
addError(localize_1.LocMessage.typeAliasTypeParamInvalid(), typeParamsExpr);
|
8870
8908
|
return undefined;
|
8871
8909
|
}
|
8872
8910
|
typeParameters = [];
|
@@ -8887,7 +8925,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8887
8925
|
}
|
8888
8926
|
});
|
8889
8927
|
if (!isTypeParamListValid) {
|
8890
|
-
addDiagnostic(
|
8928
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAliasTypeParamInvalid(), typeParamsExpr);
|
8891
8929
|
return undefined;
|
8892
8930
|
}
|
8893
8931
|
}
|
@@ -8904,7 +8942,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8904
8942
|
return true;
|
8905
8943
|
}
|
8906
8944
|
}
|
8907
|
-
addDiagnostic(
|
8945
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.expectedBoolLiteral(), node);
|
8908
8946
|
return false;
|
8909
8947
|
}
|
8910
8948
|
function getFunctionFullName(functionNode, moduleName, functionName) {
|
@@ -8928,7 +8966,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8928
8966
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
8929
8967
|
let className = '';
|
8930
8968
|
if (argList.length !== 2) {
|
8931
|
-
addDiagnostic(
|
8969
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.newTypeParamCount(), errorNode);
|
8932
8970
|
return undefined;
|
8933
8971
|
}
|
8934
8972
|
const nameArg = argList[0];
|
@@ -8938,13 +8976,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8938
8976
|
className = nameArg.valueExpression.strings.map((s) => s.value).join('');
|
8939
8977
|
}
|
8940
8978
|
if (!className) {
|
8941
|
-
addDiagnostic(
|
8979
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.newTypeBadName(), (_a = argList[0].node) !== null && _a !== void 0 ? _a : errorNode);
|
8942
8980
|
return undefined;
|
8943
8981
|
}
|
8944
8982
|
if (((_b = errorNode.parent) === null || _b === void 0 ? void 0 : _b.nodeType) === 3 /* ParseNodeType.Assignment */ &&
|
8945
8983
|
errorNode.parent.leftExpression.nodeType === 38 /* ParseNodeType.Name */ &&
|
8946
8984
|
errorNode.parent.leftExpression.value !== className) {
|
8947
|
-
addDiagnostic(
|
8985
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.newTypeNameMismatch(), errorNode.parent.leftExpression);
|
8948
8986
|
return undefined;
|
8949
8987
|
}
|
8950
8988
|
let baseClass = getTypeOfArgumentExpectingType(argList[1]).type;
|
@@ -8953,18 +8991,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8953
8991
|
if (objectType && (0, types_1.isClassInstance)(objectType)) {
|
8954
8992
|
baseClass = types_1.ClassType.cloneAsInstantiable(objectType);
|
8955
8993
|
}
|
8956
|
-
addDiagnostic(
|
8994
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.newTypeAnyOrUnknown(), (_c = argList[1].node) !== null && _c !== void 0 ? _c : errorNode);
|
8957
8995
|
isBaseClassAny = true;
|
8958
8996
|
}
|
8959
8997
|
if (!(0, types_1.isInstantiableClass)(baseClass)) {
|
8960
|
-
addDiagnostic(
|
8998
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.newTypeNotAClass(), argList[1].node || errorNode);
|
8961
8999
|
return undefined;
|
8962
9000
|
}
|
8963
9001
|
if (types_1.ClassType.isProtocolClass(baseClass) || types_1.ClassType.isTypedDictClass(baseClass)) {
|
8964
|
-
addDiagnostic(
|
9002
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.newTypeProtocolClass(), argList[1].node || errorNode);
|
8965
9003
|
}
|
8966
9004
|
else if (baseClass.literalValue !== undefined) {
|
8967
|
-
addDiagnostic(
|
9005
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.newTypeLiteral(), argList[1].node || errorNode);
|
8968
9006
|
}
|
8969
9007
|
let classFlags = baseClass.details.flags & ~(1 /* ClassTypeFlags.BuiltInClass */ | 2 /* ClassTypeFlags.SpecialBuiltIn */);
|
8970
9008
|
classFlags |= 4096 /* ClassTypeFlags.Final */ | 268435456 /* ClassTypeFlags.NewTypeClass */ | 536870912 /* ClassTypeFlags.ValidTypeAliasClass */;
|
@@ -9028,7 +9066,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9028
9066
|
}
|
9029
9067
|
});
|
9030
9068
|
if (!(0, typeUtils_1.computeMroLinearization)(classType)) {
|
9031
|
-
addError(localize_1.
|
9069
|
+
addError(localize_1.LocMessage.methodOrdering(), errorNode);
|
9032
9070
|
}
|
9033
9071
|
return classType;
|
9034
9072
|
}
|
@@ -9127,8 +9165,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9127
9165
|
if ((flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0 &&
|
9128
9166
|
((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) !== 1 /* ParseNodeType.Argument */) {
|
9129
9167
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
9130
|
-
diag.addMessage(localize_1.
|
9131
|
-
addDiagnostic(
|
9168
|
+
diag.addMessage(localize_1.LocAddendum.useDictInstead());
|
9169
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.dictInAnnotation() + diag.getString(), node);
|
9132
9170
|
}
|
9133
9171
|
// If the expected type is a union, analyze for each of the subtypes
|
9134
9172
|
// to find one that matches.
|
@@ -9413,8 +9451,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9413
9451
|
}
|
9414
9452
|
}
|
9415
9453
|
else {
|
9416
|
-
|
9417
|
-
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.dictUnpackIsNotMapping(), entryNode);
|
9454
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.dictUnpackIsNotMapping(), entryNode);
|
9418
9455
|
}
|
9419
9456
|
}
|
9420
9457
|
}
|
@@ -9451,8 +9488,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9451
9488
|
node.nodeType === 31 /* ParseNodeType.List */ &&
|
9452
9489
|
((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) !== 1 /* ParseNodeType.Argument */) {
|
9453
9490
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
9454
|
-
diag.addMessage(localize_1.
|
9455
|
-
addDiagnostic(
|
9491
|
+
diag.addMessage(localize_1.LocAddendum.useListInstead());
|
9492
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.listInAnnotation() + diag.getString(), node);
|
9456
9493
|
}
|
9457
9494
|
// If the expected type is a union, recursively call for each of the subtypes
|
9458
9495
|
// to find one that matches.
|
@@ -9627,13 +9664,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9627
9664
|
function verifySetEntryOrDictKeyIsHashable(entry, type, isDictKey) {
|
9628
9665
|
// Verify that the type is hashable.
|
9629
9666
|
if (!isTypeHashable(type)) {
|
9630
|
-
const fileInfo = AnalyzerNodeInfo.getFileInfo(entry);
|
9631
9667
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
9632
|
-
diag.addMessage(localize_1.
|
9633
|
-
const message = isDictKey
|
9634
|
-
|
9635
|
-
: localize_1.Localizer.Diagnostic.unhashableSetEntry();
|
9636
|
-
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, message + diag.getString(), entry);
|
9668
|
+
diag.addMessage(localize_1.LocAddendum.unhashableType().format({ type: printType(type) }));
|
9669
|
+
const message = isDictKey ? localize_1.LocMessage.unhashableDictKey() : localize_1.LocMessage.unhashableSetEntry();
|
9670
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, message + diag.getString(), entry);
|
9637
9671
|
}
|
9638
9672
|
}
|
9639
9673
|
function inferTypeArgFromExpectedEntryType(inferenceContext, entryTypes, isNarrowable) {
|
@@ -9882,6 +9916,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9882
9916
|
}
|
9883
9917
|
}, {
|
9884
9918
|
dependentType: expectedType,
|
9919
|
+
allowDiagnostics: !forceSpeculative && !isDiagnosticSuppressedForNode(node) && !(inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete),
|
9885
9920
|
});
|
9886
9921
|
// Mark the function type as no longer being evaluated.
|
9887
9922
|
functionType.details.flags &= ~131072 /* FunctionTypeFlags.PartiallyEvaluated */;
|
@@ -9895,13 +9930,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9895
9930
|
let isIncomplete = false;
|
9896
9931
|
let typeErrors = false;
|
9897
9932
|
// If any of the "for" clauses are marked async or any of the "if" clauses
|
9898
|
-
// or the
|
9899
|
-
//
|
9900
|
-
let isAsync = node.forIfNodes.some((comp) => {
|
9933
|
+
// or any clause other than the leftmost "for" contain an "await" operator,
|
9934
|
+
// it is treated as an async generator.
|
9935
|
+
let isAsync = node.forIfNodes.some((comp, index) => {
|
9901
9936
|
if (comp.nodeType === 33 /* ParseNodeType.ListComprehensionFor */ && comp.isAsync) {
|
9902
9937
|
return true;
|
9903
9938
|
}
|
9904
|
-
return ParseTreeUtils.containsAwaitNode(comp);
|
9939
|
+
return index > 0 && ParseTreeUtils.containsAwaitNode(comp);
|
9905
9940
|
});
|
9906
9941
|
let type = types_1.UnknownType.create();
|
9907
9942
|
if (ParseTreeUtils.containsAwaitNode(node.expression)) {
|
@@ -9934,7 +9969,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9934
9969
|
// to avoid confusion.
|
9935
9970
|
const simplifiedType = (0, types_1.removeUnbound)(type);
|
9936
9971
|
if ((0, types_1.isUnknown)(simplifiedType)) {
|
9937
|
-
addDiagnostic(
|
9972
|
+
addDiagnostic(rule, localize_1.LocMessage.typeUnknown().format({ name: nameValue }), errorNode);
|
9938
9973
|
}
|
9939
9974
|
else if ((0, typeUtils_1.isPartlyUnknown)(simplifiedType)) {
|
9940
9975
|
// If ignoreEmptyContainers is true, don't report the problem for
|
@@ -9942,11 +9977,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9942
9977
|
// only if the assigned value is used later.
|
9943
9978
|
if (!ignoreEmptyContainers || !(0, types_1.isClassInstance)(type) || !type.isEmptyContainer) {
|
9944
9979
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
9945
|
-
diagAddendum.addMessage(localize_1.
|
9980
|
+
diagAddendum.addMessage(localize_1.LocAddendum.typeOfSymbol().format({
|
9946
9981
|
name: nameValue,
|
9947
9982
|
type: printType(simplifiedType, { expandTypeAlias: true }),
|
9948
9983
|
}));
|
9949
|
-
addDiagnostic(
|
9984
|
+
addDiagnostic(rule, localize_1.LocMessage.typePartiallyUnknown().format({ name: nameValue }) + diagAddendum.getString(), errorNode);
|
9950
9985
|
}
|
9951
9986
|
}
|
9952
9987
|
}
|
@@ -10052,7 +10087,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10052
10087
|
function validateTypeArg(argResult, options) {
|
10053
10088
|
if (argResult.typeList) {
|
10054
10089
|
if (!(options === null || options === void 0 ? void 0 : options.allowTypeArgList)) {
|
10055
|
-
addError(localize_1.
|
10090
|
+
addError(localize_1.LocMessage.typeArgListNotAllowed(), argResult.node);
|
10056
10091
|
return false;
|
10057
10092
|
}
|
10058
10093
|
else {
|
@@ -10063,23 +10098,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10063
10098
|
}
|
10064
10099
|
if ((0, typeUtils_1.isEllipsisType)(argResult.type)) {
|
10065
10100
|
if (!(options === null || options === void 0 ? void 0 : options.allowTypeArgList)) {
|
10066
|
-
addError(localize_1.
|
10101
|
+
addError(localize_1.LocMessage.ellipsisContext(), argResult.node);
|
10067
10102
|
return false;
|
10068
10103
|
}
|
10069
10104
|
}
|
10070
10105
|
if ((0, types_1.isModule)(argResult.type)) {
|
10071
|
-
addError(localize_1.
|
10106
|
+
addError(localize_1.LocMessage.moduleAsType(), argResult.node);
|
10072
10107
|
return false;
|
10073
10108
|
}
|
10074
10109
|
if ((0, types_1.isParamSpec)(argResult.type)) {
|
10075
10110
|
if (!(options === null || options === void 0 ? void 0 : options.allowParamSpec)) {
|
10076
|
-
addError(localize_1.
|
10111
|
+
addError(localize_1.LocMessage.paramSpecContext(), argResult.node);
|
10077
10112
|
return false;
|
10078
10113
|
}
|
10079
10114
|
}
|
10080
10115
|
if ((0, types_1.isVariadicTypeVar)(argResult.type) && !argResult.type.isVariadicInUnion) {
|
10081
10116
|
if (!(options === null || options === void 0 ? void 0 : options.allowVariadicTypeVar)) {
|
10082
|
-
addError(localize_1.
|
10117
|
+
addError(localize_1.LocMessage.typeVarTupleContext(), argResult.node);
|
10083
10118
|
return false;
|
10084
10119
|
}
|
10085
10120
|
else {
|
@@ -10087,12 +10122,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10087
10122
|
}
|
10088
10123
|
}
|
10089
10124
|
if (!(options === null || options === void 0 ? void 0 : options.allowEmptyTuple) && argResult.isEmptyTupleShorthand) {
|
10090
|
-
addError(localize_1.
|
10125
|
+
addError(localize_1.LocMessage.zeroLengthTupleNotAllowed(), argResult.node);
|
10091
10126
|
return false;
|
10092
10127
|
}
|
10093
10128
|
if ((0, types_1.isUnpackedClass)(argResult.type)) {
|
10094
10129
|
if (!(options === null || options === void 0 ? void 0 : options.allowUnpackedTuples)) {
|
10095
|
-
addError(localize_1.
|
10130
|
+
addError(localize_1.LocMessage.unpackedArgInTypeArgument(), argResult.node);
|
10096
10131
|
return false;
|
10097
10132
|
}
|
10098
10133
|
}
|
@@ -10117,7 +10152,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10117
10152
|
// Make sure we have at most one unpacked variadic type variable.
|
10118
10153
|
if (sawUnpacked) {
|
10119
10154
|
if (!reportedUnpackedError) {
|
10120
|
-
addError(localize_1.
|
10155
|
+
addError(localize_1.LocMessage.variadicTypeArgsTooMany(), entry.node);
|
10121
10156
|
reportedUnpackedError = true;
|
10122
10157
|
}
|
10123
10158
|
}
|
@@ -10188,7 +10223,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10188
10223
|
}
|
10189
10224
|
}
|
10190
10225
|
else {
|
10191
|
-
addError(localize_1.
|
10226
|
+
addError(localize_1.LocMessage.callableFirstArg(), typeArgs[0].node);
|
10192
10227
|
}
|
10193
10228
|
}
|
10194
10229
|
if (typeArgs.length > 1) {
|
@@ -10199,12 +10234,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10199
10234
|
functionType.details.declaredReturnType = (0, typeUtils_1.convertToInstance)(typeArg1Type);
|
10200
10235
|
}
|
10201
10236
|
else {
|
10202
|
-
|
10203
|
-
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.callableSecondArg(), errorNode);
|
10237
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportMissingTypeArgument, localize_1.LocMessage.callableSecondArg(), errorNode);
|
10204
10238
|
functionType.details.declaredReturnType = types_1.UnknownType.create();
|
10205
10239
|
}
|
10206
10240
|
if (typeArgs.length > 2) {
|
10207
|
-
addError(localize_1.
|
10241
|
+
addError(localize_1.LocMessage.callableExtraArgs(), typeArgs[2].node);
|
10208
10242
|
}
|
10209
10243
|
}
|
10210
10244
|
else {
|
@@ -10220,13 +10254,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10220
10254
|
// depends on whether we're evaluating a type annotation or
|
10221
10255
|
// we're in some other context.
|
10222
10256
|
if ((flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0) {
|
10223
|
-
addError(localize_1.
|
10257
|
+
addError(localize_1.LocMessage.optionalExtraArgs(), errorNode);
|
10224
10258
|
return types_1.UnknownType.create();
|
10225
10259
|
}
|
10226
10260
|
return classType;
|
10227
10261
|
}
|
10228
10262
|
if (typeArgs.length > 1) {
|
10229
|
-
addError(localize_1.
|
10263
|
+
addError(localize_1.LocMessage.optionalExtraArgs(), errorNode);
|
10230
10264
|
return types_1.UnknownType.create();
|
10231
10265
|
}
|
10232
10266
|
let typeArg0Type = typeArgs[0].type;
|
@@ -10262,7 +10296,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10262
10296
|
// Creates a type that represents a Literal.
|
10263
10297
|
function createLiteralType(classType, node, flags) {
|
10264
10298
|
if (node.items.length === 0) {
|
10265
|
-
addError(localize_1.
|
10299
|
+
addError(localize_1.LocMessage.literalEmptyArgs(), node.baseExpression);
|
10266
10300
|
return types_1.UnknownType.create();
|
10267
10301
|
}
|
10268
10302
|
// As per the specification, we support None, int, bool, str, bytes literals
|
@@ -10272,11 +10306,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10272
10306
|
let type;
|
10273
10307
|
const itemExpr = item.valueExpression;
|
10274
10308
|
if (item.argumentCategory !== 0 /* ArgumentCategory.Simple */) {
|
10275
|
-
addError(localize_1.
|
10309
|
+
addError(localize_1.LocMessage.unpackedArgInTypeArgument(), itemExpr);
|
10276
10310
|
type = types_1.UnknownType.create();
|
10277
10311
|
}
|
10278
10312
|
else if (item.name) {
|
10279
|
-
addError(localize_1.
|
10313
|
+
addError(localize_1.LocMessage.keywordArgInTypeArgument(), itemExpr);
|
10280
10314
|
type = types_1.UnknownType.create();
|
10281
10315
|
}
|
10282
10316
|
else if (itemExpr.nodeType === 48 /* ParseNodeType.StringList */) {
|
@@ -10340,7 +10374,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10340
10374
|
}
|
10341
10375
|
}
|
10342
10376
|
if (!type) {
|
10343
|
-
addError(localize_1.
|
10377
|
+
addError(localize_1.LocMessage.literalUnsupportedType(), item);
|
10344
10378
|
type = types_1.UnknownType.create();
|
10345
10379
|
}
|
10346
10380
|
literalTypes.push(type);
|
@@ -10351,26 +10385,25 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10351
10385
|
function createClassVarType(classType, errorNode, typeArgs, flags) {
|
10352
10386
|
var _a;
|
10353
10387
|
if (flags & 131072 /* EvaluatorFlags.DisallowClassVar */) {
|
10354
|
-
addError(localize_1.
|
10388
|
+
addError(localize_1.LocMessage.classVarNotAllowed(), errorNode);
|
10355
10389
|
return types_1.AnyType.create();
|
10356
10390
|
}
|
10357
10391
|
if (!typeArgs) {
|
10358
10392
|
return classType;
|
10359
10393
|
}
|
10360
10394
|
else if (typeArgs.length === 0) {
|
10361
|
-
addError(localize_1.
|
10395
|
+
addError(localize_1.LocMessage.classVarFirstArgMissing(), errorNode);
|
10362
10396
|
return types_1.UnknownType.create();
|
10363
10397
|
}
|
10364
10398
|
else if (typeArgs.length > 1) {
|
10365
|
-
addError(localize_1.
|
10399
|
+
addError(localize_1.LocMessage.classVarTooManyArgs(), typeArgs[1].node);
|
10366
10400
|
return types_1.UnknownType.create();
|
10367
10401
|
}
|
10368
10402
|
const type = typeArgs[0].type;
|
10369
10403
|
// A ClassVar should not allow TypeVars or generic types parameterized
|
10370
10404
|
// by TypeVars.
|
10371
10405
|
if ((0, typeUtils_1.requiresSpecialization)(type, { ignorePseudoGeneric: true, ignoreSelf: true })) {
|
10372
|
-
|
10373
|
-
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.classVarWithTypeVar(), (_a = typeArgs[0].node) !== null && _a !== void 0 ? _a : errorNode);
|
10406
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.classVarWithTypeVar(), (_a = typeArgs[0].node) !== null && _a !== void 0 ? _a : errorNode);
|
10374
10407
|
}
|
10375
10408
|
return type;
|
10376
10409
|
}
|
@@ -10378,18 +10411,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10378
10411
|
// isn't a generic type and therefore doesn't have a typeParameter.
|
10379
10412
|
// We'll abuse our internal types a bit by specializing it with
|
10380
10413
|
// a type argument anyway.
|
10381
|
-
function createTypeGuardType(
|
10414
|
+
function createTypeGuardType(classType, errorNode, typeArgs, flags) {
|
10382
10415
|
// If no type arguments are provided, the resulting type
|
10383
10416
|
// depends on whether we're evaluating a type annotation or
|
10384
10417
|
// we're in some other context.
|
10385
10418
|
if (!typeArgs) {
|
10386
10419
|
if ((flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0) {
|
10387
|
-
addError(localize_1.
|
10420
|
+
addError(localize_1.LocMessage.typeGuardArgCount(), errorNode);
|
10388
10421
|
}
|
10389
10422
|
return classType;
|
10390
10423
|
}
|
10391
10424
|
else if (typeArgs.length !== 1) {
|
10392
|
-
addError(localize_1.
|
10425
|
+
addError(localize_1.LocMessage.typeGuardArgCount(), errorNode);
|
10393
10426
|
return types_1.UnknownType.create();
|
10394
10427
|
}
|
10395
10428
|
const convertedTypeArgs = typeArgs.map((typeArg) => {
|
@@ -10399,10 +10432,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10399
10432
|
}
|
10400
10433
|
function createSelfType(classType, errorNode, typeArgs, flags) {
|
10401
10434
|
var _a;
|
10402
|
-
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
10403
10435
|
// Self doesn't support any type arguments.
|
10404
10436
|
if (typeArgs) {
|
10405
|
-
addDiagnostic(
|
10437
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeArgsExpectingNone().format({
|
10406
10438
|
name: classType.details.name,
|
10407
10439
|
}), (_a = typeArgs[0].node) !== null && _a !== void 0 ? _a : errorNode);
|
10408
10440
|
}
|
@@ -10416,13 +10448,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10416
10448
|
const enclosingClassTypeResult = enclosingClass ? getTypeOfClass(enclosingClass) : undefined;
|
10417
10449
|
if (!enclosingClassTypeResult) {
|
10418
10450
|
if ((flags & (256 /* EvaluatorFlags.ExpectingTypeAnnotation */ | 128 /* EvaluatorFlags.ExpectingInstantiableType */)) !== 0) {
|
10419
|
-
addDiagnostic(
|
10451
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.selfTypeContext(), errorNode);
|
10420
10452
|
}
|
10421
10453
|
return types_1.UnknownType.create();
|
10422
10454
|
}
|
10423
10455
|
else if ((0, typeUtils_1.isInstantiableMetaclass)(enclosingClassTypeResult.classType)) {
|
10424
10456
|
// If `Self` appears within a metaclass, it is considered illegal.
|
10425
|
-
addDiagnostic(
|
10457
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.selfTypeMetaclass(), errorNode);
|
10426
10458
|
return types_1.UnknownType.create();
|
10427
10459
|
}
|
10428
10460
|
const enclosingFunction = ParseTreeUtils.getEnclosingFunction(errorNode);
|
@@ -10433,7 +10465,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10433
10465
|
if (!isInnerFunction) {
|
10434
10466
|
// Check for static methods.
|
10435
10467
|
if (functionInfo.flags & 4 /* FunctionTypeFlags.StaticMethod */) {
|
10436
|
-
addDiagnostic(
|
10468
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.selfTypeContext(), errorNode);
|
10437
10469
|
return types_1.UnknownType.create();
|
10438
10470
|
}
|
10439
10471
|
if (enclosingFunction.parameters.length > 0) {
|
@@ -10444,7 +10476,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10444
10476
|
associateTypeVarsWithScope: true,
|
10445
10477
|
});
|
10446
10478
|
if (!(0, types_1.isTypeVar)(annotationType) || !annotationType.details.isSynthesizedSelf) {
|
10447
|
-
addDiagnostic(
|
10479
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.selfTypeWithTypedSelfOrCls(), errorNode);
|
10448
10480
|
}
|
10449
10481
|
}
|
10450
10482
|
}
|
@@ -10461,10 +10493,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10461
10493
|
}
|
10462
10494
|
if (!typeArgs || typeArgs.length !== 1) {
|
10463
10495
|
addError(classType.details.name === 'ReadOnly'
|
10464
|
-
? localize_1.
|
10496
|
+
? localize_1.LocMessage.readOnlyArgCount()
|
10465
10497
|
: classType.details.name === 'Required'
|
10466
|
-
? localize_1.
|
10467
|
-
: localize_1.
|
10498
|
+
? localize_1.LocMessage.requiredArgCount()
|
10499
|
+
: localize_1.LocMessage.notRequiredArgCount(), errorNode);
|
10468
10500
|
return { type: classType };
|
10469
10501
|
}
|
10470
10502
|
const typeArgType = typeArgs[0].type;
|
@@ -10503,10 +10535,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10503
10535
|
}
|
10504
10536
|
if (!isUsageLegal) {
|
10505
10537
|
addError(classType.details.name === 'ReadOnly'
|
10506
|
-
? localize_1.
|
10538
|
+
? localize_1.LocMessage.readOnlyNotInTypedDict()
|
10507
10539
|
: classType.details.name === 'Required'
|
10508
|
-
? localize_1.
|
10509
|
-
: localize_1.
|
10540
|
+
? localize_1.LocMessage.requiredNotInTypedDict()
|
10541
|
+
: localize_1.LocMessage.notRequiredNotInTypedDict(), errorNode);
|
10510
10542
|
return { type: types_1.ClassType.cloneForSpecialization(classType, [(0, typeUtils_1.convertToInstance)(typeArgType)], !!typeArgs) };
|
10511
10543
|
}
|
10512
10544
|
return { type: typeArgType, isReadOnly, isRequired, isNotRequired };
|
@@ -10519,14 +10551,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10519
10551
|
return classType;
|
10520
10552
|
}
|
10521
10553
|
if (!typeArgs || typeArgs.length !== 1) {
|
10522
|
-
addError(localize_1.
|
10554
|
+
addError(localize_1.LocMessage.unpackArgCount(), errorNode);
|
10523
10555
|
return types_1.UnknownType.create();
|
10524
10556
|
}
|
10525
10557
|
let typeArgType = typeArgs[0].type;
|
10526
10558
|
if ((0, types_1.isUnion)(typeArgType) && typeArgType.subtypes.length === 1) {
|
10527
10559
|
typeArgType = typeArgType.subtypes[0];
|
10528
10560
|
}
|
10529
|
-
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
10530
10561
|
if ((flags & 2097152 /* EvaluatorFlags.AllowUnpackedTupleOrTypeVarTuple */) !== 0) {
|
10531
10562
|
if ((0, types_1.isInstantiableClass)(typeArgType) && !typeArgType.includeSubclasses && (0, typeUtils_1.isTupleClass)(typeArgType)) {
|
10532
10563
|
return types_1.ClassType.cloneForUnpacked(typeArgType);
|
@@ -10534,75 +10565,75 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10534
10565
|
if ((0, types_1.isVariadicTypeVar)(typeArgType) && !typeArgType.isVariadicUnpacked) {
|
10535
10566
|
return types_1.TypeVarType.cloneForUnpacked(typeArgType);
|
10536
10567
|
}
|
10537
|
-
addDiagnostic(
|
10568
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.unpackExpectedTypeVarTuple(), errorNode);
|
10538
10569
|
return types_1.UnknownType.create();
|
10539
10570
|
}
|
10540
10571
|
if ((flags & 8388608 /* EvaluatorFlags.AllowUnpackedTypedDict */) !== 0) {
|
10541
10572
|
if ((0, types_1.isInstantiableClass)(typeArgType) && types_1.ClassType.isTypedDictClass(typeArgType)) {
|
10542
10573
|
return types_1.ClassType.cloneForUnpacked(typeArgType);
|
10543
10574
|
}
|
10544
|
-
addDiagnostic(
|
10575
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.unpackExpectedTypedDict(), errorNode);
|
10545
10576
|
return types_1.UnknownType.create();
|
10546
10577
|
}
|
10547
|
-
addDiagnostic(
|
10578
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.unpackNotAllowed(), errorNode);
|
10548
10579
|
return types_1.UnknownType.create();
|
10549
10580
|
}
|
10550
10581
|
// Creates a "Final" type.
|
10551
10582
|
function createFinalType(classType, errorNode, typeArgs, flags) {
|
10552
10583
|
if (flags & 16 /* EvaluatorFlags.DisallowFinal */) {
|
10553
|
-
addError(localize_1.
|
10584
|
+
addError(localize_1.LocMessage.finalContext(), errorNode);
|
10554
10585
|
return types_1.AnyType.create();
|
10555
10586
|
}
|
10556
10587
|
if (!typeArgs || typeArgs.length === 0) {
|
10557
10588
|
return classType;
|
10558
10589
|
}
|
10559
10590
|
if (typeArgs.length > 1) {
|
10560
|
-
addError(localize_1.
|
10591
|
+
addError(localize_1.LocMessage.finalTooManyArgs(), errorNode);
|
10561
10592
|
}
|
10562
10593
|
return typeArgs[0].type;
|
10563
10594
|
}
|
10564
|
-
function createConcatenateType(
|
10595
|
+
function createConcatenateType(classType, errorNode, typeArgs, flags) {
|
10565
10596
|
if ((flags & 134217728 /* EvaluatorFlags.AllowConcatenate */) === 0) {
|
10566
|
-
addError(localize_1.
|
10597
|
+
addError(localize_1.LocMessage.concatenateContext(), errorNode);
|
10567
10598
|
return types_1.AnyType.create();
|
10568
10599
|
}
|
10569
10600
|
if (!typeArgs || typeArgs.length === 0) {
|
10570
|
-
addError(localize_1.
|
10601
|
+
addError(localize_1.LocMessage.concatenateTypeArgsMissing(), errorNode);
|
10571
10602
|
}
|
10572
10603
|
else {
|
10573
10604
|
typeArgs.forEach((typeArg, index) => {
|
10574
10605
|
if (index === typeArgs.length - 1) {
|
10575
10606
|
if (!(0, types_1.isParamSpec)(typeArg.type) && !(0, typeUtils_1.isEllipsisType)(typeArg.type)) {
|
10576
|
-
addError(localize_1.
|
10607
|
+
addError(localize_1.LocMessage.concatenateParamSpecMissing(), typeArg.node);
|
10577
10608
|
}
|
10578
10609
|
}
|
10579
10610
|
else {
|
10580
10611
|
if ((0, types_1.isParamSpec)(typeArg.type)) {
|
10581
|
-
addError(localize_1.
|
10612
|
+
addError(localize_1.LocMessage.paramSpecContext(), typeArg.node);
|
10582
10613
|
}
|
10583
10614
|
else if ((0, types_1.isUnpackedVariadicTypeVar)(typeArg.type)) {
|
10584
|
-
addError(localize_1.
|
10615
|
+
addError(localize_1.LocMessage.typeVarTupleContext(), typeArg.node);
|
10585
10616
|
}
|
10586
10617
|
else if ((0, types_1.isUnpackedClass)(typeArg.type)) {
|
10587
|
-
addError(localize_1.
|
10618
|
+
addError(localize_1.LocMessage.unpackedArgInTypeArgument(), typeArg.node);
|
10588
10619
|
}
|
10589
10620
|
}
|
10590
10621
|
});
|
10591
10622
|
}
|
10592
10623
|
return createSpecialType(classType, typeArgs, /* paramLimit */ undefined, /* allowParamSpec */ true);
|
10593
10624
|
}
|
10594
|
-
function createAnnotatedType(errorNode, typeArgs) {
|
10625
|
+
function createAnnotatedType(classType, errorNode, typeArgs) {
|
10595
10626
|
if (typeArgs && typeArgs.length < 2) {
|
10596
|
-
addError(localize_1.
|
10627
|
+
addError(localize_1.LocMessage.annotatedTypeArgMissing(), errorNode);
|
10597
10628
|
}
|
10598
10629
|
if (!typeArgs || typeArgs.length === 0) {
|
10599
10630
|
return { type: types_1.AnyType.create() };
|
10600
10631
|
}
|
10601
10632
|
if (typeArgs[0].typeList) {
|
10602
|
-
addError(localize_1.
|
10633
|
+
addError(localize_1.LocMessage.typeArgListNotAllowed(), typeArgs[0].node);
|
10603
10634
|
}
|
10604
10635
|
return {
|
10605
|
-
type: types_1.TypeBase.
|
10636
|
+
type: types_1.TypeBase.cloneAsSpecialForm(typeArgs[0].type, classType),
|
10606
10637
|
isReadOnly: typeArgs[0].isReadOnly,
|
10607
10638
|
isRequired: typeArgs[0].isRequired,
|
10608
10639
|
isNotRequired: typeArgs[0].isNotRequired,
|
@@ -10622,7 +10653,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10622
10653
|
const noteSawUnpacked = (typeArg) => {
|
10623
10654
|
if (sawUnpacked) {
|
10624
10655
|
if (!reportedUnpackedError) {
|
10625
|
-
addError(localize_1.
|
10656
|
+
addError(localize_1.LocMessage.variadicTypeArgsTooMany(), typeArg.node);
|
10626
10657
|
reportedUnpackedError = true;
|
10627
10658
|
}
|
10628
10659
|
}
|
@@ -10635,17 +10666,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10635
10666
|
if ((0, typeUtils_1.isEllipsisType)(typeArg.type)) {
|
10636
10667
|
if (!isTupleTypeParam) {
|
10637
10668
|
if (!allowParamSpec) {
|
10638
|
-
addError(localize_1.
|
10669
|
+
addError(localize_1.LocMessage.ellipsisContext(), typeArg.node);
|
10639
10670
|
}
|
10640
10671
|
}
|
10641
10672
|
else if (typeArgs.length !== 2 || index !== 1) {
|
10642
|
-
addError(localize_1.
|
10673
|
+
addError(localize_1.LocMessage.ellipsisSecondArg(), typeArg.node);
|
10643
10674
|
}
|
10644
10675
|
else {
|
10645
10676
|
if ((0, types_1.isTypeVar)(typeArgs[0].type) &&
|
10646
10677
|
(0, types_1.isVariadicTypeVar)(typeArgs[0].type) &&
|
10647
10678
|
!typeArgs[0].type.isVariadicInUnion) {
|
10648
|
-
addError(localize_1.
|
10679
|
+
addError(localize_1.LocMessage.typeVarTupleContext(), typeArgs[0].node);
|
10680
|
+
}
|
10681
|
+
else if (sawUnpacked) {
|
10682
|
+
addError(localize_1.LocMessage.ellipsisAfterUnpacked(), typeArg.node);
|
10649
10683
|
}
|
10650
10684
|
}
|
10651
10685
|
}
|
@@ -10653,7 +10687,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10653
10687
|
// Nothing to do - this is allowed.
|
10654
10688
|
}
|
10655
10689
|
else if ((0, types_1.isVariadicTypeVar)(typeArg.type) && paramLimit === undefined) {
|
10656
|
-
|
10690
|
+
if (!typeArg.type.isVariadicInUnion) {
|
10691
|
+
noteSawUnpacked(typeArg);
|
10692
|
+
}
|
10657
10693
|
validateVariadicTypeVarIsUnpacked(typeArg.type, typeArg.node);
|
10658
10694
|
}
|
10659
10695
|
else if (paramLimit === undefined && (0, types_1.isUnpacked)(typeArg.type)) {
|
@@ -10670,7 +10706,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10670
10706
|
// Make sure the argument list count is correct.
|
10671
10707
|
if (paramLimit !== undefined) {
|
10672
10708
|
if (typeArgs && typeArgTypes.length > paramLimit) {
|
10673
|
-
addError(localize_1.
|
10709
|
+
addError(localize_1.LocMessage.typeArgsTooMany().format({
|
10674
10710
|
name: classType.aliasName || classType.details.name,
|
10675
10711
|
expected: paramLimit,
|
10676
10712
|
received: typeArgTypes.length,
|
@@ -10698,9 +10734,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10698
10734
|
if (tupleTypeArgTypes.length === 1 && !tupleTypeArgTypes[0].isUnbounded) {
|
10699
10735
|
tupleTypeArgTypes[0] = { type: tupleTypeArgTypes[0].type, isUnbounded: true };
|
10700
10736
|
}
|
10701
|
-
else {
|
10702
|
-
addError(localize_1.Localizer.Diagnostic.ellipsisSecondArg(), typeArg.node);
|
10703
|
-
}
|
10704
10737
|
}
|
10705
10738
|
else if ((0, types_1.isUnpackedClass)(typeArg.type) && typeArg.type.tupleTypeArguments) {
|
10706
10739
|
(0, collectionUtils_1.appendArray)(tupleTypeArgTypes, typeArg.type.tupleTypeArguments);
|
@@ -10730,7 +10763,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10730
10763
|
// depends on whether we're evaluating a type annotation or
|
10731
10764
|
// we're in some other context.
|
10732
10765
|
if ((flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0) {
|
10733
|
-
addError(localize_1.
|
10766
|
+
addError(localize_1.LocMessage.unionTypeArgCount(), errorNode);
|
10734
10767
|
return types_1.NeverType.createNever();
|
10735
10768
|
}
|
10736
10769
|
return classType;
|
@@ -10753,7 +10786,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10753
10786
|
allowSingleTypeArg = true;
|
10754
10787
|
}
|
10755
10788
|
else {
|
10756
|
-
addDiagnostic(
|
10789
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.unionUnpackedTuple(), errorNode);
|
10757
10790
|
types.push(types_1.UnknownType.create());
|
10758
10791
|
}
|
10759
10792
|
}
|
@@ -10766,7 +10799,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10766
10799
|
allowSingleTypeArg = true;
|
10767
10800
|
}
|
10768
10801
|
else {
|
10769
|
-
addDiagnostic(
|
10802
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.unionUnpackedTypeVarTuple(), errorNode);
|
10770
10803
|
typeArgType = types_1.UnknownType.create();
|
10771
10804
|
}
|
10772
10805
|
}
|
@@ -10777,7 +10810,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10777
10810
|
// is allowed if it's an unpacked variadic type var or tuple. None is also allowed
|
10778
10811
|
// since it is used to define NoReturn in typeshed stubs).
|
10779
10812
|
if (types.length === 1 && !allowSingleTypeArg && !(0, typeUtils_1.isNoneInstance)(types[0])) {
|
10780
|
-
addDiagnostic(
|
10813
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.unionTypeArgCount(), errorNode);
|
10781
10814
|
}
|
10782
10815
|
let unionType = (0, types_1.combineTypes)(types);
|
10783
10816
|
if (unionClassType && (0, types_1.isInstantiableClass)(unionClassType)) {
|
@@ -10793,7 +10826,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10793
10826
|
// depends on whether we're evaluating a type annotation or
|
10794
10827
|
// we're in some other context.
|
10795
10828
|
if ((flags & (256 /* EvaluatorFlags.ExpectingTypeAnnotation */ | 262144 /* EvaluatorFlags.DisallowNakedGeneric */)) !== 0) {
|
10796
|
-
addError(localize_1.
|
10829
|
+
addError(localize_1.LocMessage.genericTypeArgMissing(), errorNode);
|
10797
10830
|
}
|
10798
10831
|
return classType;
|
10799
10832
|
}
|
@@ -10801,16 +10834,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10801
10834
|
if (typeArgs) {
|
10802
10835
|
// Make sure there's at least one type arg.
|
10803
10836
|
if (typeArgs.length === 0) {
|
10804
|
-
addError(localize_1.
|
10837
|
+
addError(localize_1.LocMessage.genericTypeArgMissing(), errorNode);
|
10805
10838
|
}
|
10806
10839
|
// Make sure that all of the type args are typeVars and are unique.
|
10807
10840
|
typeArgs.forEach((typeArg) => {
|
10808
10841
|
if (!(0, types_1.isTypeVar)(typeArg.type)) {
|
10809
|
-
addError(localize_1.
|
10842
|
+
addError(localize_1.LocMessage.genericTypeArgTypeVar(), typeArg.node);
|
10810
10843
|
}
|
10811
10844
|
else {
|
10812
10845
|
if (uniqueTypeVars.some((t) => (0, types_1.isTypeSame)(t, typeArg.type))) {
|
10813
|
-
addError(localize_1.
|
10846
|
+
addError(localize_1.LocMessage.genericTypeArgUnique(), typeArg.node);
|
10814
10847
|
}
|
10815
10848
|
uniqueTypeVars.push(typeArg.type);
|
10816
10849
|
}
|
@@ -10859,14 +10892,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10859
10892
|
// Verify that we have at most one variadic type variable.
|
10860
10893
|
const variadics = typeParameters.filter((param) => (0, types_1.isVariadicTypeVar)(param));
|
10861
10894
|
if (variadics.length > 1) {
|
10862
|
-
addError(localize_1.
|
10895
|
+
addError(localize_1.LocMessage.variadicTypeParamTooManyAlias().format({
|
10863
10896
|
names: variadics.map((v) => `"${v.details.name}"`).join(', '),
|
10864
10897
|
}), errorNode);
|
10865
10898
|
}
|
10866
10899
|
if (!isPep695Syntax && !isPep695TypeVarType) {
|
10867
10900
|
const boundTypeVars = typeParameters.filter((typeVar) => typeVar.scopeId !== typeAliasScopeId && typeVar.scopeType === 0 /* TypeVarScopeType.Class */);
|
10868
10901
|
if (boundTypeVars.length > 0) {
|
10869
|
-
addError(localize_1.
|
10902
|
+
addError(localize_1.LocMessage.genericTypeAliasBoundTypeVar().format({
|
10870
10903
|
names: boundTypeVars.map((t) => `${t.details.name}`).join(', '),
|
10871
10904
|
}), errorNode);
|
10872
10905
|
}
|
@@ -11081,7 +11114,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11081
11114
|
if (isDeclaredTypeAlias(node.leftExpression)) {
|
11082
11115
|
typeAliasNameNode = node.leftExpression.valueExpression;
|
11083
11116
|
if (!isLegalTypeAliasExpressionForm(node.rightExpression)) {
|
11084
|
-
addDiagnostic(
|
11117
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAliasIllegalExpressionForm(), node.rightExpression);
|
11085
11118
|
}
|
11086
11119
|
}
|
11087
11120
|
else if (node.leftExpression.nodeType === 38 /* ParseNodeType.Name */) {
|
@@ -11132,7 +11165,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11132
11165
|
rightHandType = srcType;
|
11133
11166
|
if (node.leftExpression.nodeType === 38 /* ParseNodeType.Name */ && !node.typeAnnotationComment) {
|
11134
11167
|
rightHandType =
|
11135
|
-
(_a = (0, enums_1.transformTypeForPossibleEnumClass)(evaluatorInterface, node.leftExpression, () => rightHandType)) !== null && _a !== void 0 ? _a : rightHandType;
|
11168
|
+
(_a = (0, enums_1.transformTypeForPossibleEnumClass)(evaluatorInterface, node, node.leftExpression, () => rightHandType)) !== null && _a !== void 0 ? _a : rightHandType;
|
11136
11169
|
}
|
11137
11170
|
if (typeAliasNameNode) {
|
11138
11171
|
// If this was a speculative type alias, it becomes a real type alias
|
@@ -11144,7 +11177,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11144
11177
|
/* isPep695TypeVarType */ false);
|
11145
11178
|
(0, debug_1.assert)(typeAliasTypeVar !== undefined);
|
11146
11179
|
if ((0, typeUtils_1.isTypeAliasRecursive)(typeAliasTypeVar, rightHandType)) {
|
11147
|
-
addDiagnostic(
|
11180
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAliasIsRecursiveDirect().format({
|
11148
11181
|
name: typeAliasNameNode.value,
|
11149
11182
|
}), node.rightExpression);
|
11150
11183
|
rightHandType = types_1.UnknownType.create();
|
@@ -11243,7 +11276,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11243
11276
|
aliasType = transformTypeForTypeAlias(aliasType, nameNode, nameNode, isPep695Syntax,
|
11244
11277
|
/* isPep695TypeVarType */ true, typeParameters, typeParamNodes);
|
11245
11278
|
if ((0, typeUtils_1.isTypeAliasRecursive)(typeAliasTypeVar, aliasType)) {
|
11246
|
-
addDiagnostic(
|
11279
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAliasIsRecursiveDirect().format({
|
11247
11280
|
name: nameNode.value,
|
11248
11281
|
}), valueNode);
|
11249
11282
|
aliasType = types_1.UnknownType.create();
|
@@ -11364,7 +11397,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11364
11397
|
argType = types_1.UnknownType.create();
|
11365
11398
|
}
|
11366
11399
|
else {
|
11367
|
-
argType =
|
11400
|
+
argType = getTypeOfExpression(arg.valueExpression, exprFlags).type;
|
11401
|
+
if ((0, types_1.isTypeVar)(argType) && argType.specialForm && types_1.TypeBase.isInstance(argType.specialForm)) {
|
11402
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.baseClassInvalid(), arg);
|
11403
|
+
argType = types_1.UnknownType.create();
|
11404
|
+
}
|
11405
|
+
argType = makeTopLevelTypeVarsConcrete(argType);
|
11368
11406
|
}
|
11369
11407
|
// In some stub files, classes are conditionally defined (e.g. based
|
11370
11408
|
// on platform type). We'll assume that the conditional logic is correct
|
@@ -11386,7 +11424,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11386
11424
|
: types_1.UnknownType.create();
|
11387
11425
|
}
|
11388
11426
|
else if (!(0, types_1.isInstantiableClass)(argType)) {
|
11389
|
-
addDiagnostic(
|
11427
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.baseClassInvalid(), arg);
|
11390
11428
|
argType = types_1.UnknownType.create();
|
11391
11429
|
}
|
11392
11430
|
else {
|
@@ -11401,7 +11439,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11401
11439
|
if (!fileInfo.isStubFile &&
|
11402
11440
|
!types_1.ClassType.isTypingExtensionClass(argType) &&
|
11403
11441
|
fileInfo.executionEnvironment.pythonVersion < pythonVersion_1.PythonVersion.V3_7) {
|
11404
|
-
addError(localize_1.
|
11442
|
+
addError(localize_1.LocMessage.protocolIllegal(), arg.valueExpression);
|
11405
11443
|
}
|
11406
11444
|
classType.details.flags |= 8192 /* ClassTypeFlags.ProtocolClass */;
|
11407
11445
|
}
|
@@ -11426,19 +11464,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11426
11464
|
// Validate that the class isn't deriving from itself, creating a
|
11427
11465
|
// circular dependency.
|
11428
11466
|
if ((0, typeUtils_1.derivesFromClassRecursive)(argType, classType, /* ignoreUnknown */ true)) {
|
11429
|
-
addError(localize_1.
|
11467
|
+
addError(localize_1.LocMessage.baseClassCircular(), arg);
|
11430
11468
|
argType = types_1.UnknownType.create();
|
11431
11469
|
}
|
11432
11470
|
// If the class is attempting to derive from a TypeAliasType,
|
11433
11471
|
// generate an error.
|
11434
11472
|
if (argType.specialForm && types_1.ClassType.isBuiltIn(argType.specialForm, 'TypeAliasType')) {
|
11435
|
-
addError(localize_1.
|
11473
|
+
addError(localize_1.LocMessage.typeAliasTypeBaseClass(), arg);
|
11436
11474
|
argType = types_1.UnknownType.create();
|
11437
11475
|
}
|
11438
11476
|
}
|
11439
11477
|
}
|
11440
11478
|
if ((0, types_1.isUnknown)(argType)) {
|
11441
|
-
addDiagnostic(
|
11479
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUntypedBaseClass, localize_1.LocMessage.baseClassUnknown(), arg);
|
11442
11480
|
}
|
11443
11481
|
// Check for a duplicate class.
|
11444
11482
|
if (classType.details.baseClasses.some((prevBaseClass) => {
|
@@ -11446,7 +11484,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11446
11484
|
(0, types_1.isInstantiableClass)(argType) &&
|
11447
11485
|
types_1.ClassType.isSameGenericClass(argType, prevBaseClass));
|
11448
11486
|
})) {
|
11449
|
-
addDiagnostic(
|
11487
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.duplicateBaseClass(), arg.name || arg);
|
11450
11488
|
}
|
11451
11489
|
classType.details.baseClasses.push(argType);
|
11452
11490
|
if ((0, types_1.isInstantiableClass)(argType)) {
|
@@ -11467,7 +11505,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11467
11505
|
}
|
11468
11506
|
if (types_1.ClassType.isFinal(argType)) {
|
11469
11507
|
const className = printObjectTypeForClass(argType);
|
11470
|
-
addError(localize_1.
|
11508
|
+
addError(localize_1.LocMessage.baseClassFinal().format({ type: className }), arg.valueExpression);
|
11471
11509
|
}
|
11472
11510
|
}
|
11473
11511
|
(0, typeUtils_1.addTypeVarsToListIfUnique)(typeParameters, (0, typeUtils_1.getTypeVarArgumentsRecursive)(argType));
|
@@ -11475,12 +11513,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11475
11513
|
if (types_1.ClassType.isBuiltIn(argType, 'Generic')) {
|
11476
11514
|
// 'Generic' is implicitly added if type parameter syntax is used.
|
11477
11515
|
if (node.typeParameters) {
|
11478
|
-
addDiagnostic(
|
11516
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.genericBaseClassNotAllowed(), arg.valueExpression);
|
11479
11517
|
}
|
11480
11518
|
else {
|
11481
11519
|
if (!genericTypeParameters) {
|
11482
11520
|
if (protocolTypeParameters) {
|
11483
|
-
addDiagnostic(
|
11521
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.duplicateGenericAndProtocolBase(), arg.valueExpression);
|
11484
11522
|
}
|
11485
11523
|
genericTypeParameters = [];
|
11486
11524
|
(0, typeUtils_1.addTypeVarsToListIfUnique)(genericTypeParameters, (0, typeUtils_1.getTypeVarArgumentsRecursive)(argType));
|
@@ -11492,12 +11530,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11492
11530
|
argType.typeArguments.length > 0) {
|
11493
11531
|
if (!protocolTypeParameters) {
|
11494
11532
|
if (genericTypeParameters) {
|
11495
|
-
addDiagnostic(
|
11533
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.duplicateGenericAndProtocolBase(), arg.valueExpression);
|
11496
11534
|
}
|
11497
11535
|
protocolTypeParameters = [];
|
11498
11536
|
(0, typeUtils_1.addTypeVarsToListIfUnique)(protocolTypeParameters, (0, typeUtils_1.getTypeVarArgumentsRecursive)(argType));
|
11499
11537
|
if (node.typeParameters && protocolTypeParameters.length > 0) {
|
11500
|
-
addDiagnostic(
|
11538
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.protocolBaseClassWithTypeArgs(), arg.valueExpression);
|
11501
11539
|
protocolTypeParameters = [];
|
11502
11540
|
}
|
11503
11541
|
}
|
@@ -11510,19 +11548,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11510
11548
|
// PEP 589 specifies that the parameter must be either True or False.
|
11511
11549
|
const constArgValue = (0, staticExpressions_1.evaluateStaticBoolExpression)(arg.valueExpression, fileInfo.executionEnvironment, fileInfo.definedConstants);
|
11512
11550
|
if (constArgValue === undefined) {
|
11513
|
-
addError(localize_1.
|
11551
|
+
addError(localize_1.LocMessage.typedDictBoolParam().format({ name: arg.name.value }), arg.valueExpression);
|
11514
11552
|
}
|
11515
11553
|
else if (arg.name.value === 'total' && !constArgValue) {
|
11516
11554
|
classType.details.flags |= 256 /* ClassTypeFlags.CanOmitDictValues */;
|
11517
11555
|
}
|
11518
11556
|
}
|
11519
11557
|
else {
|
11520
|
-
addError(localize_1.
|
11558
|
+
addError(localize_1.LocMessage.typedDictInitsubclassParameter().format({ name: arg.name.value }), arg);
|
11521
11559
|
}
|
11522
11560
|
}
|
11523
11561
|
else if (arg.name.value === 'metaclass') {
|
11524
11562
|
if (metaclassNode) {
|
11525
|
-
addError(localize_1.
|
11563
|
+
addError(localize_1.LocMessage.metaclassDuplicate(), arg);
|
11526
11564
|
}
|
11527
11565
|
else {
|
11528
11566
|
metaclassNode = arg.valueExpression;
|
@@ -11554,7 +11592,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11554
11592
|
}
|
11555
11593
|
});
|
11556
11594
|
if (derivesFromNamedTuple && foundIllegalBaseClass) {
|
11557
|
-
addDiagnostic(
|
11595
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.namedTupleMultipleInheritance(), node.name);
|
11558
11596
|
}
|
11559
11597
|
}
|
11560
11598
|
// Make sure we don't have 'object' derive from itself. Infinite
|
@@ -11578,7 +11616,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11578
11616
|
// Make sure there's at most one variadic type parameter.
|
11579
11617
|
const variadics = classType.details.typeParameters.filter((param) => (0, types_1.isVariadicTypeVar)(param));
|
11580
11618
|
if (variadics.length > 1) {
|
11581
|
-
addError(localize_1.
|
11619
|
+
addError(localize_1.LocMessage.variadicTypeParamTooManyClass().format({
|
11582
11620
|
names: variadics.map((v) => `"${v.details.name}"`).join(', '),
|
11583
11621
|
}), node.name, textRange_1.TextRange.combine(node.arguments) || node.name);
|
11584
11622
|
}
|
@@ -11593,7 +11631,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11593
11631
|
validateTypeParameterDefault(bestErrorNode, typeParam, classType.details.typeParameters.slice(0, index), classType.details.typeVarScopeId);
|
11594
11632
|
});
|
11595
11633
|
if (!(0, typeUtils_1.computeMroLinearization)(classType)) {
|
11596
|
-
addError(localize_1.
|
11634
|
+
addError(localize_1.LocMessage.methodOrdering(), node.name);
|
11597
11635
|
}
|
11598
11636
|
// The scope for this class becomes the "fields" for the corresponding type.
|
11599
11637
|
const innerScope = ScopeUtils.getScopeForNode(node.suite);
|
@@ -11663,14 +11701,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11663
11701
|
const metaclassType = getTypeOfExpression(metaclassNode, exprFlags).type;
|
11664
11702
|
if ((0, types_1.isInstantiableClass)(metaclassType) || (0, types_1.isUnknown)(metaclassType)) {
|
11665
11703
|
if ((0, typeUtils_1.requiresSpecialization)(metaclassType, { ignorePseudoGeneric: true })) {
|
11666
|
-
addDiagnostic(
|
11704
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.metaclassIsGeneric(), metaclassNode);
|
11667
11705
|
}
|
11668
11706
|
classType.details.declaredMetaclass = metaclassType;
|
11669
11707
|
if ((0, types_1.isInstantiableClass)(metaclassType)) {
|
11670
|
-
if (
|
11708
|
+
if ((0, enums_1.isEnumMetaclass)(metaclassType)) {
|
11671
11709
|
classType.details.flags |= 1048576 /* ClassTypeFlags.EnumClass */;
|
11672
11710
|
}
|
11673
|
-
|
11711
|
+
if (types_1.ClassType.isBuiltIn(metaclassType, 'ABCMeta')) {
|
11674
11712
|
classType.details.flags |= 1024 /* ClassTypeFlags.SupportsAbstractMethods */;
|
11675
11713
|
}
|
11676
11714
|
}
|
@@ -11689,7 +11727,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11689
11727
|
if (unknownOrAny && (0, types_1.isUnknown)(unknownOrAny)) {
|
11690
11728
|
// Report this error only on the first unknown type.
|
11691
11729
|
if (!foundUnknown) {
|
11692
|
-
addDiagnostic(
|
11730
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUntypedClassDecorator, localize_1.LocMessage.classDecoratorTypeUnknown(), node.decorators[i].expression);
|
11693
11731
|
foundUnknown = true;
|
11694
11732
|
}
|
11695
11733
|
}
|
@@ -11734,11 +11772,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11734
11772
|
!types_1.ClassType.isTypedDictClass(baseClass) &&
|
11735
11773
|
!types_1.ClassType.isBuiltIn(baseClass, ['_TypedDict', 'Generic'])) {
|
11736
11774
|
foundInvalidBaseClass = true;
|
11737
|
-
diag.addMessage(localize_1.
|
11775
|
+
diag.addMessage(localize_1.LocAddendum.typedDictBaseClass().format({ type: baseClass.details.name }));
|
11738
11776
|
}
|
11739
11777
|
});
|
11740
11778
|
if (foundInvalidBaseClass) {
|
11741
|
-
addError(localize_1.
|
11779
|
+
addError(localize_1.LocMessage.typedDictBaseClass() + diag.getString(), node.name);
|
11742
11780
|
}
|
11743
11781
|
(0, typedDicts_1.synthesizeTypedDictClassMethods)(evaluatorInterface, node, classType, (0, types_1.isClass)(decoratedType) && types_1.ClassType.isFinal(decoratedType));
|
11744
11782
|
}
|
@@ -11814,7 +11852,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11814
11852
|
!typeParam.details.isSynthesizedSelf) {
|
11815
11853
|
const typeVarWithDefault = otherLiveTypeParams.find((param) => param.details.defaultType && param.scopeId === scopeId);
|
11816
11854
|
if (typeVarWithDefault) {
|
11817
|
-
addDiagnostic(
|
11855
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarWithoutDefault().format({
|
11818
11856
|
name: typeParam.details.name,
|
11819
11857
|
other: typeVarWithDefault.details.name,
|
11820
11858
|
}), errorNode);
|
@@ -11827,9 +11865,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11827
11865
|
if (invalidTypeVars.size > 0) {
|
11828
11866
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
11829
11867
|
invalidTypeVars.forEach((name) => {
|
11830
|
-
diag.addMessage(localize_1.
|
11868
|
+
diag.addMessage(localize_1.LocAddendum.typeVarDefaultOutOfScope().format({ name }));
|
11831
11869
|
});
|
11832
|
-
addDiagnostic(
|
11870
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarDefaultInvalidTypeVar().format({
|
11833
11871
|
name: typeParam.details.name,
|
11834
11872
|
}) + diag.getString(), errorNode);
|
11835
11873
|
}
|
@@ -11851,11 +11889,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11851
11889
|
param.computedVariance = 1 /* Variance.Unknown */;
|
11852
11890
|
}
|
11853
11891
|
});
|
11854
|
-
// Replace all of the type parameters with invariant TypeVars.
|
11855
|
-
const updatedTypeParams = classType.details.typeParameters.map((typeParam) => types_1.TypeVarType.cloneAsInvariant(typeParam));
|
11856
|
-
const updatedClassType = types_1.ClassType.cloneWithNewTypeParameters(classType, updatedTypeParams);
|
11857
11892
|
const dummyTypeObject = types_1.ClassType.createInstantiable('__varianceDummy', '', '', uri_1.Uri.empty(), 0, 0, undefined, undefined);
|
11858
|
-
|
11893
|
+
classType.details.typeParameters.forEach((param, paramIndex) => {
|
11859
11894
|
// Skip variadics and ParamSpecs.
|
11860
11895
|
if (param.details.isVariadic || param.details.isParamSpec) {
|
11861
11896
|
return;
|
@@ -11866,7 +11901,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11866
11901
|
}
|
11867
11902
|
// Replace all type arguments with a dummy type except for the
|
11868
11903
|
// TypeVar of interest, which is replaced with an object instance.
|
11869
|
-
const srcTypeArgs =
|
11904
|
+
const srcTypeArgs = classType.details.typeParameters.map((p, i) => {
|
11870
11905
|
if (p.details.isVariadic) {
|
11871
11906
|
return p;
|
11872
11907
|
}
|
@@ -11875,20 +11910,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11875
11910
|
});
|
11876
11911
|
// Replace all type arguments with a dummy type except for the
|
11877
11912
|
// TypeVar of interest, which is replaced with itself.
|
11878
|
-
const destTypeArgs =
|
11913
|
+
const destTypeArgs = classType.details.typeParameters.map((p, i) => {
|
11879
11914
|
return i === paramIndex || p.details.isVariadic ? p : dummyTypeObject;
|
11880
11915
|
});
|
11881
|
-
const srcType = types_1.ClassType.cloneForSpecialization(
|
11916
|
+
const srcType = types_1.ClassType.cloneForSpecialization(classType, srcTypeArgs, /* isTypeArgumentExplicit */ true);
|
11917
|
+
const destType = types_1.ClassType.cloneForSpecialization(classType, destTypeArgs,
|
11882
11918
|
/* isTypeArgumentExplicit */ true);
|
11883
|
-
const
|
11884
|
-
/*
|
11885
|
-
const isDestSubtypeOfSrc = assignClassToSelf(srcType, destType, /* ignoreBaseClassVariance */ false);
|
11919
|
+
const isDestSubtypeOfSrc = assignClassToSelf(srcType, destType, 3 /* Variance.Covariant */,
|
11920
|
+
/* ignoreBaseClassVariance */ false);
|
11886
11921
|
let inferredVariance;
|
11887
11922
|
if (isDestSubtypeOfSrc) {
|
11888
11923
|
inferredVariance = 3 /* Variance.Covariant */;
|
11889
11924
|
}
|
11890
11925
|
else {
|
11891
|
-
const isSrcSubtypeOfDest = assignClassToSelf(destType, srcType, /*
|
11926
|
+
const isSrcSubtypeOfDest = assignClassToSelf(destType, srcType, 4 /* Variance.Contravariant */,
|
11927
|
+
/* ignoreBaseClassVariance */ false);
|
11892
11928
|
if (isSrcSubtypeOfDest) {
|
11893
11929
|
inferredVariance = 4 /* Variance.Contravariant */;
|
11894
11930
|
}
|
@@ -11938,11 +11974,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11938
11974
|
else if (!(0, typeUtils_1.derivesFromClassRecursive)(effectiveMetaclass, baseClassMeta, /* ignoreUnknown */ false)) {
|
11939
11975
|
if (!reportedMetaclassConflict) {
|
11940
11976
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
11941
|
-
diag.addMessage(localize_1.
|
11977
|
+
diag.addMessage(localize_1.LocAddendum.metaclassConflict().format({
|
11942
11978
|
metaclass1: printType((0, typeUtils_1.convertToInstance)(effectiveMetaclass)),
|
11943
11979
|
metaclass2: printType((0, typeUtils_1.convertToInstance)(baseClassMeta)),
|
11944
11980
|
}));
|
11945
|
-
addDiagnostic(
|
11981
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.metaclassConflict() + diag.getString(), errorNode);
|
11946
11982
|
// Don't report more than once.
|
11947
11983
|
reportedMetaclassConflict = true;
|
11948
11984
|
}
|
@@ -11952,9 +11988,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11952
11988
|
effectiveMetaclass = baseClassMeta ? types_1.UnknownType.create() : undefined;
|
11953
11989
|
break;
|
11954
11990
|
}
|
11955
|
-
if (types_1.ClassType.isEnumClass(baseClass)) {
|
11956
|
-
classType.details.flags |= 1048576 /* ClassTypeFlags.EnumClass */;
|
11957
|
-
}
|
11958
11991
|
}
|
11959
11992
|
else {
|
11960
11993
|
// If one of the base classes is unknown, then the effective
|
@@ -11984,10 +12017,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11984
12017
|
});
|
11985
12018
|
if (missingFromGeneric.length > 0) {
|
11986
12019
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
11987
|
-
diag.addMessage(localize_1.
|
12020
|
+
diag.addMessage(localize_1.LocAddendum.typeVarsMissing().format({
|
11988
12021
|
names: missingFromGeneric.map((typeVar) => `"${typeVar.details.name}"`).join(', '),
|
11989
12022
|
}));
|
11990
|
-
addDiagnostic(
|
12023
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarsNotInGenericOrProtocol() + diag.getString(), errorNode);
|
11991
12024
|
}
|
11992
12025
|
}
|
11993
12026
|
// Records the fact that the specified class requires "deferred completion" because
|
@@ -12033,7 +12066,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12033
12066
|
function completeClassTypeDeferred(type, errorNode) {
|
12034
12067
|
// Recompute the MRO linearization.
|
12035
12068
|
if (!(0, typeUtils_1.computeMroLinearization)(type)) {
|
12036
|
-
addError(localize_1.
|
12069
|
+
addError(localize_1.LocMessage.methodOrdering(), errorNode);
|
12037
12070
|
}
|
12038
12071
|
// Recompute the effective metaclass.
|
12039
12072
|
computeEffectiveMetaclass(type, errorNode);
|
@@ -12090,7 +12123,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12090
12123
|
paramMap.delete(arg.name.value);
|
12091
12124
|
}
|
12092
12125
|
else {
|
12093
|
-
addDiagnostic(
|
12126
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.paramNameMissing().format({ name: arg.name.value }), (_c = arg.name) !== null && _c !== void 0 ? _c : errorNode);
|
12094
12127
|
}
|
12095
12128
|
}
|
12096
12129
|
});
|
@@ -12105,9 +12138,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12105
12138
|
});
|
12106
12139
|
if (unassignedParams.length > 0) {
|
12107
12140
|
const missingParamNames = unassignedParams.map((p) => `"${p}"`).join(', ');
|
12108
|
-
addDiagnostic(
|
12109
|
-
? localize_1.
|
12110
|
-
: localize_1.
|
12141
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, unassignedParams.length === 1
|
12142
|
+
? localize_1.LocMessage.argMissingForParam().format({ name: missingParamNames })
|
12143
|
+
: localize_1.LocMessage.argMissingForParams().format({ names: missingParamNames }), errorNode);
|
12111
12144
|
}
|
12112
12145
|
}
|
12113
12146
|
}
|
@@ -12127,7 +12160,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12127
12160
|
/* typeVarContext */ undefined,
|
12128
12161
|
/* skipUnknownArgCheck */ false, (0, typeUtils_1.makeInferenceContext)(getNoneType()));
|
12129
12162
|
if (callResult.argumentErrors) {
|
12130
|
-
const diag = addDiagnostic(
|
12163
|
+
const diag = addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.initSubclassCallFailed(), node.name);
|
12131
12164
|
const initSubclassFunction = (0, types_1.isOverloadedFunction)(initSubclassMethodType)
|
12132
12165
|
? types_1.OverloadedFunctionType.getOverloads(initSubclassMethodType)[0]
|
12133
12166
|
: initSubclassMethodType;
|
@@ -12135,7 +12168,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12135
12168
|
? initSubclassFunction.details.declaration
|
12136
12169
|
: undefined;
|
12137
12170
|
if (diag && initSubclassDecl) {
|
12138
|
-
diag.addRelatedInfo(localize_1.
|
12171
|
+
diag.addRelatedInfo(localize_1.LocAddendum.initSubclassLocation().format({
|
12139
12172
|
name: printType((0, typeUtils_1.convertToInstance)(initSubclassMethodInfo.classType)),
|
12140
12173
|
}), initSubclassDecl.uri, initSubclassDecl.range);
|
12141
12174
|
}
|
@@ -12151,6 +12184,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12151
12184
|
});
|
12152
12185
|
}
|
12153
12186
|
function getTypeOfFunction(node) {
|
12187
|
+
var _a;
|
12154
12188
|
initializedBasicTypes(node);
|
12155
12189
|
// Is this predecorated function type cached?
|
12156
12190
|
let functionType = readTypeCache(node.name, 0 /* EvaluatorFlags.None */);
|
@@ -12189,8 +12223,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12189
12223
|
if (unknownOrAny && (0, types_1.isUnknown)(unknownOrAny)) {
|
12190
12224
|
// Report this error only on the first unknown type.
|
12191
12225
|
if (!foundUnknown) {
|
12192
|
-
|
12193
|
-
addDiagnostic(fileInfo.diagnosticRuleSet.reportUntypedFunctionDecorator, diagnosticRules_1.DiagnosticRule.reportUntypedFunctionDecorator, localize_1.Localizer.Diagnostic.functionDecoratorTypeUnknown(), node.decorators[i].expression);
|
12226
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUntypedFunctionDecorator, localize_1.LocMessage.functionDecoratorTypeUnknown(), node.decorators[i].expression);
|
12194
12227
|
foundUnknown = true;
|
12195
12228
|
}
|
12196
12229
|
}
|
@@ -12199,6 +12232,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12199
12232
|
decoratedType = newDecoratedType;
|
12200
12233
|
}
|
12201
12234
|
}
|
12235
|
+
// In case this is an enum class and a method wrapped in an enum.member.
|
12236
|
+
decoratedType =
|
12237
|
+
(_a = (0, enums_1.transformTypeForPossibleEnumClass)(evaluatorInterface, node, node.name, () => decoratedType)) !== null && _a !== void 0 ? _a : decoratedType;
|
12202
12238
|
// See if there are any overloads provided by previous function declarations.
|
12203
12239
|
if ((0, types_1.isFunction)(decoratedType)) {
|
12204
12240
|
decoratedType.details.deprecatedMessage = functionType.details.deprecatedMessage;
|
@@ -12295,7 +12331,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12295
12331
|
firstCommentAnnotationIndex = 0;
|
12296
12332
|
}
|
12297
12333
|
else if (received !== expected) {
|
12298
|
-
addError(localize_1.
|
12334
|
+
addError(localize_1.LocMessage.annotatedParamCountMismatch().format({
|
12299
12335
|
expected,
|
12300
12336
|
received,
|
12301
12337
|
}), node.functionAnnotationComment);
|
@@ -12347,9 +12383,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12347
12383
|
}
|
12348
12384
|
}
|
12349
12385
|
if (paramTypeNode) {
|
12350
|
-
|
12386
|
+
if ((functionInfo.flags & 524288 /* FunctionTypeFlags.NoTypeCheck */) !== 0) {
|
12387
|
+
annotatedType = types_1.UnknownType.create();
|
12388
|
+
}
|
12389
|
+
else {
|
12390
|
+
annotatedType = getTypeOfParameterAnnotation(paramTypeNode, param.category);
|
12391
|
+
}
|
12351
12392
|
if ((0, types_1.isVariadicTypeVar)(annotatedType) && !annotatedType.isVariadicUnpacked) {
|
12352
|
-
addError(localize_1.
|
12393
|
+
addError(localize_1.LocMessage.unpackedTypeVarTupleExpected().format({
|
12353
12394
|
name1: annotatedType.details.name,
|
12354
12395
|
name2: annotatedType.details.name,
|
12355
12396
|
}), paramTypeNode);
|
@@ -12394,7 +12435,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12394
12435
|
}
|
12395
12436
|
}
|
12396
12437
|
if (!assignType(annotatedType, defaultValueType, diagAddendum, typeVarContext)) {
|
12397
|
-
addDiagnostic(
|
12438
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.paramAssignmentMismatch().format({
|
12398
12439
|
sourceType: printType(defaultValueType),
|
12399
12440
|
paramType: printType(annotatedType),
|
12400
12441
|
}) + diagAddendum.getString(), param.defaultValue);
|
@@ -12842,6 +12883,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12842
12883
|
isIncomplete = true;
|
12843
12884
|
}
|
12844
12885
|
let returnType = returnTypeResult.type;
|
12886
|
+
// If the type is a special form, use the special form instead.
|
12887
|
+
if (returnType.specialForm) {
|
12888
|
+
returnType = returnType.specialForm;
|
12889
|
+
}
|
12845
12890
|
// If the return type includes an instance of a class with isEmptyContainer
|
12846
12891
|
// set, clear that because we don't want this flag to "leak" into the
|
12847
12892
|
// inferred return type.
|
@@ -13039,8 +13084,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13039
13084
|
let exprType = exprTypeResult.type;
|
13040
13085
|
const isAsync = node.parent && node.parent.nodeType === 58 /* ParseNodeType.With */ && !!node.parent.isAsync;
|
13041
13086
|
if ((0, typeUtils_1.isOptionalType)(exprType)) {
|
13042
|
-
|
13043
|
-
addDiagnostic(fileInfo.diagnosticRuleSet.reportOptionalContextManager, diagnosticRules_1.DiagnosticRule.reportOptionalContextManager, localize_1.Localizer.Diagnostic.noneNotUsableWith(), node.expression);
|
13087
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportOptionalContextManager, localize_1.LocMessage.noneNotUsableWith(), node.expression);
|
13044
13088
|
exprType = (0, typeUtils_1.removeNoneFromUnion)(exprType);
|
13045
13089
|
}
|
13046
13090
|
// Verify that the target has an __enter__ or __aenter__ method defined.
|
@@ -13064,12 +13108,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13064
13108
|
if (!isAsync) {
|
13065
13109
|
if (getTypeOfMagicMethodCall(subtype, '__aenter__', [], node.expression,
|
13066
13110
|
/* inferenceContext */ undefined)) {
|
13067
|
-
additionalHelp.addMessage(localize_1.
|
13111
|
+
additionalHelp.addMessage(localize_1.LocAddendum.asyncHelp());
|
13068
13112
|
}
|
13069
13113
|
}
|
13070
13114
|
}
|
13071
|
-
|
13072
|
-
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeNotUsableWith().format({ type: printType(subtype), method: enterMethodName }) +
|
13115
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeNotUsableWith().format({ type: printType(subtype), method: enterMethodName }) +
|
13073
13116
|
additionalHelp.getString(), node.expression);
|
13074
13117
|
return types_1.UnknownType.create();
|
13075
13118
|
});
|
@@ -13088,8 +13131,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13088
13131
|
return;
|
13089
13132
|
}
|
13090
13133
|
}
|
13091
|
-
|
13092
|
-
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeNotUsableWith().format({ type: printType(subtype), method: exitMethodName }), node.expression);
|
13134
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeNotUsableWith().format({ type: printType(subtype), method: exitMethodName }), node.expression);
|
13093
13135
|
});
|
13094
13136
|
if (node.target) {
|
13095
13137
|
assignTypeToExpression(node.target, scopedType, !!exprTypeResult.isIncomplete, node.target);
|
@@ -13183,7 +13225,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13183
13225
|
reportError = true;
|
13184
13226
|
}
|
13185
13227
|
if (reportError) {
|
13186
|
-
addDiagnostic(
|
13228
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.importSymbolUnknown().format({ name: node.name.value }), node.name);
|
13187
13229
|
}
|
13188
13230
|
}
|
13189
13231
|
if (!symbolType) {
|
@@ -13264,7 +13306,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13264
13306
|
}
|
13265
13307
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
13266
13308
|
if (!assignType(declaredType, importedSymbolType, diagAddendum)) {
|
13267
|
-
addDiagnostic(
|
13309
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAssignmentMismatchWildcard().format({
|
13268
13310
|
...printSrcDestTypes(importedSymbolType, declaredType),
|
13269
13311
|
name,
|
13270
13312
|
}) + diagAddendum.getString(), node, (_b = node.wildcardToken) !== null && _b !== void 0 ? _b : node);
|
@@ -13347,18 +13389,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13347
13389
|
}
|
13348
13390
|
if (node.nodeType === 23 /* ParseNodeType.ImportFromAs */) {
|
13349
13391
|
if (resolvedAliasInfo.isPrivate) {
|
13350
|
-
addDiagnostic(
|
13392
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportPrivateUsage, localize_1.LocMessage.privateUsedOutsideOfModule().format({
|
13351
13393
|
name: node.name.value,
|
13352
13394
|
}), node.name);
|
13353
13395
|
}
|
13354
13396
|
if (resolvedAliasInfo.privatePyTypedImporter) {
|
13355
13397
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
13356
13398
|
if (resolvedAliasInfo.privatePyTypedImported) {
|
13357
|
-
diag.addMessage(localize_1.
|
13399
|
+
diag.addMessage(localize_1.LocAddendum.privateImportFromPyTypedSource().format({
|
13358
13400
|
module: resolvedAliasInfo.privatePyTypedImported,
|
13359
13401
|
}));
|
13360
13402
|
}
|
13361
|
-
addDiagnostic(
|
13403
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportPrivateImportUsage, localize_1.LocMessage.privateImportFromPyTypedModule().format({
|
13362
13404
|
name: node.name.value,
|
13363
13405
|
module: resolvedAliasInfo.privatePyTypedImporter,
|
13364
13406
|
}) + diag.getString(), node.name);
|
@@ -13450,9 +13492,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13450
13492
|
// See if the expression is part of a pattern used in a case statement.
|
13451
13493
|
const possibleCaseNode = ParseTreeUtils.getParentNodeOfType(node, 64 /* ParseNodeType.Case */);
|
13452
13494
|
if (possibleCaseNode) {
|
13453
|
-
|
13454
|
-
|
13455
|
-
evaluateTypesForCaseStatement(caseNode);
|
13495
|
+
if (ParseTreeUtils.isNodeContainedWithin(node, possibleCaseNode.pattern)) {
|
13496
|
+
evaluateTypesForCaseStatement(possibleCaseNode);
|
13456
13497
|
return;
|
13457
13498
|
}
|
13458
13499
|
}
|
@@ -13856,13 +13897,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13856
13897
|
}
|
13857
13898
|
case 'Never': {
|
13858
13899
|
if (typeArgs && typeArgs.length > 0) {
|
13859
|
-
addError(localize_1.
|
13900
|
+
addError(localize_1.LocMessage.typeArgsExpectingNone().format({ name: 'Never' }), typeArgs[0].node);
|
13860
13901
|
}
|
13861
13902
|
return { type: types_1.NeverType.createNever() };
|
13862
13903
|
}
|
13863
13904
|
case 'NoReturn': {
|
13864
13905
|
if (typeArgs && typeArgs.length > 0) {
|
13865
|
-
addError(localize_1.
|
13906
|
+
addError(localize_1.LocMessage.typeArgsExpectingNone().format({ name: 'NoReturn' }), typeArgs[0].node);
|
13866
13907
|
}
|
13867
13908
|
return { type: types_1.NeverType.createNoReturn() };
|
13868
13909
|
}
|
@@ -13885,7 +13926,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13885
13926
|
if ((flags &
|
13886
13927
|
(67108864 /* EvaluatorFlags.DisallowNonTypeSpecialForms */ | 256 /* EvaluatorFlags.ExpectingTypeAnnotation */)) !==
|
13887
13928
|
0) {
|
13888
|
-
addError(localize_1.
|
13929
|
+
addError(localize_1.LocMessage.protocolNotAllowed(), errorNode);
|
13889
13930
|
}
|
13890
13931
|
return {
|
13891
13932
|
type: createSpecialType(classType, typeArgs,
|
@@ -13897,7 +13938,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13897
13938
|
if ((flags &
|
13898
13939
|
(67108864 /* EvaluatorFlags.DisallowNonTypeSpecialForms */ | 256 /* EvaluatorFlags.ExpectingTypeAnnotation */)) !==
|
13899
13940
|
0) {
|
13900
|
-
addError(localize_1.
|
13941
|
+
addError(localize_1.LocMessage.typedDictNotAllowed(), errorNode);
|
13901
13942
|
}
|
13902
13943
|
break;
|
13903
13944
|
}
|
@@ -13905,7 +13946,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13905
13946
|
if ((flags &
|
13906
13947
|
(67108864 /* EvaluatorFlags.DisallowNonTypeSpecialForms */ | 256 /* EvaluatorFlags.ExpectingTypeAnnotation */)) !==
|
13907
13948
|
0) {
|
13908
|
-
addError(localize_1.
|
13949
|
+
addError(localize_1.LocMessage.literalNotAllowed(), errorNode);
|
13909
13950
|
}
|
13910
13951
|
break;
|
13911
13952
|
}
|
@@ -13927,13 +13968,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13927
13968
|
return { type: createFinalType(classType, errorNode, typeArgs, flags) };
|
13928
13969
|
}
|
13929
13970
|
case 'Annotated': {
|
13930
|
-
return createAnnotatedType(errorNode, typeArgs);
|
13971
|
+
return createAnnotatedType(classType, errorNode, typeArgs);
|
13931
13972
|
}
|
13932
13973
|
case 'Concatenate': {
|
13933
|
-
return { type: createConcatenateType(
|
13974
|
+
return { type: createConcatenateType(classType, errorNode, typeArgs, flags) };
|
13934
13975
|
}
|
13935
13976
|
case 'TypeGuard': {
|
13936
|
-
return { type: createTypeGuardType(
|
13977
|
+
return { type: createTypeGuardType(classType, errorNode, typeArgs, flags) };
|
13937
13978
|
}
|
13938
13979
|
case 'Unpack': {
|
13939
13980
|
return { type: createUnpackType(classType, errorNode, typeArgs, flags) };
|
@@ -13967,7 +14008,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13967
14008
|
if (typeArgs.length >= 1) {
|
13968
14009
|
// Treat type[function] as illegal.
|
13969
14010
|
if ((0, types_1.isFunction)(typeArgs[0].type) || (0, types_1.isOverloadedFunction)(typeArgs[0].type)) {
|
13970
|
-
addDiagnostic(
|
14011
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAnnotationWithCallable(), typeArgs[0].node);
|
13971
14012
|
return { type: types_1.UnknownType.create() };
|
13972
14013
|
}
|
13973
14014
|
}
|
@@ -14010,7 +14051,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14010
14051
|
// Classes that accept inlined type dict type args allow only one.
|
14011
14052
|
if (typeArgs[0].inlinedTypeDict) {
|
14012
14053
|
if (typeArgs.length > 1) {
|
14013
|
-
addDiagnostic(
|
14054
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeArgsTooMany().format({
|
14014
14055
|
name: classType.aliasName || classType.details.name,
|
14015
14056
|
expected: 1,
|
14016
14057
|
received: typeArgCount,
|
@@ -14020,14 +14061,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14020
14061
|
}
|
14021
14062
|
else if (typeArgCount > typeParameters.length) {
|
14022
14063
|
if (!types_1.ClassType.isPartiallyEvaluated(classType) && !types_1.ClassType.isTupleClass(classType)) {
|
14023
|
-
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
14024
14064
|
if (typeParameters.length === 0) {
|
14025
|
-
addDiagnostic(
|
14065
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeArgsExpectingNone().format({
|
14026
14066
|
name: classType.aliasName || classType.details.name,
|
14027
14067
|
}), typeArgs[typeParameters.length].node);
|
14028
14068
|
}
|
14029
14069
|
else if (typeParameters.length !== 1 || !(0, types_1.isParamSpec)(typeParameters[0])) {
|
14030
|
-
addDiagnostic(
|
14070
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeArgsTooMany().format({
|
14031
14071
|
name: classType.aliasName || classType.details.name,
|
14032
14072
|
expected: typeParameters.length,
|
14033
14073
|
received: typeArgCount,
|
@@ -14037,8 +14077,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14037
14077
|
}
|
14038
14078
|
}
|
14039
14079
|
else if (typeArgCount < minTypeArgCount) {
|
14040
|
-
|
14041
|
-
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeArgsTooFew().format({
|
14080
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeArgsTooFew().format({
|
14042
14081
|
name: classType.aliasName || classType.details.name,
|
14043
14082
|
expected: minTypeArgCount,
|
14044
14083
|
received: typeArgCount,
|
@@ -14089,11 +14128,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14089
14128
|
else if (typeArgs.length > 1) {
|
14090
14129
|
const paramSpecTypeArg = typeArgs.find((typeArg) => (0, types_1.isParamSpec)(typeArg.type));
|
14091
14130
|
if (paramSpecTypeArg) {
|
14092
|
-
addError(localize_1.
|
14131
|
+
addError(localize_1.LocMessage.paramSpecContext(), paramSpecTypeArg.node);
|
14093
14132
|
}
|
14094
14133
|
const listTypeArg = typeArgs.find((typeArg) => !!typeArg.typeList);
|
14095
14134
|
if (listTypeArg) {
|
14096
|
-
addError(localize_1.
|
14135
|
+
addError(localize_1.LocMessage.typeArgListNotAllowed(), listTypeArg.node);
|
14097
14136
|
}
|
14098
14137
|
}
|
14099
14138
|
}
|
@@ -14179,7 +14218,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14179
14218
|
const destType = typeParameters[index];
|
14180
14219
|
const declaredVariance = destType.details.declaredVariance;
|
14181
14220
|
if (!(0, typeUtils_1.isVarianceOfTypeArgumentCompatible)(adjustedTypeArgType, declaredVariance)) {
|
14182
|
-
diag.addMessage(localize_1.
|
14221
|
+
diag.addMessage(localize_1.LocAddendum.varianceMismatchForClass().format({
|
14183
14222
|
typeVarName: printType(adjustedTypeArgType),
|
14184
14223
|
className: classType.details.name,
|
14185
14224
|
}));
|
@@ -14193,8 +14232,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14193
14232
|
// Avoid emitting this error for a partially-constructed class.
|
14194
14233
|
if (!(0, types_1.isClassInstance)(typeArgType) || !types_1.ClassType.isPartiallyEvaluated(typeArgType)) {
|
14195
14234
|
(0, debug_1.assert)(typeArgs !== undefined);
|
14196
|
-
|
14197
|
-
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeVarAssignmentMismatch().format({
|
14235
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarAssignmentMismatch().format({
|
14198
14236
|
type: printType(typeArgType),
|
14199
14237
|
name: types_1.TypeVarType.getReadableName(typeParameters[index]),
|
14200
14238
|
}) + diag.getString(), typeArgs[index].node);
|
@@ -14671,7 +14709,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14671
14709
|
return declarations;
|
14672
14710
|
}
|
14673
14711
|
function getTypeForDeclaration(declaration) {
|
14674
|
-
var _a, _b, _c;
|
14712
|
+
var _a, _b, _c, _d;
|
14675
14713
|
switch (declaration.type) {
|
14676
14714
|
case 0 /* DeclarationType.Intrinsic */: {
|
14677
14715
|
if (declaration.intrinsicType === 'Any') {
|
@@ -14780,8 +14818,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14780
14818
|
if (declaredType) {
|
14781
14819
|
// Apply enum transform if appropriate.
|
14782
14820
|
if (declaration.node.nodeType === 38 /* ParseNodeType.Name */) {
|
14783
|
-
|
14784
|
-
|
14821
|
+
const variableNode = (_c = ParseTreeUtils.getParentNodeOfType(declaration.node, 3 /* ParseNodeType.Assignment */)) !== null && _c !== void 0 ? _c : ParseTreeUtils.getParentNodeOfType(declaration.node, 54 /* ParseNodeType.TypeAnnotation */);
|
14822
|
+
if (variableNode) {
|
14823
|
+
declaredType =
|
14824
|
+
(_d = (0, enums_1.transformTypeForPossibleEnumClass)(evaluatorInterface, variableNode, declaration.node, () => declaredType)) !== null && _d !== void 0 ? _d : declaredType;
|
14825
|
+
}
|
14785
14826
|
}
|
14786
14827
|
if ((0, types_1.isClassInstance)(declaredType) && types_1.ClassType.isBuiltIn(declaredType, 'TypeAlias')) {
|
14787
14828
|
return { type: undefined, isTypeAlias: true };
|
@@ -14811,7 +14852,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14811
14852
|
}
|
14812
14853
|
const runtimeType = getTypingType(node, runtimeClassName);
|
14813
14854
|
const runtimeClass = runtimeType && (0, types_1.isInstantiableClass)(runtimeType) ? runtimeType : undefined;
|
14814
|
-
let typeVar = types_1.TypeVarType.createInstantiable(node.name.value, node.typeParamCategory === parseNodes_1.TypeParameterCategory.ParamSpec
|
14855
|
+
let typeVar = types_1.TypeVarType.createInstantiable(node.name.value, node.typeParamCategory === parseNodes_1.TypeParameterCategory.ParamSpec);
|
14856
|
+
if (runtimeClass) {
|
14857
|
+
typeVar = types_1.TypeBase.cloneAsSpecialForm(typeVar, types_1.ClassType.cloneAsInstance(runtimeClass));
|
14858
|
+
}
|
14815
14859
|
typeVar.details.isTypeParamSyntax = true;
|
14816
14860
|
if (node.typeParamCategory === parseNodes_1.TypeParameterCategory.TypeVarTuple) {
|
14817
14861
|
typeVar.details.isVariadic = true;
|
@@ -14830,12 +14874,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14830
14874
|
ignorePseudoGeneric: true,
|
14831
14875
|
ignoreImplicitTypeArgs: true,
|
14832
14876
|
})) {
|
14833
|
-
addError(localize_1.
|
14877
|
+
addError(localize_1.LocMessage.typeVarBoundGeneric(), constraint);
|
14834
14878
|
}
|
14835
14879
|
return (0, typeUtils_1.convertToInstance)(constraintType);
|
14836
14880
|
});
|
14837
14881
|
if (constraints.length < 2) {
|
14838
|
-
addDiagnostic(
|
14882
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarSingleConstraint(), node.boundExpression);
|
14839
14883
|
}
|
14840
14884
|
else if (node.typeParamCategory === parseNodes_1.TypeParameterCategory.TypeVar) {
|
14841
14885
|
typeVar.details.constraints = constraints;
|
@@ -14844,7 +14888,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14844
14888
|
else {
|
14845
14889
|
const boundType = getTypeOfExpressionExpectingType(node.boundExpression).type;
|
14846
14890
|
if ((0, typeUtils_1.requiresSpecialization)(boundType, { ignorePseudoGeneric: true })) {
|
14847
|
-
addError(localize_1.
|
14891
|
+
addError(localize_1.LocMessage.typeVarConstraintGeneric(), node.boundExpression);
|
14848
14892
|
}
|
14849
14893
|
if (node.typeParamCategory === parseNodes_1.TypeParameterCategory.TypeVar) {
|
14850
14894
|
typeVar.details.boundType = (0, typeUtils_1.convertToInstance)(boundType);
|
@@ -14871,12 +14915,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14871
14915
|
});
|
14872
14916
|
if (typeVar.details.boundType) {
|
14873
14917
|
if (!assignType(typeVar.details.boundType, concreteDefaultType)) {
|
14874
|
-
addDiagnostic(
|
14918
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarDefaultBoundMismatch(), node.defaultExpression);
|
14875
14919
|
}
|
14876
14920
|
}
|
14877
14921
|
else if (typeVar.details.constraints.length > 0) {
|
14878
14922
|
if (!typeVar.details.constraints.some((constraint) => (0, types_1.isTypeSame)(constraint, concreteDefaultType))) {
|
14879
|
-
addDiagnostic(
|
14923
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarDefaultConstraintMismatch(), node.defaultExpression);
|
14880
14924
|
}
|
14881
14925
|
}
|
14882
14926
|
}
|
@@ -14901,7 +14945,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14901
14945
|
return typeVar;
|
14902
14946
|
}
|
14903
14947
|
function getInferredTypeOfDeclaration(symbol, decl) {
|
14904
|
-
var _a, _b, _c;
|
14948
|
+
var _a, _b, _c, _d;
|
14905
14949
|
const resolvedDecl = resolveAliasDeclaration(decl, /* resolveLocalNames */ true, {
|
14906
14950
|
allowExternallyHiddenAccess: AnalyzerNodeInfo.getFileInfo(decl.node).isStubFile,
|
14907
14951
|
});
|
@@ -15025,17 +15069,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15025
15069
|
evaluateTypesForStatement(typeSource);
|
15026
15070
|
})) === null || _c === void 0 ? void 0 : _c.type;
|
15027
15071
|
if (inferredType && resolvedDecl.node.nodeType === 38 /* ParseNodeType.Name */) {
|
15028
|
-
|
15029
|
-
|
15030
|
-
|
15031
|
-
(0,
|
15032
|
-
|
15033
|
-
|
15034
|
-
|
15035
|
-
|
15036
|
-
|
15037
|
-
|
15038
|
-
|
15072
|
+
const variableNode = (_d = ParseTreeUtils.getParentNodeOfType(resolvedDecl.node, 3 /* ParseNodeType.Assignment */)) !== null && _d !== void 0 ? _d : ParseTreeUtils.getParentNodeOfType(resolvedDecl.node, 54 /* ParseNodeType.TypeAnnotation */);
|
15073
|
+
if (variableNode) {
|
15074
|
+
// See if this is an enum member. If so, we need to handle it as a special case.
|
15075
|
+
const enumMemberType = (0, enums_1.transformTypeForPossibleEnumClass)(evaluatorInterface, variableNode, resolvedDecl.node, () => {
|
15076
|
+
var _a, _b;
|
15077
|
+
(0, debug_1.assert)(resolvedDecl.inferredTypeSource !== undefined);
|
15078
|
+
const inferredTypeSource = resolvedDecl.inferredTypeSource;
|
15079
|
+
return ((_b = (_a = evaluateTypeForSubnode(inferredTypeSource, () => {
|
15080
|
+
evaluateTypesForStatement(inferredTypeSource);
|
15081
|
+
})) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.UnknownType.create());
|
15082
|
+
});
|
15083
|
+
if (enumMemberType) {
|
15084
|
+
inferredType = enumMemberType;
|
15085
|
+
}
|
15039
15086
|
}
|
15040
15087
|
}
|
15041
15088
|
if (inferredType && isTypeAlias && resolvedDecl.typeAliasName) {
|
@@ -15738,7 +15785,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15738
15785
|
}
|
15739
15786
|
return types_1.UnknownType.create();
|
15740
15787
|
}
|
15741
|
-
function getTypeOfMemberInternal(member, selfClass) {
|
15788
|
+
function getTypeOfMemberInternal(errorNode, member, selfClass, flags) {
|
15742
15789
|
if ((0, types_1.isInstantiableClass)(member.classType)) {
|
15743
15790
|
const typeResult = getEffectiveTypeOfSymbolForUsage(member.symbol);
|
15744
15791
|
if (typeResult) {
|
@@ -15746,6 +15793,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15746
15793
|
// and cache the return type if necessary. This needs to be done
|
15747
15794
|
// prior to specializing.
|
15748
15795
|
inferReturnTypeIfNecessary(typeResult.type);
|
15796
|
+
if (member.isInstanceMember &&
|
15797
|
+
(flags & 1024 /* MemberAccessFlags.DisallowGenericInstanceVariableAccess */) !== 0) {
|
15798
|
+
let isGenericNonCallable = false;
|
15799
|
+
(0, typeUtils_1.doForEachSubtype)(typeResult.type, (subtype) => {
|
15800
|
+
if (!(0, types_1.isAnyOrUnknown)(subtype) && !(0, types_1.isFunction)(subtype) && !(0, types_1.isOverloadedFunction)(subtype)) {
|
15801
|
+
if ((0, typeUtils_1.requiresSpecialization)(typeResult.type, {
|
15802
|
+
ignoreSelf: true,
|
15803
|
+
ignoreImplicitTypeArgs: true,
|
15804
|
+
})) {
|
15805
|
+
isGenericNonCallable = true;
|
15806
|
+
}
|
15807
|
+
}
|
15808
|
+
});
|
15809
|
+
if (isGenericNonCallable && errorNode) {
|
15810
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.genericInstanceVariableAccess(), errorNode);
|
15811
|
+
}
|
15812
|
+
}
|
15749
15813
|
return {
|
15750
15814
|
type: (0, typeUtils_1.partiallySpecializeType)(typeResult.type, member.classType, selfClass),
|
15751
15815
|
isIncomplete: !!typeResult.isIncomplete,
|
@@ -15776,7 +15840,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15776
15840
|
return false;
|
15777
15841
|
}
|
15778
15842
|
if (types_1.ClassType.isFinal(destType) !== types_1.ClassType.isFinal(srcType)) {
|
15779
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
15843
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typedDictFinalMismatch().format({
|
15780
15844
|
sourceType: printType((0, typeUtils_1.convertToInstance)(srcType)),
|
15781
15845
|
destType: printType((0, typeUtils_1.convertToInstance)(destType)),
|
15782
15846
|
}));
|
@@ -15809,7 +15873,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15809
15873
|
// testing to see if the metaclass matches the protocol.
|
15810
15874
|
if (types_1.ClassType.isProtocolClass(destType) && !isDerivedFrom) {
|
15811
15875
|
if (!(0, protocols_1.assignClassToProtocol)(evaluatorInterface, destType, types_1.ClassType.cloneAsInstance(srcType), diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
|
15812
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
15876
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.protocolIncompatible().format({
|
15813
15877
|
sourceType: printType((0, typeUtils_1.convertToInstance)(srcType)),
|
15814
15878
|
destType: printType((0, typeUtils_1.convertToInstance)(destType)),
|
15815
15879
|
}));
|
@@ -15840,7 +15904,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15840
15904
|
destErrorTypeText = destType.details.fullName;
|
15841
15905
|
srcErrorTypeText = srcType.details.fullName;
|
15842
15906
|
}
|
15843
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
15907
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeIncompatible().format({
|
15844
15908
|
sourceType: srcErrorTypeText,
|
15845
15909
|
destType: destErrorTypeText,
|
15846
15910
|
}));
|
@@ -15848,7 +15912,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15848
15912
|
if (types_1.ClassType.isBuiltIn(destType, 'bytes')) {
|
15849
15913
|
const promotions = typePromotions.get(destType.details.fullName);
|
15850
15914
|
if (promotions && promotions.some((name) => name === srcType.details.fullName)) {
|
15851
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
15915
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.bytesTypePromotions());
|
15852
15916
|
}
|
15853
15917
|
}
|
15854
15918
|
return false;
|
@@ -15858,98 +15922,109 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15858
15922
|
// the type parameters for the base class are honored. This is useful for
|
15859
15923
|
// variance inference (PEP 695). For validation of protocol variance, we
|
15860
15924
|
// want to ignore the variance for all base classes in the class hierarchy.
|
15861
|
-
function assignClassToSelf(destType, srcType, ignoreBaseClassVariance = true, recursionCount = 0) {
|
15925
|
+
function assignClassToSelf(destType, srcType, assumedVariance, ignoreBaseClassVariance = true, recursionCount = 0) {
|
15862
15926
|
(0, debug_1.assert)(types_1.ClassType.isSameGenericClass(destType, srcType));
|
15863
15927
|
(0, debug_1.assert)(destType.details.typeParameters.length > 0);
|
15864
15928
|
const typeVarContext = new typeVarContext_1.TypeVarContext();
|
15865
15929
|
let isAssignable = true;
|
15866
|
-
|
15867
|
-
|
15868
|
-
|
15869
|
-
|
15870
|
-
//
|
15871
|
-
|
15872
|
-
|
15873
|
-
|
15874
|
-
|
15875
|
-
(0, debug_1.assert)(memberInfo !== undefined);
|
15876
|
-
let destMemberType = getEffectiveTypeOfSymbol(symbol);
|
15877
|
-
const srcMemberType = getTypeOfMember(memberInfo);
|
15878
|
-
destMemberType = (0, typeUtils_1.partiallySpecializeType)(destMemberType, destType);
|
15879
|
-
// Properties require special processing.
|
15880
|
-
if ((0, types_1.isClassInstance)(destMemberType) &&
|
15881
|
-
types_1.ClassType.isPropertyClass(destMemberType) &&
|
15882
|
-
(0, types_1.isClassInstance)(srcMemberType) &&
|
15883
|
-
types_1.ClassType.isPropertyClass(srcMemberType)) {
|
15884
|
-
if (!(0, properties_1.assignProperty)(evaluatorInterface, types_1.ClassType.cloneAsInstantiable(destMemberType), types_1.ClassType.cloneAsInstantiable(srcMemberType), destType, srcType,
|
15885
|
-
/* diag */ undefined, typeVarContext,
|
15886
|
-
/* selfTypeVarContext */ undefined, recursionCount)) {
|
15887
|
-
isAssignable = false;
|
15930
|
+
// Use a try/catch block here to make sure that we reset
|
15931
|
+
// the assignClassToSelfClass to undefined if an exception occurs.
|
15932
|
+
try {
|
15933
|
+
// Stash the current class type so any references to it are treated
|
15934
|
+
// as though all TypeParameters are invariant.
|
15935
|
+
assignClassToSelfStack.push({ class: destType, assumedVariance });
|
15936
|
+
destType.details.fields.forEach((symbol, name) => {
|
15937
|
+
if (!isAssignable || symbol.isIgnoredForProtocolMatch()) {
|
15938
|
+
return;
|
15888
15939
|
}
|
15889
|
-
|
15890
|
-
|
15891
|
-
|
15892
|
-
|
15893
|
-
|
15894
|
-
|
15895
|
-
|
15896
|
-
|
15897
|
-
|
15898
|
-
|
15899
|
-
|
15900
|
-
|
15901
|
-
|
15940
|
+
// Constructor methods are exempt from variance calculations.
|
15941
|
+
if (name === '__new__' || name === '__init__') {
|
15942
|
+
return;
|
15943
|
+
}
|
15944
|
+
const memberInfo = (0, typeUtils_1.lookUpClassMember)(srcType, name);
|
15945
|
+
(0, debug_1.assert)(memberInfo !== undefined);
|
15946
|
+
let destMemberType = getEffectiveTypeOfSymbol(symbol);
|
15947
|
+
const srcMemberType = getTypeOfMember(memberInfo);
|
15948
|
+
destMemberType = (0, typeUtils_1.partiallySpecializeType)(destMemberType, destType);
|
15949
|
+
// Properties require special processing.
|
15950
|
+
if ((0, types_1.isClassInstance)(destMemberType) &&
|
15951
|
+
types_1.ClassType.isPropertyClass(destMemberType) &&
|
15952
|
+
(0, types_1.isClassInstance)(srcMemberType) &&
|
15953
|
+
types_1.ClassType.isPropertyClass(srcMemberType)) {
|
15954
|
+
if (!(0, properties_1.assignProperty)(evaluatorInterface, types_1.ClassType.cloneAsInstantiable(destMemberType), types_1.ClassType.cloneAsInstantiable(srcMemberType), destType, srcType,
|
15955
|
+
/* diag */ undefined, typeVarContext,
|
15956
|
+
/* selfTypeVarContext */ undefined, recursionCount)) {
|
15957
|
+
isAssignable = false;
|
15902
15958
|
}
|
15903
15959
|
}
|
15904
|
-
|
15905
|
-
|
15906
|
-
|
15907
|
-
|
15960
|
+
else {
|
15961
|
+
const primaryDecl = symbol.getDeclarations()[0];
|
15962
|
+
let flags = 0 /* AssignTypeFlags.Default */;
|
15963
|
+
if ((primaryDecl === null || primaryDecl === void 0 ? void 0 : primaryDecl.type) === 1 /* DeclarationType.Variable */ &&
|
15964
|
+
!isFinalVariableDeclaration(primaryDecl) &&
|
15965
|
+
!types_1.ClassType.isFrozenDataClass(destType)) {
|
15966
|
+
// Class and instance variables that are mutable need to
|
15967
|
+
// enforce invariance. We will exempt variables that are
|
15968
|
+
// private or protected, since these are presumably
|
15969
|
+
// not modifiable outside of the class.
|
15970
|
+
if (!(0, symbolNameUtils_1.isPrivateOrProtectedName)(name)) {
|
15971
|
+
flags |= 1 /* AssignTypeFlags.EnforceInvariance */;
|
15972
|
+
}
|
15973
|
+
}
|
15974
|
+
if (!assignType(destMemberType, srcMemberType,
|
15975
|
+
/* diag */ undefined, typeVarContext,
|
15976
|
+
/* srcTypeVarContext */ undefined, flags | 65536 /* AssignTypeFlags.IgnoreSelfClsParamCompatibility */, recursionCount)) {
|
15977
|
+
isAssignable = false;
|
15978
|
+
}
|
15908
15979
|
}
|
15980
|
+
});
|
15981
|
+
if (!isAssignable) {
|
15982
|
+
return false;
|
15909
15983
|
}
|
15910
|
-
|
15911
|
-
|
15912
|
-
|
15913
|
-
|
15914
|
-
|
15915
|
-
|
15916
|
-
|
15917
|
-
|
15918
|
-
|
15919
|
-
|
15920
|
-
|
15921
|
-
|
15922
|
-
|
15923
|
-
|
15924
|
-
|
15925
|
-
|
15926
|
-
|
15927
|
-
|
15928
|
-
|
15929
|
-
|
15930
|
-
|
15931
|
-
|
15932
|
-
|
15933
|
-
|
15934
|
-
if (paramVariance === 2 /* Variance.Invariant */ || paramVariance === 4 /* Variance.Contravariant */) {
|
15935
|
-
isAssignable = false;
|
15984
|
+
// Now handle generic base classes.
|
15985
|
+
destType.details.baseClasses.forEach((baseClass) => {
|
15986
|
+
if ((0, types_1.isInstantiableClass)(baseClass) &&
|
15987
|
+
!types_1.ClassType.isBuiltIn(baseClass, 'object') &&
|
15988
|
+
!types_1.ClassType.isBuiltIn(baseClass, 'Protocol') &&
|
15989
|
+
!types_1.ClassType.isBuiltIn(baseClass, 'Generic') &&
|
15990
|
+
baseClass.details.typeParameters.length > 0) {
|
15991
|
+
const specializedDestBaseClass = (0, typeUtils_1.specializeForBaseClass)(destType, baseClass);
|
15992
|
+
const specializedSrcBaseClass = (0, typeUtils_1.specializeForBaseClass)(srcType, baseClass);
|
15993
|
+
if (!ignoreBaseClassVariance) {
|
15994
|
+
specializedDestBaseClass.details.typeParameters.forEach((param, index) => {
|
15995
|
+
if (!param.details.isParamSpec &&
|
15996
|
+
!param.details.isVariadic &&
|
15997
|
+
!param.details.isSynthesized &&
|
15998
|
+
specializedSrcBaseClass.typeArguments &&
|
15999
|
+
index < specializedSrcBaseClass.typeArguments.length &&
|
16000
|
+
specializedDestBaseClass.typeArguments &&
|
16001
|
+
index < specializedDestBaseClass.typeArguments.length) {
|
16002
|
+
const paramVariance = param.details.declaredVariance;
|
16003
|
+
if ((0, types_1.isTypeVar)(specializedSrcBaseClass.typeArguments[index])) {
|
16004
|
+
if (paramVariance === 2 /* Variance.Invariant */ ||
|
16005
|
+
paramVariance === 4 /* Variance.Contravariant */) {
|
16006
|
+
isAssignable = false;
|
16007
|
+
}
|
15936
16008
|
}
|
15937
|
-
|
15938
|
-
|
15939
|
-
|
15940
|
-
|
16009
|
+
else if ((0, types_1.isTypeVar)(specializedDestBaseClass.typeArguments[index])) {
|
16010
|
+
if (paramVariance === 2 /* Variance.Invariant */ || paramVariance === 3 /* Variance.Covariant */) {
|
16011
|
+
isAssignable = false;
|
16012
|
+
}
|
15941
16013
|
}
|
15942
16014
|
}
|
15943
|
-
}
|
15944
|
-
}
|
15945
|
-
|
15946
|
-
|
15947
|
-
|
15948
|
-
|
16015
|
+
});
|
16016
|
+
}
|
16017
|
+
if (isAssignable &&
|
16018
|
+
!assignClassToSelf(specializedDestBaseClass, specializedSrcBaseClass, assumedVariance, ignoreBaseClassVariance, recursionCount)) {
|
16019
|
+
isAssignable = false;
|
16020
|
+
}
|
15949
16021
|
}
|
15950
|
-
}
|
15951
|
-
|
15952
|
-
|
16022
|
+
});
|
16023
|
+
return isAssignable;
|
16024
|
+
}
|
16025
|
+
finally {
|
16026
|
+
assignClassToSelfStack.pop();
|
16027
|
+
}
|
15953
16028
|
}
|
15954
16029
|
// Adjusts the source and/or dest type arguments list to attempt to match
|
15955
16030
|
// the length of the src type arguments list if the dest or source contain
|
@@ -15959,9 +16034,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15959
16034
|
const destUnboundedOrVariadicIndex = destTypeArgs.findIndex((t) => t.isUnbounded || (0, types_1.isVariadicTypeVar)(t.type));
|
15960
16035
|
const srcUnboundedIndex = srcTypeArgs.findIndex((t) => t.isUnbounded);
|
15961
16036
|
const srcVariadicIndex = srcTypeArgs.findIndex((t) => (0, types_1.isVariadicTypeVar)(t.type));
|
16037
|
+
let isSrcVariadicAny = false;
|
15962
16038
|
// If the src contains an unbounded type but the dest does not, it's incompatible.
|
15963
16039
|
if (srcUnboundedIndex >= 0 && destUnboundedOrVariadicIndex < 0) {
|
15964
|
-
|
16040
|
+
// Unless the source contains an [Any, ...].
|
16041
|
+
if ((0, types_1.isAnyOrUnknown)(srcTypeArgs[srcUnboundedIndex].type)) {
|
16042
|
+
isSrcVariadicAny = true;
|
16043
|
+
}
|
16044
|
+
else {
|
16045
|
+
return false;
|
16046
|
+
}
|
15965
16047
|
}
|
15966
16048
|
if (srcUnboundedIndex >= 0) {
|
15967
16049
|
// The source is unbounded, so expand the unbounded argument to try
|
@@ -15970,6 +16052,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15970
16052
|
while (srcTypeArgs.length < destTypeArgs.length) {
|
15971
16053
|
srcTypeArgs.splice(srcUnboundedIndex, 0, { type: typeToReplicate, isUnbounded: true });
|
15972
16054
|
}
|
16055
|
+
if (isSrcVariadicAny && srcTypeArgs.length > destTypeArgs.length) {
|
16056
|
+
srcTypeArgs.splice(srcUnboundedIndex, 1);
|
16057
|
+
}
|
15973
16058
|
}
|
15974
16059
|
// Remove any optional parameters from the end of the two lists until the lengths match.
|
15975
16060
|
while (srcTypeArgs.length > destTypeArgs.length && srcTypeArgs[srcTypeArgs.length - 1].isOptional) {
|
@@ -16049,7 +16134,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16049
16134
|
const entryDiag = diag === null || diag === void 0 ? void 0 : diag.createAddendum();
|
16050
16135
|
if (!assignType(destTypeArgs[argIndex].type, srcTypeArgs[argIndex].type, entryDiag === null || entryDiag === void 0 ? void 0 : entryDiag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
|
16051
16136
|
if (entryDiag) {
|
16052
|
-
entryDiag.addMessage(localize_1.
|
16137
|
+
entryDiag.addMessage(localize_1.LocAddendum.tupleEntryTypeMismatch().format({
|
16053
16138
|
entry: argIndex + 1,
|
16054
16139
|
}));
|
16055
16140
|
}
|
@@ -16059,12 +16144,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16059
16144
|
}
|
16060
16145
|
else {
|
16061
16146
|
if (srcTypeArgs.find((t) => t.isUnbounded)) {
|
16062
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
16147
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.tupleSizeIndeterminate().format({
|
16063
16148
|
expected: destTypeArgs.length,
|
16064
16149
|
}));
|
16065
16150
|
}
|
16066
16151
|
else {
|
16067
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
16152
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.tupleSizeMismatch().format({
|
16068
16153
|
expected: destTypeArgs.length,
|
16069
16154
|
received: srcTypeArgs.length,
|
16070
16155
|
}));
|
@@ -16180,6 +16265,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16180
16265
|
const destTypeParams = types_1.ClassType.getTypeParameters(destType);
|
16181
16266
|
let destTypeArgs;
|
16182
16267
|
let srcTypeArgs;
|
16268
|
+
// Are we performing protocol variance validation for this class? If so,
|
16269
|
+
// treat all of the type parameters as invariant even if they are declared
|
16270
|
+
// otherwise.
|
16271
|
+
const assignClassToSelfInfo = assignClassToSelfStack.find((info) => types_1.ClassType.isSameGenericClass(info.class, destType));
|
16272
|
+
const assumedVariance = assignClassToSelfInfo === null || assignClassToSelfInfo === void 0 ? void 0 : assignClassToSelfInfo.assumedVariance;
|
16183
16273
|
// If either source or dest type arguments are missing, they are
|
16184
16274
|
// treated as "Any", so they are assumed to be assignable.
|
16185
16275
|
if (!destType.typeArguments || !srcType.typeArguments) {
|
@@ -16202,22 +16292,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16202
16292
|
const destTypeArg = destArgIndex >= 0 ? destTypeArgs[destArgIndex] : types_1.UnknownType.create();
|
16203
16293
|
const destTypeParam = destArgIndex < destTypeParams.length ? destTypeParams[destArgIndex] : undefined;
|
16204
16294
|
const assignmentDiag = new diagnostic_1.DiagnosticAddendum();
|
16205
|
-
const variance = destTypeParam ? types_1.TypeVarType.getVariance(destTypeParam) : 3 /* Variance.Covariant
|
16295
|
+
const variance = assumedVariance !== null && assumedVariance !== void 0 ? assumedVariance : (destTypeParam ? types_1.TypeVarType.getVariance(destTypeParam) : 3 /* Variance.Covariant */);
|
16206
16296
|
let effectiveFlags;
|
16207
16297
|
let errorSource;
|
16208
16298
|
let includeDiagAddendum = true;
|
16209
16299
|
if (variance === 3 /* Variance.Covariant */) {
|
16210
16300
|
effectiveFlags = flags | 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */;
|
16211
|
-
errorSource = localize_1.
|
16301
|
+
errorSource = localize_1.LocAddendum.typeVarIsCovariant;
|
16212
16302
|
}
|
16213
16303
|
else if (variance === 4 /* Variance.Contravariant */) {
|
16214
16304
|
effectiveFlags =
|
16215
16305
|
(flags ^ 2 /* AssignTypeFlags.ReverseTypeVarMatching */) | 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */;
|
16216
|
-
errorSource = localize_1.
|
16306
|
+
errorSource = localize_1.LocAddendum.typeVarIsContravariant;
|
16217
16307
|
}
|
16218
16308
|
else {
|
16219
16309
|
effectiveFlags = flags | 1 /* AssignTypeFlags.EnforceInvariance */ | 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */;
|
16220
|
-
errorSource = localize_1.
|
16310
|
+
errorSource = localize_1.LocAddendum.typeVarIsInvariant;
|
16221
16311
|
// Omit the diagnostic addendum for the invariant case because it's obvious
|
16222
16312
|
// why two types are not the same.
|
16223
16313
|
includeDiagAddendum = false;
|
@@ -16239,13 +16329,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16239
16329
|
if (isCompatible && types_1.ClassType.isSameGenericClass(destType, srcType)) {
|
16240
16330
|
// Add additional notes to help the user if this is a common type mismatch.
|
16241
16331
|
if (types_1.ClassType.isBuiltIn(destType, 'dict') && srcArgIndex === 1) {
|
16242
|
-
childDiag.addMessage(localize_1.
|
16332
|
+
childDiag.addMessage(localize_1.LocAddendum.invariantSuggestionDict());
|
16243
16333
|
}
|
16244
16334
|
else if (types_1.ClassType.isBuiltIn(destType, 'list')) {
|
16245
|
-
childDiag.addMessage(localize_1.
|
16335
|
+
childDiag.addMessage(localize_1.LocAddendum.invariantSuggestionList());
|
16246
16336
|
}
|
16247
16337
|
else if (types_1.ClassType.isBuiltIn(destType, 'set')) {
|
16248
|
-
childDiag.addMessage(localize_1.
|
16338
|
+
childDiag.addMessage(localize_1.LocAddendum.invariantSuggestionSet());
|
16249
16339
|
}
|
16250
16340
|
}
|
16251
16341
|
}
|
@@ -16477,7 +16567,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16477
16567
|
return true;
|
16478
16568
|
}
|
16479
16569
|
if (!(0, types_1.isUnion)(destType)) {
|
16480
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
16570
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
|
16481
16571
|
return false;
|
16482
16572
|
}
|
16483
16573
|
}
|
@@ -16570,7 +16660,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16570
16660
|
if (assignType(destType, (0, typeUtils_1.convertToInstantiable)(typeTypeArg), diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
|
16571
16661
|
return true;
|
16572
16662
|
}
|
16573
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
16663
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
|
16574
16664
|
return false;
|
16575
16665
|
}
|
16576
16666
|
}
|
@@ -16583,7 +16673,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16583
16673
|
if (types_1.ClassType.isProtocolClass(expandedSrcType) &&
|
16584
16674
|
(0, types_1.isInstantiableClass)(srcType) &&
|
16585
16675
|
!srcType.includeSubclasses) {
|
16586
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
16676
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.protocolSourceIsNotConcrete().format({
|
16587
16677
|
sourceType: printType((0, typeUtils_1.convertToInstance)(srcType)),
|
16588
16678
|
destType: printType(destType),
|
16589
16679
|
}));
|
@@ -16595,7 +16685,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16595
16685
|
/* reportErrorsUsingObjType */ false)) {
|
16596
16686
|
return true;
|
16597
16687
|
}
|
16598
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
16688
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
|
16599
16689
|
return false;
|
16600
16690
|
}
|
16601
16691
|
else if ((0, types_1.isClassInstance)(expandedSrcType) && (0, typeUtils_1.isMetaclassInstance)(expandedSrcType)) {
|
@@ -16607,7 +16697,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16607
16697
|
/* reportErrorsUsingObjType */ false)) {
|
16608
16698
|
return true;
|
16609
16699
|
}
|
16610
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
16700
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
|
16611
16701
|
return false;
|
16612
16702
|
}
|
16613
16703
|
}
|
@@ -16646,7 +16736,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16646
16736
|
if (destType.literalValue !== undefined) {
|
16647
16737
|
const srcLiteral = concreteSrcType.literalValue;
|
16648
16738
|
if (srcLiteral === undefined || !types_1.ClassType.isLiteralValueSame(concreteSrcType, destType)) {
|
16649
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
16739
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.literalAssignmentMismatch().format({
|
16650
16740
|
sourceType: printType(srcType),
|
16651
16741
|
destType: printType(destType),
|
16652
16742
|
}));
|
@@ -16768,7 +16858,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16768
16858
|
}
|
16769
16859
|
});
|
16770
16860
|
if (filteredOverloads.length === 0) {
|
16771
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
16861
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.noOverloadAssignable().format({ type: printType(destType) }));
|
16772
16862
|
return false;
|
16773
16863
|
}
|
16774
16864
|
if (destTypeVarContext) {
|
@@ -16813,7 +16903,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16813
16903
|
});
|
16814
16904
|
if (!isAssignable) {
|
16815
16905
|
if (overloadDiag) {
|
16816
|
-
overloadDiag.addMessage(localize_1.
|
16906
|
+
overloadDiag.addMessage(localize_1.LocAddendum.overloadNotAssignable().format({
|
16817
16907
|
name: destType.overloads[0].details.name,
|
16818
16908
|
}));
|
16819
16909
|
}
|
@@ -16836,10 +16926,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16836
16926
|
}
|
16837
16927
|
}
|
16838
16928
|
if ((0, typeUtils_1.isNoneInstance)(destType)) {
|
16839
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
16929
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.assignToNone());
|
16840
16930
|
return false;
|
16841
16931
|
}
|
16842
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
16932
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
|
16843
16933
|
return false;
|
16844
16934
|
}
|
16845
16935
|
function assignFromUnionType(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount) {
|
@@ -17014,7 +17104,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17014
17104
|
if ((flags & 32 /* AssignTypeFlags.PartialOverloadOverlapCheck */) !== 0 && matchedSomeSubtypes) {
|
17015
17105
|
return true;
|
17016
17106
|
}
|
17017
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
17107
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
|
17018
17108
|
return false;
|
17019
17109
|
}
|
17020
17110
|
return true;
|
@@ -17105,7 +17195,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17105
17195
|
}
|
17106
17196
|
});
|
17107
17197
|
if (isIncompatible) {
|
17108
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
17198
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
|
17109
17199
|
return false;
|
17110
17200
|
}
|
17111
17201
|
return true;
|
@@ -17185,7 +17275,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17185
17275
|
}
|
17186
17276
|
if (!foundMatch) {
|
17187
17277
|
if (diag && diagAddendum) {
|
17188
|
-
diag.addMessage(localize_1.
|
17278
|
+
diag.addMessage(localize_1.LocAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
|
17189
17279
|
diag.addAddendum(diagAddendum);
|
17190
17280
|
}
|
17191
17281
|
return false;
|
@@ -17308,7 +17398,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17308
17398
|
// of the lambda itself.
|
17309
17399
|
if (!(0, types_1.isTypeSame)(destType, srcType)) {
|
17310
17400
|
if (diag && paramIndex !== undefined) {
|
17311
|
-
diag.addMessage(localize_1.
|
17401
|
+
diag.addMessage(localize_1.LocAddendum.paramAssignment().format({
|
17312
17402
|
index: paramIndex + 1,
|
17313
17403
|
sourceType: printType(destType),
|
17314
17404
|
destType: printType(srcType),
|
@@ -17420,6 +17510,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17420
17510
|
const positionalsToMatch = Math.min(destPositionalCount, srcPositionalCount);
|
17421
17511
|
// Match positional parameters.
|
17422
17512
|
for (let paramIndex = 0; paramIndex < positionalsToMatch; paramIndex++) {
|
17513
|
+
if (paramIndex === 0 &&
|
17514
|
+
destType.details.methodClass &&
|
17515
|
+
(flags & 65536 /* AssignTypeFlags.IgnoreSelfClsParamCompatibility */) !== 0) {
|
17516
|
+
if (types_1.FunctionType.isInstanceMethod(destType) || types_1.FunctionType.isClassMethod(destType)) {
|
17517
|
+
continue;
|
17518
|
+
}
|
17519
|
+
}
|
17423
17520
|
// Skip over the *args parameter since it's handled separately below.
|
17424
17521
|
if (paramIndex === destParamDetails.argsIndex) {
|
17425
17522
|
continue;
|
@@ -17438,13 +17535,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17438
17535
|
destParam.param.category !== 1 /* ParameterCategory.ArgsList */ &&
|
17439
17536
|
srcParam.param.category !== 1 /* ParameterCategory.ArgsList */) {
|
17440
17537
|
if (srcParam.source === parameterUtils_1.ParameterSource.PositionOnly) {
|
17441
|
-
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.
|
17538
|
+
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.functionParamPositionOnly().format({
|
17442
17539
|
name: destParamName,
|
17443
17540
|
}));
|
17444
17541
|
canAssign = false;
|
17445
17542
|
}
|
17446
17543
|
else if (destParamName !== srcParamName) {
|
17447
|
-
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.
|
17544
|
+
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.functionParamName().format({
|
17448
17545
|
srcName: srcParamName,
|
17449
17546
|
destName: destParamName,
|
17450
17547
|
}));
|
@@ -17455,7 +17552,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17455
17552
|
if (!!destParam.param.hasDefault &&
|
17456
17553
|
!srcParam.param.hasDefault &&
|
17457
17554
|
paramIndex !== srcParamDetails.argsIndex) {
|
17458
|
-
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.
|
17555
|
+
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.functionParamDefaultMissing().format({
|
17459
17556
|
name: srcParamName,
|
17460
17557
|
}));
|
17461
17558
|
canAssign = false;
|
@@ -17484,7 +17581,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17484
17581
|
if (!types_1.FunctionType.shouldSkipArgsKwargsCompatibilityCheck(destType) &&
|
17485
17582
|
destParamDetails.firstPositionOrKeywordIndex < srcParamDetails.positionOnlyParamCount &&
|
17486
17583
|
!targetIncludesParamSpec) {
|
17487
|
-
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.
|
17584
|
+
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.argsPositionOnly().format({
|
17488
17585
|
expected: srcParamDetails.positionOnlyParamCount,
|
17489
17586
|
received: destParamDetails.firstPositionOrKeywordIndex,
|
17490
17587
|
}));
|
@@ -17499,7 +17596,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17499
17596
|
if (destPositionalCount < nonDefaultSrcParamCount) {
|
17500
17597
|
if (destParamDetails.firstPositionOrKeywordIndex > 0 &&
|
17501
17598
|
destParamDetails.firstPositionOrKeywordIndex < srcPositionalCount) {
|
17502
|
-
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.
|
17599
|
+
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.functionTooFewParams().format({
|
17503
17600
|
expected: nonDefaultSrcParamCount,
|
17504
17601
|
received: destPositionalCount,
|
17505
17602
|
}));
|
@@ -17533,7 +17630,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17533
17630
|
}
|
17534
17631
|
const destParamType = destParamDetails.params[paramIndex].type;
|
17535
17632
|
if ((0, types_1.isVariadicTypeVar)(destParamType) && !(0, types_1.isVariadicTypeVar)(srcArgsType)) {
|
17536
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
17633
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeVarTupleRequiresKnownLength());
|
17537
17634
|
canAssign = false;
|
17538
17635
|
}
|
17539
17636
|
else {
|
@@ -17542,7 +17639,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17542
17639
|
}
|
17543
17640
|
if (destParamDetails.params[paramIndex].source !== parameterUtils_1.ParameterSource.PositionOnly &&
|
17544
17641
|
srcParamDetails.kwargsIndex === undefined) {
|
17545
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
17642
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.namedParamMissingInSource().format({
|
17546
17643
|
name: (_e = destParamDetails.params[paramIndex].param.name) !== null && _e !== void 0 ? _e : '',
|
17547
17644
|
}));
|
17548
17645
|
canAssign = false;
|
@@ -17558,7 +17655,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17558
17655
|
adjDestPositionalCount--;
|
17559
17656
|
}
|
17560
17657
|
if (srcPositionalCount < adjDestPositionalCount) {
|
17561
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
17658
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.functionTooManyParams().format({
|
17562
17659
|
expected: srcPositionalCount,
|
17563
17660
|
received: destPositionalCount,
|
17564
17661
|
}));
|
@@ -17594,7 +17691,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17594
17691
|
srcType.details.paramSpec === undefined &&
|
17595
17692
|
destParamDetails.argsIndex !== undefined &&
|
17596
17693
|
!destParamDetails.hasUnpackedVariadicTypeVar) {
|
17597
|
-
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.
|
17694
|
+
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.argsParamMissing().format({
|
17598
17695
|
paramName: (_f = destParamDetails.params[destParamDetails.argsIndex].param.name) !== null && _f !== void 0 ? _f : '',
|
17599
17696
|
}));
|
17600
17697
|
canAssign = false;
|
@@ -17630,7 +17727,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17630
17727
|
if (!destParamInfo) {
|
17631
17728
|
if (destParamDetails.kwargsIndex === undefined && !srcParamInfo.param.hasDefault) {
|
17632
17729
|
if (paramDiag && srcParamDetails.firstKeywordOnlyIndex !== undefined) {
|
17633
|
-
paramDiag.addMessage(localize_1.
|
17730
|
+
paramDiag.addMessage(localize_1.LocAddendum.namedParamMissingInDest().format({
|
17634
17731
|
name: srcParamInfo.param.name,
|
17635
17732
|
}));
|
17636
17733
|
}
|
@@ -17651,7 +17748,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17651
17748
|
if (!assignFunctionParameter(destParamInfo.type, srcParamType,
|
17652
17749
|
/* paramIndex */ undefined, paramDiag === null || paramDiag === void 0 ? void 0 : paramDiag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
|
17653
17750
|
if (paramDiag) {
|
17654
|
-
paramDiag.addMessage(localize_1.
|
17751
|
+
paramDiag.addMessage(localize_1.LocAddendum.namedParamTypeMismatch().format({
|
17655
17752
|
name: srcParamInfo.param.name,
|
17656
17753
|
sourceType: printType(specializedDestParamType),
|
17657
17754
|
destType: printType(srcParamType),
|
@@ -17660,7 +17757,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17660
17757
|
canAssign = false;
|
17661
17758
|
}
|
17662
17759
|
if (!!destParamInfo.param.hasDefault && !srcParamInfo.param.hasDefault) {
|
17663
|
-
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.
|
17760
|
+
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.functionParamDefaultMissing().format({
|
17664
17761
|
name: srcParamInfo.param.name,
|
17665
17762
|
}));
|
17666
17763
|
canAssign = false;
|
@@ -17681,7 +17778,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17681
17778
|
destParamMap.delete(paramName);
|
17682
17779
|
}
|
17683
17780
|
else {
|
17684
|
-
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.
|
17781
|
+
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.namedParamMissingInSource().format({ name: paramName }));
|
17685
17782
|
canAssign = false;
|
17686
17783
|
}
|
17687
17784
|
});
|
@@ -17697,7 +17794,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17697
17794
|
srcParamDetails.kwargsIndex === undefined &&
|
17698
17795
|
srcType.details.paramSpec === undefined &&
|
17699
17796
|
destParamDetails.kwargsIndex !== undefined) {
|
17700
|
-
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.
|
17797
|
+
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.kwargsParamMissing().format({
|
17701
17798
|
paramName: destParamDetails.params[destParamDetails.kwargsIndex].param.name,
|
17702
17799
|
}));
|
17703
17800
|
canAssign = false;
|
@@ -17828,7 +17925,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17828
17925
|
}
|
17829
17926
|
if (!isReturnTypeCompatible) {
|
17830
17927
|
if (returnDiag) {
|
17831
|
-
returnDiag.addMessage(localize_1.
|
17928
|
+
returnDiag.addMessage(localize_1.LocAddendum.functionReturnTypeMismatch().format({
|
17832
17929
|
sourceType: printType(srcReturnType),
|
17833
17930
|
destType: printType(destReturnType),
|
17834
17931
|
}));
|
@@ -17967,7 +18064,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17967
18064
|
// If we're overriding a non-method with a method, report it as an error.
|
17968
18065
|
// This occurs when a non-property overrides a property.
|
17969
18066
|
if (!(0, types_1.isFunction)(baseMethod) && !(0, types_1.isOverloadedFunction)(baseMethod)) {
|
17970
|
-
diag.addMessage(localize_1.
|
18067
|
+
diag.addMessage(localize_1.LocAddendum.overrideType().format({ type: printType(baseMethod) }));
|
17971
18068
|
return false;
|
17972
18069
|
}
|
17973
18070
|
if ((0, types_1.isFunction)(baseMethod)) {
|
@@ -17983,7 +18080,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17983
18080
|
})) {
|
17984
18081
|
return true;
|
17985
18082
|
}
|
17986
|
-
diag.addMessage(localize_1.
|
18083
|
+
diag.addMessage(localize_1.LocAddendum.overrideNoOverloadMatches());
|
17987
18084
|
return false;
|
17988
18085
|
}
|
17989
18086
|
// For a non-overloaded method overriding an overloaded method, the
|
@@ -18028,7 +18125,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18028
18125
|
break;
|
18029
18126
|
}
|
18030
18127
|
if (matchIndex < previousMatchIndex) {
|
18031
|
-
diag.addMessage(localize_1.
|
18128
|
+
diag.addMessage(localize_1.LocAddendum.overrideOverloadOrder());
|
18032
18129
|
return false;
|
18033
18130
|
}
|
18034
18131
|
previousMatchIndex = matchIndex;
|
@@ -18041,7 +18138,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18041
18138
|
return isOverrideMethodApplicable(overload, baseClass);
|
18042
18139
|
})) {
|
18043
18140
|
// We didn't find matches for all of the base overloads.
|
18044
|
-
diag.addMessage(localize_1.
|
18141
|
+
diag.addMessage(localize_1.LocAddendum.overrideOverloadNoMatch());
|
18045
18142
|
return false;
|
18046
18143
|
}
|
18047
18144
|
}
|
@@ -18097,19 +18194,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18097
18194
|
// an incompatible type.
|
18098
18195
|
if (types_1.FunctionType.isStaticMethod(baseMethod)) {
|
18099
18196
|
if (!types_1.FunctionType.isStaticMethod(overrideMethod)) {
|
18100
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
18197
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideNotStaticMethod());
|
18101
18198
|
canOverride = false;
|
18102
18199
|
}
|
18103
18200
|
}
|
18104
18201
|
else if (types_1.FunctionType.isClassMethod(baseMethod)) {
|
18105
18202
|
if (!types_1.FunctionType.isClassMethod(overrideMethod)) {
|
18106
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
18203
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideNotClassMethod());
|
18107
18204
|
canOverride = false;
|
18108
18205
|
}
|
18109
18206
|
}
|
18110
18207
|
else if (types_1.FunctionType.isInstanceMethod(baseMethod)) {
|
18111
18208
|
if (!types_1.FunctionType.isInstanceMethod(overrideMethod)) {
|
18112
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
18209
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideNotInstanceMethod());
|
18113
18210
|
canOverride = false;
|
18114
18211
|
}
|
18115
18212
|
}
|
@@ -18124,7 +18221,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18124
18221
|
const overrideArgsType = overrideParamDetails.params[overrideParamDetails.argsIndex].type;
|
18125
18222
|
for (let i = overrideParamDetails.positionParamCount; i < baseParamDetails.positionParamCount; i++) {
|
18126
18223
|
if (!assignType(overrideArgsType, baseParamDetails.params[i].type, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overrideMethod)), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(baseMethod)), 8 /* AssignTypeFlags.SkipSolveTypeVars */)) {
|
18127
|
-
localize_1.
|
18224
|
+
localize_1.LocAddendum.overrideParamType().format({
|
18128
18225
|
index: i + 1,
|
18129
18226
|
baseType: printType(baseParamDetails.params[i].type),
|
18130
18227
|
overrideType: printType(overrideArgsType),
|
@@ -18148,7 +18245,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18148
18245
|
}
|
18149
18246
|
}
|
18150
18247
|
if (foundParamCountMismatch) {
|
18151
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
18248
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overridePositionalParamCount().format({
|
18152
18249
|
baseCount: baseParamDetails.params.length,
|
18153
18250
|
overrideCount: overrideParamDetails.params.length,
|
18154
18251
|
}));
|
@@ -18176,13 +18273,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18176
18273
|
if (overrideParam.category === 0 /* ParameterCategory.Simple */) {
|
18177
18274
|
if (enforceParamNames && !baseParam.isNameSynthesized) {
|
18178
18275
|
if (overrideParamDetails.params[i].source === parameterUtils_1.ParameterSource.PositionOnly) {
|
18179
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
18276
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamNamePositionOnly().format({
|
18180
18277
|
index: i + 1,
|
18181
18278
|
baseName: baseParam.name || '*',
|
18182
18279
|
}));
|
18183
18280
|
}
|
18184
18281
|
else {
|
18185
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
18282
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamName().format({
|
18186
18283
|
index: i + 1,
|
18187
18284
|
baseName: baseParam.name || '*',
|
18188
18285
|
overrideName: overrideParam.name || '*',
|
@@ -18196,7 +18293,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18196
18293
|
i >= baseParamDetails.positionOnlyParamCount) {
|
18197
18294
|
if (!baseParam.isNameSynthesized &&
|
18198
18295
|
baseParamDetails.params[i].source !== parameterUtils_1.ParameterSource.PositionOnly) {
|
18199
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
18296
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamNamePositionOnly().format({
|
18200
18297
|
index: i + 1,
|
18201
18298
|
baseName: baseParam.name || '*',
|
18202
18299
|
}));
|
@@ -18211,7 +18308,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18211
18308
|
if (!exemptSelfClsParam || (!baseIsSynthesizedTypeVar && !overrideIsSynthesizedTypeVar)) {
|
18212
18309
|
if (baseParam.category !== overrideParam.category ||
|
18213
18310
|
!assignType(overrideParamType, baseParamType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overrideMethod)), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(baseMethod)), 8 /* AssignTypeFlags.SkipSolveTypeVars */)) {
|
18214
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
18311
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamType().format({
|
18215
18312
|
index: i + 1,
|
18216
18313
|
baseType: printType(baseParamType),
|
18217
18314
|
overrideType: printType(overrideParamType),
|
@@ -18221,7 +18318,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18221
18318
|
}
|
18222
18319
|
if (baseParamDetails.params[i].param.hasDefault &&
|
18223
18320
|
!overrideParamDetails.params[i].param.hasDefault) {
|
18224
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
18321
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamNoDefault().format({
|
18225
18322
|
index: i + 1,
|
18226
18323
|
}));
|
18227
18324
|
canOverride = false;
|
@@ -18231,7 +18328,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18231
18328
|
// Check for a *args match.
|
18232
18329
|
if (baseParamDetails.argsIndex !== undefined) {
|
18233
18330
|
if (overrideParamDetails.argsIndex === undefined) {
|
18234
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
18331
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamNameMissing().format({
|
18235
18332
|
name: (_a = baseParamDetails.params[baseParamDetails.argsIndex].param.name) !== null && _a !== void 0 ? _a : '?',
|
18236
18333
|
}));
|
18237
18334
|
canOverride = false;
|
@@ -18241,7 +18338,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18241
18338
|
const baseParamType = baseParamDetails.params[baseParamDetails.argsIndex].type;
|
18242
18339
|
if (!assignType(overrideParamType, baseParamType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overrideMethod)),
|
18243
18340
|
/* srcTypeVarContext */ undefined, 8 /* AssignTypeFlags.SkipSolveTypeVars */)) {
|
18244
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
18341
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamKeywordType().format({
|
18245
18342
|
name: (_b = overrideParamDetails.params[overrideParamDetails.argsIndex].param.name) !== null && _b !== void 0 ? _b : '?',
|
18246
18343
|
baseType: printType(baseParamType),
|
18247
18344
|
overrideType: printType(overrideParamType),
|
@@ -18259,7 +18356,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18259
18356
|
var _a, _b, _c;
|
18260
18357
|
const overrideParamInfo = overrideKwOnlyParams.find((pi) => paramInfo.param.name === pi.param.name);
|
18261
18358
|
if (!overrideParamInfo && overrideParamDetails.kwargsIndex === undefined) {
|
18262
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
18359
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamNameMissing().format({
|
18263
18360
|
name: (_a = paramInfo.param.name) !== null && _a !== void 0 ? _a : '?',
|
18264
18361
|
}));
|
18265
18362
|
canOverride = false;
|
@@ -18270,7 +18367,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18270
18367
|
targetParamType = overrideParamDetails.params[overrideParamDetails.kwargsIndex].type;
|
18271
18368
|
}
|
18272
18369
|
if (!assignType(targetParamType, paramInfo.type, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overrideMethod)), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(baseMethod)), 8 /* AssignTypeFlags.SkipSolveTypeVars */)) {
|
18273
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
18370
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamKeywordType().format({
|
18274
18371
|
name: (_b = paramInfo.param.name) !== null && _b !== void 0 ? _b : '?',
|
18275
18372
|
baseType: printType(paramInfo.type),
|
18276
18373
|
overrideType: printType(targetParamType),
|
@@ -18279,7 +18376,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18279
18376
|
}
|
18280
18377
|
if (overrideParamInfo) {
|
18281
18378
|
if (paramInfo.param.hasDefault && !overrideParamInfo.param.hasDefault) {
|
18282
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
18379
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamKeywordNoDefault().format({
|
18283
18380
|
name: (_c = overrideParamInfo.param.name) !== null && _c !== void 0 ? _c : '?',
|
18284
18381
|
}));
|
18285
18382
|
canOverride = false;
|
@@ -18295,7 +18392,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18295
18392
|
if (!baseParamInfo) {
|
18296
18393
|
if (baseParamDetails.kwargsIndex === undefined) {
|
18297
18394
|
if (!paramInfo.param.hasDefault) {
|
18298
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
18395
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamNameExtra().format({
|
18299
18396
|
name: (_a = paramInfo.param.name) !== null && _a !== void 0 ? _a : '?',
|
18300
18397
|
}));
|
18301
18398
|
canOverride = false;
|
@@ -18305,7 +18402,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18305
18402
|
});
|
18306
18403
|
// Verify that if the base method has a **kwargs parameter, the override does too.
|
18307
18404
|
if (baseParamDetails.kwargsIndex !== undefined && overrideParamDetails.kwargsIndex === undefined) {
|
18308
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
18405
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.kwargsParamMissing().format({
|
18309
18406
|
paramName: baseParamDetails.params[baseParamDetails.kwargsIndex].param.name,
|
18310
18407
|
}));
|
18311
18408
|
canOverride = false;
|
@@ -18320,7 +18417,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18320
18417
|
overrideParamDetails.kwargsIndex !== undefined &&
|
18321
18418
|
(0, types_1.isAnyOrUnknown)(overrideParamDetails.params[overrideParamDetails.kwargsIndex].type);
|
18322
18419
|
if (!overrideHasArgsKwargs) {
|
18323
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
18420
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.paramSpecMissingInOverride());
|
18324
18421
|
canOverride = false;
|
18325
18422
|
}
|
18326
18423
|
}
|
@@ -18328,7 +18425,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18328
18425
|
const baseReturnType = getFunctionEffectiveReturnType(baseMethod);
|
18329
18426
|
const overrideReturnType = getFunctionEffectiveReturnType(overrideMethod);
|
18330
18427
|
if (!assignType(baseReturnType, overrideReturnType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(baseMethod)), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overrideMethod)), 8 /* AssignTypeFlags.SkipSolveTypeVars */)) {
|
18331
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
18428
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideReturnType().format({
|
18332
18429
|
baseType: printType(baseReturnType),
|
18333
18430
|
overrideType: printType(overrideReturnType),
|
18334
18431
|
}));
|
@@ -18364,7 +18461,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18364
18461
|
// Avoid adding a message that will confuse users if the TypeVar was
|
18365
18462
|
// synthesized for internal purposes.
|
18366
18463
|
if (!destType.details.isSynthesized) {
|
18367
|
-
diag.addMessage(localize_1.
|
18464
|
+
diag.addMessage(localize_1.LocAddendum.typeBound().format({
|
18368
18465
|
sourceType: printType(effectiveSrcType),
|
18369
18466
|
destType: printType(destType.details.boundType),
|
18370
18467
|
name: types_1.TypeVarType.getReadableName(destType),
|
@@ -18383,14 +18480,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18383
18480
|
if ((0, types_1.isClassInstance)(srcType) && types_1.ClassType.isBuiltIn(srcType, 'Concatenate')) {
|
18384
18481
|
return srcType;
|
18385
18482
|
}
|
18386
|
-
diag.addMessage(localize_1.
|
18483
|
+
diag.addMessage(localize_1.LocAddendum.typeParamSpec().format({
|
18387
18484
|
type: printType(srcType),
|
18388
18485
|
name: types_1.TypeVarType.getReadableName(destType),
|
18389
18486
|
}));
|
18390
18487
|
return undefined;
|
18391
18488
|
}
|
18392
18489
|
if ((0, types_1.isTypeVar)(srcType) && srcType.details.isParamSpec) {
|
18393
|
-
diag.addMessage(localize_1.
|
18490
|
+
diag.addMessage(localize_1.LocMessage.paramSpecContext());
|
18394
18491
|
return undefined;
|
18395
18492
|
}
|
18396
18493
|
// If there are no constraints, we're done.
|
@@ -18424,61 +18521,38 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18424
18521
|
return bestConstraintSoFar;
|
18425
18522
|
}
|
18426
18523
|
}
|
18427
|
-
diag.addMessage(localize_1.
|
18524
|
+
diag.addMessage(localize_1.LocAddendum.typeConstrainedTypeVar().format({
|
18428
18525
|
type: printType(srcType),
|
18429
18526
|
name: types_1.TypeVarType.getReadableName(destType),
|
18430
18527
|
}));
|
18431
18528
|
return undefined;
|
18432
18529
|
}
|
18433
|
-
|
18530
|
+
// Returns a list of unimplemented abstract symbols (methods or variables) for
|
18531
|
+
// the specified class.
|
18532
|
+
function getAbstractSymbols(classType) {
|
18434
18533
|
const symbolTable = new Map();
|
18435
18534
|
types_1.ClassType.getReverseMro(classType).forEach((mroClass) => {
|
18436
18535
|
if ((0, types_1.isInstantiableClass)(mroClass)) {
|
18437
|
-
// See if this class is introducing a new abstract
|
18438
|
-
// introduced previously or if it is overriding an abstract
|
18536
|
+
// See if this class is introducing a new abstract symbol that has not been
|
18537
|
+
// introduced previously or if it is overriding an abstract symbol with
|
18439
18538
|
// a non-abstract one.
|
18440
18539
|
mroClass.details.fields.forEach((symbol, symbolName) => {
|
18441
|
-
|
18442
|
-
|
18443
|
-
|
18444
|
-
|
18445
|
-
|
18446
|
-
|
18447
|
-
// abstract method.
|
18448
|
-
if (symbol.isClassMember() || symbol.isNamedTupleMemberMember()) {
|
18449
|
-
let isAbstract;
|
18450
|
-
const decl = (0, symbolUtils_1.getLastTypedDeclaredForSymbol)(symbol);
|
18451
|
-
if (decl && decl.type === 5 /* DeclarationType.Function */) {
|
18452
|
-
const functionFlags = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, decl.node, true).flags;
|
18453
|
-
isAbstract = !!(functionFlags & 8 /* FunctionTypeFlags.AbstractMethod */);
|
18454
|
-
}
|
18455
|
-
else {
|
18456
|
-
// If a symbol is overridden by a non-function, it is no longer
|
18457
|
-
// considered abstract. This can happen in some code, for example,
|
18458
|
-
// when a base class declares an abstract property and a subclass
|
18459
|
-
// "overrides" it with an instance variable.
|
18460
|
-
isAbstract = false;
|
18461
|
-
}
|
18462
|
-
if (isAbstract) {
|
18463
|
-
symbolTable.set(symbolName, {
|
18464
|
-
symbol,
|
18465
|
-
symbolName,
|
18466
|
-
classType: mroClass,
|
18467
|
-
});
|
18468
|
-
}
|
18469
|
-
else {
|
18470
|
-
symbolTable.delete(symbolName);
|
18471
|
-
}
|
18540
|
+
const abstractSymbolInfo = getAbstractSymbolInfo(mroClass, symbolName);
|
18541
|
+
if (abstractSymbolInfo) {
|
18542
|
+
symbolTable.set(symbolName, abstractSymbolInfo);
|
18543
|
+
}
|
18544
|
+
else {
|
18545
|
+
symbolTable.delete(symbolName);
|
18472
18546
|
}
|
18473
18547
|
});
|
18474
18548
|
}
|
18475
18549
|
});
|
18476
|
-
// Create a final list of
|
18477
|
-
const
|
18550
|
+
// Create a final list of symbols that are abstract.
|
18551
|
+
const symbolList = [];
|
18478
18552
|
symbolTable.forEach((method) => {
|
18479
|
-
|
18553
|
+
symbolList.push(method);
|
18480
18554
|
});
|
18481
|
-
return
|
18555
|
+
return symbolList;
|
18482
18556
|
}
|
18483
18557
|
// If the memberType is an instance or class method, creates a new
|
18484
18558
|
// version of the function that has the "self" or "cls" parameter bound
|
@@ -18553,7 +18627,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18553
18627
|
!memberTypeFirstParam.isNameSynthesized &&
|
18554
18628
|
memberTypeFirstParam.hasDeclaredType) {
|
18555
18629
|
if (diag) {
|
18556
|
-
diag.addMessage(localize_1.
|
18630
|
+
diag.addMessage(localize_1.LocMessage.bindTypeMismatch().format({
|
18557
18631
|
type: printType(baseType),
|
18558
18632
|
methodName: memberType.details.name || '<anonymous>',
|
18559
18633
|
paramName: memberTypeFirstParam.name,
|
@@ -18821,7 +18895,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18821
18895
|
getTypeOfMagicMethodCall,
|
18822
18896
|
bindFunctionToClassOrObject,
|
18823
18897
|
getCallSignatureInfo,
|
18824
|
-
|
18898
|
+
getAbstractSymbols,
|
18825
18899
|
narrowConstrainedTypeVar,
|
18826
18900
|
assignType,
|
18827
18901
|
validateOverrideMethod,
|
@@ -18843,8 +18917,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18843
18917
|
isFinalVariable,
|
18844
18918
|
isFinalVariableDeclaration,
|
18845
18919
|
isExplicitTypeAliasDeclaration,
|
18846
|
-
addError,
|
18847
|
-
addWarning,
|
18848
18920
|
addInformation,
|
18849
18921
|
addUnusedCode,
|
18850
18922
|
addUnreachableCode,
|