@zzzen/pyright-internal 1.2.0-dev.20240114 → 1.2.0-dev.20240128
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 +99 -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 +16 -19
- 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 +839 -762
- 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 +13 -6
- 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 +17 -0
- package/dist/common/configOptions.js +93 -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/diagnosticRules.d.ts +16 -0
- package/dist/common/diagnosticRules.js +16 -0
- package/dist/common/diagnosticRules.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 +4 -5
- package/dist/localization/localize.js +5 -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 +7 -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 +6 -6
- package/dist/tests/typeEvaluator2.test.js +8 -4
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +17 -5
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +3 -3
- 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.reportAssignmentType, 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.reportAssignmentType, (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.reportInvalidTypeForm, 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.reportAttributeAccessIssue, 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.reportAttributeAccessIssue;
|
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.reportInvalidTypeArguments, 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.reportInvalidTypeArguments, 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.reportIndexIssue, 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.reportIndexIssue, 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.reportInvalidTypeForm, 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.reportInvalidTypeForm, 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.reportInvalidTypeForm, 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.reportAssertTypeFailure, 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.reportArgumentType, 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.reportArgumentType, 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.reportCallIssue, 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.reportCallIssue, 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.reportCallIssue, 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.reportCallIssue, 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.reportCallIssue, 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.reportCallIssue, 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.reportCallIssue, 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.reportCallIssue, 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.reportAbstractUsage, 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.reportAbstractUsage, 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.reportCallIssue, 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.reportCallIssue, 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.reportCallIssue, 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.reportCallIssue, 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.reportCallIssue, 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.reportCallIssue, 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.reportCallIssue, 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.reportCallIssue, 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.reportCallIssue, 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.reportCallIssue, 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.reportCallIssue, 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.reportCallIssue, 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.reportCallIssue, 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.reportCallIssue, 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.reportAbstractUsage, 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.reportCallIssue, 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.reportCallIssue, localize_1.LocMessage.paramSpecArgsMissing().format({
|
8256
8295
|
type: printType(functionType.details.paramSpec),
|
8257
8296
|
}), argErrorNode !== null && argErrorNode !== void 0 ? argErrorNode : errorNode);
|
8258
8297
|
}
|
@@ -8317,8 +8356,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8317
8356
|
? 512 /* EvaluatorFlags.AllowMissingTypeArgs */ |
|
8318
8357
|
8 /* EvaluatorFlags.EvaluateStringLiteralAsType */ |
|
8319
8358
|
32 /* EvaluatorFlags.DisallowParamSpec */ |
|
8320
|
-
64 /* EvaluatorFlags.DisallowTypeVarTuple */
|
8321
|
-
|
8359
|
+
64 /* EvaluatorFlags.DisallowTypeVarTuple */ |
|
8360
|
+
16 /* EvaluatorFlags.DisallowFinal */
|
8361
|
+
: 2 /* EvaluatorFlags.DoNotSpecialize */ | 16 /* EvaluatorFlags.DisallowFinal */;
|
8322
8362
|
const exprTypeResult = getTypeOfExpression(argParam.argument.valueExpression, flags, (0, typeUtils_1.makeInferenceContext)(expectedType, !!(typeResult === null || typeResult === void 0 ? void 0 : typeResult.isIncomplete), signatureTracker));
|
8323
8363
|
argType = exprTypeResult.type;
|
8324
8364
|
// If the type includes multiple instances of a generic function
|
@@ -8445,16 +8485,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8445
8485
|
// Mismatching parameter types are common in untyped code; don't bother spending time
|
8446
8486
|
// printing types if the diagnostic is disabled.
|
8447
8487
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(argParam.errorNode);
|
8448
|
-
if (fileInfo.diagnosticRuleSet.
|
8488
|
+
if (fileInfo.diagnosticRuleSet.reportArgumentType !== 'none' &&
|
8449
8489
|
!isDiagnosticSuppressedForNode(argParam.errorNode) &&
|
8450
8490
|
!isTypeIncomplete) {
|
8451
|
-
const fileInfo = AnalyzerNodeInfo.getFileInfo(argParam.errorNode);
|
8452
8491
|
const argTypeText = printType(argType);
|
8453
8492
|
const paramTypeText = printType(argParam.paramType);
|
8454
8493
|
let message;
|
8455
8494
|
if (argParam.paramName && !argParam.isParamNameSynthesized) {
|
8456
8495
|
if (functionName) {
|
8457
|
-
message = localize_1.
|
8496
|
+
message = localize_1.LocMessage.argAssignmentParamFunction().format({
|
8458
8497
|
argType: argTypeText,
|
8459
8498
|
paramType: paramTypeText,
|
8460
8499
|
functionName,
|
@@ -8462,7 +8501,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8462
8501
|
});
|
8463
8502
|
}
|
8464
8503
|
else {
|
8465
|
-
message = localize_1.
|
8504
|
+
message = localize_1.LocMessage.argAssignmentParam().format({
|
8466
8505
|
argType: argTypeText,
|
8467
8506
|
paramType: paramTypeText,
|
8468
8507
|
paramName: argParam.paramName,
|
@@ -8471,14 +8510,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8471
8510
|
}
|
8472
8511
|
else {
|
8473
8512
|
if (functionName) {
|
8474
|
-
message = localize_1.
|
8513
|
+
message = localize_1.LocMessage.argAssignmentFunction().format({
|
8475
8514
|
argType: argTypeText,
|
8476
8515
|
paramType: paramTypeText,
|
8477
8516
|
functionName,
|
8478
8517
|
});
|
8479
8518
|
}
|
8480
8519
|
else {
|
8481
|
-
message = localize_1.
|
8520
|
+
message = localize_1.LocMessage.argAssignment().format({
|
8482
8521
|
argType: argTypeText,
|
8483
8522
|
paramType: paramTypeText,
|
8484
8523
|
});
|
@@ -8490,7 +8529,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8490
8529
|
if (expectedTypeDiag) {
|
8491
8530
|
diag = expectedTypeDiag;
|
8492
8531
|
}
|
8493
|
-
addDiagnostic(
|
8532
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportArgumentType, message + diag.getString(), argParam.errorNode, (_a = diag.getEffectiveTextRange()) !== null && _a !== void 0 ? _a : argParam.errorNode);
|
8494
8533
|
}
|
8495
8534
|
return { isCompatible: false, argType, isTypeIncomplete, skippedBareTypeVarExpectedType, condition };
|
8496
8535
|
}
|
@@ -8501,11 +8540,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8501
8540
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
8502
8541
|
if (argParam.paramName) {
|
8503
8542
|
diagAddendum.addMessage((functionName
|
8504
|
-
? localize_1.
|
8543
|
+
? localize_1.LocAddendum.argParamFunction().format({
|
8505
8544
|
paramName: argParam.paramName,
|
8506
8545
|
functionName,
|
8507
8546
|
})
|
8508
|
-
: localize_1.
|
8547
|
+
: localize_1.LocAddendum.argParam().format({ paramName: argParam.paramName })) +
|
8509
8548
|
diagAddendum.getString());
|
8510
8549
|
}
|
8511
8550
|
return diagAddendum;
|
@@ -8517,7 +8556,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8517
8556
|
!isTypeIncomplete) {
|
8518
8557
|
if ((0, types_1.isUnknown)(simplifiedType)) {
|
8519
8558
|
const diagAddendum = getDiagAddendum();
|
8520
|
-
addDiagnostic(
|
8559
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownArgumentType, localize_1.LocMessage.argTypeUnknown() + diagAddendum.getString(), argParam.errorNode);
|
8521
8560
|
}
|
8522
8561
|
else if ((0, typeUtils_1.isPartlyUnknown)(simplifiedType)) {
|
8523
8562
|
// If the parameter type is also partially unknown, don't report
|
@@ -8525,10 +8564,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8525
8564
|
// arose due to bidirectional type matching.
|
8526
8565
|
if (!(0, typeUtils_1.isPartlyUnknown)(argParam.paramType)) {
|
8527
8566
|
const diagAddendum = getDiagAddendum();
|
8528
|
-
diagAddendum.addMessage(localize_1.
|
8567
|
+
diagAddendum.addMessage(localize_1.LocAddendum.argumentType().format({
|
8529
8568
|
type: printType(simplifiedType, { expandTypeAlias: true }),
|
8530
8569
|
}));
|
8531
|
-
addDiagnostic(
|
8570
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownArgumentType, localize_1.LocMessage.argTypePartiallyUnknown() + diagAddendum.getString(), argParam.errorNode);
|
8532
8571
|
}
|
8533
8572
|
}
|
8534
8573
|
}
|
@@ -8541,7 +8580,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8541
8580
|
let firstConstraintArg;
|
8542
8581
|
let defaultValueNode;
|
8543
8582
|
if (argList.length === 0) {
|
8544
|
-
addError(localize_1.
|
8583
|
+
addError(localize_1.LocMessage.typeVarFirstArg(), errorNode);
|
8545
8584
|
return undefined;
|
8546
8585
|
}
|
8547
8586
|
const firstArg = argList[0];
|
@@ -8549,9 +8588,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8549
8588
|
typeVarName = firstArg.valueExpression.strings.map((s) => s.value).join('');
|
8550
8589
|
}
|
8551
8590
|
else {
|
8552
|
-
addError(localize_1.
|
8591
|
+
addError(localize_1.LocMessage.typeVarFirstArg(), firstArg.valueExpression || errorNode);
|
8553
8592
|
}
|
8554
|
-
const typeVar = types_1.TypeVarType.createInstantiable(typeVarName, /* isParamSpec */ false, classType);
|
8593
|
+
const typeVar = types_1.TypeBase.cloneAsSpecialForm(types_1.TypeVarType.createInstantiable(typeVarName, /* isParamSpec */ false), types_1.ClassType.cloneAsInstance(classType));
|
8555
8594
|
// Parse the remaining parameters.
|
8556
8595
|
const paramNameMap = new Map();
|
8557
8596
|
for (let i = 1; i < argList.length; i++) {
|
@@ -8559,18 +8598,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8559
8598
|
const paramName = paramNameNode ? paramNameNode.value : undefined;
|
8560
8599
|
if (paramName) {
|
8561
8600
|
if (paramNameMap.get(paramName)) {
|
8562
|
-
addError(localize_1.
|
8601
|
+
addError(localize_1.LocMessage.duplicateParam().format({ name: paramName }), argList[i].valueExpression || errorNode);
|
8563
8602
|
}
|
8564
8603
|
if (paramName === 'bound') {
|
8565
8604
|
if (typeVar.details.constraints.length > 0) {
|
8566
|
-
addError(localize_1.
|
8605
|
+
addError(localize_1.LocMessage.typeVarBoundAndConstrained(), argList[i].valueExpression || errorNode);
|
8567
8606
|
}
|
8568
8607
|
else {
|
8569
8608
|
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
8609
|
disallowProtocolAndTypedDict: true,
|
8571
8610
|
}).type;
|
8572
8611
|
if ((0, typeUtils_1.requiresSpecialization)(argType, { ignorePseudoGeneric: true, ignoreImplicitTypeArgs: true })) {
|
8573
|
-
addError(localize_1.
|
8612
|
+
addError(localize_1.LocMessage.typeVarBoundGeneric(), argList[i].valueExpression || errorNode);
|
8574
8613
|
}
|
8575
8614
|
typeVar.details.boundType = (0, typeUtils_1.convertToInstance)(argType);
|
8576
8615
|
}
|
@@ -8579,7 +8618,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8579
8618
|
if (argList[i].valueExpression && getBooleanValue(argList[i].valueExpression)) {
|
8580
8619
|
if (typeVar.details.declaredVariance === 4 /* Variance.Contravariant */ ||
|
8581
8620
|
typeVar.details.declaredVariance === 0 /* Variance.Auto */) {
|
8582
|
-
addError(localize_1.
|
8621
|
+
addError(localize_1.LocMessage.typeVarVariance(), argList[i].valueExpression);
|
8583
8622
|
}
|
8584
8623
|
else {
|
8585
8624
|
typeVar.details.declaredVariance = 3 /* Variance.Covariant */;
|
@@ -8590,7 +8629,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8590
8629
|
if (argList[i].valueExpression && getBooleanValue(argList[i].valueExpression)) {
|
8591
8630
|
if (typeVar.details.declaredVariance === 3 /* Variance.Covariant */ ||
|
8592
8631
|
typeVar.details.declaredVariance === 0 /* Variance.Auto */) {
|
8593
|
-
addError(localize_1.
|
8632
|
+
addError(localize_1.LocMessage.typeVarVariance(), argList[i].valueExpression);
|
8594
8633
|
}
|
8595
8634
|
else {
|
8596
8635
|
typeVar.details.declaredVariance = 4 /* Variance.Contravariant */;
|
@@ -8601,7 +8640,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8601
8640
|
if (argList[i].valueExpression && getBooleanValue(argList[i].valueExpression)) {
|
8602
8641
|
if (typeVar.details.declaredVariance === 3 /* Variance.Covariant */ ||
|
8603
8642
|
typeVar.details.declaredVariance === 4 /* Variance.Contravariant */) {
|
8604
|
-
addError(localize_1.
|
8643
|
+
addError(localize_1.LocMessage.typeVarVariance(), argList[i].valueExpression);
|
8605
8644
|
}
|
8606
8645
|
else {
|
8607
8646
|
typeVar.details.declaredVariance = 0 /* Variance.Auto */;
|
@@ -8618,22 +8657,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8618
8657
|
if (!fileInfo.isStubFile &&
|
8619
8658
|
fileInfo.executionEnvironment.pythonVersion < pythonVersion_1.PythonVersion.V3_13 &&
|
8620
8659
|
classType.details.moduleName !== 'typing_extensions') {
|
8621
|
-
addError(localize_1.
|
8660
|
+
addError(localize_1.LocMessage.typeVarDefaultIllegal(), defaultValueNode);
|
8622
8661
|
}
|
8623
8662
|
}
|
8624
8663
|
else {
|
8625
|
-
addError(localize_1.
|
8664
|
+
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
8665
|
}
|
8627
8666
|
paramNameMap.set(paramName, paramName);
|
8628
8667
|
}
|
8629
8668
|
else {
|
8630
8669
|
if (typeVar.details.boundType) {
|
8631
|
-
addError(localize_1.
|
8670
|
+
addError(localize_1.LocMessage.typeVarBoundAndConstrained(), argList[i].valueExpression || errorNode);
|
8632
8671
|
}
|
8633
8672
|
else {
|
8634
8673
|
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
8674
|
if ((0, typeUtils_1.requiresSpecialization)(argType, { ignorePseudoGeneric: true })) {
|
8636
|
-
addError(localize_1.
|
8675
|
+
addError(localize_1.LocMessage.typeVarConstraintGeneric(), argList[i].valueExpression || errorNode);
|
8637
8676
|
}
|
8638
8677
|
types_1.TypeVarType.addConstraint(typeVar, (0, typeUtils_1.convertToInstance)(argType));
|
8639
8678
|
if (firstConstraintArg === undefined) {
|
@@ -8643,7 +8682,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8643
8682
|
}
|
8644
8683
|
}
|
8645
8684
|
if (typeVar.details.constraints.length === 1 && firstConstraintArg) {
|
8646
|
-
addDiagnostic(
|
8685
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarSingleConstraint(), firstConstraintArg.valueExpression || errorNode);
|
8647
8686
|
}
|
8648
8687
|
// If a default is provided, make sure it is compatible with the bound
|
8649
8688
|
// or constraint.
|
@@ -8654,12 +8693,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8654
8693
|
}));
|
8655
8694
|
if (typeVar.details.boundType) {
|
8656
8695
|
if (!assignType(typeVar.details.boundType, concreteDefaultType)) {
|
8657
|
-
addDiagnostic(
|
8696
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarDefaultBoundMismatch(), defaultValueNode);
|
8658
8697
|
}
|
8659
8698
|
}
|
8660
8699
|
else if (typeVar.details.constraints.length > 0) {
|
8661
8700
|
if (!typeVar.details.constraints.some((constraint) => (0, types_1.isTypeSame)(constraint, concreteDefaultType))) {
|
8662
|
-
addDiagnostic(
|
8701
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarDefaultConstraintMismatch(), defaultValueNode);
|
8663
8702
|
}
|
8664
8703
|
}
|
8665
8704
|
}
|
@@ -8669,7 +8708,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8669
8708
|
var _a, _b;
|
8670
8709
|
let typeVarName = '';
|
8671
8710
|
if (argList.length === 0) {
|
8672
|
-
addError(localize_1.
|
8711
|
+
addError(localize_1.LocMessage.typeVarFirstArg(), errorNode);
|
8673
8712
|
return undefined;
|
8674
8713
|
}
|
8675
8714
|
const firstArg = argList[0];
|
@@ -8677,9 +8716,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8677
8716
|
typeVarName = firstArg.valueExpression.strings.map((s) => s.value).join('');
|
8678
8717
|
}
|
8679
8718
|
else {
|
8680
|
-
addError(localize_1.
|
8719
|
+
addError(localize_1.LocMessage.typeVarFirstArg(), firstArg.valueExpression || errorNode);
|
8681
8720
|
}
|
8682
|
-
const typeVar = types_1.TypeVarType.createInstantiable(typeVarName, /* isParamSpec */ false, classType);
|
8721
|
+
const typeVar = types_1.TypeBase.cloneAsSpecialForm(types_1.TypeVarType.createInstantiable(typeVarName, /* isParamSpec */ false), types_1.ClassType.cloneAsInstance(classType));
|
8683
8722
|
typeVar.details.isVariadic = true;
|
8684
8723
|
// Parse the remaining parameters.
|
8685
8724
|
for (let i = 1; i < argList.length; i++) {
|
@@ -8695,15 +8734,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8695
8734
|
if (!fileInfo.isStubFile &&
|
8696
8735
|
fileInfo.executionEnvironment.pythonVersion < pythonVersion_1.PythonVersion.V3_13 &&
|
8697
8736
|
classType.details.moduleName !== 'typing_extensions') {
|
8698
|
-
addError(localize_1.
|
8737
|
+
addError(localize_1.LocMessage.typeVarDefaultIllegal(), expr);
|
8699
8738
|
}
|
8700
8739
|
}
|
8701
8740
|
else {
|
8702
|
-
addError(localize_1.
|
8741
|
+
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
8742
|
}
|
8704
8743
|
}
|
8705
8744
|
else {
|
8706
|
-
addError(localize_1.
|
8745
|
+
addError(localize_1.LocMessage.typeVarTupleConstraints(), argList[i].valueExpression || errorNode);
|
8707
8746
|
}
|
8708
8747
|
}
|
8709
8748
|
return typeVar;
|
@@ -8716,14 +8755,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8716
8755
|
const isUnpackedTuple = (0, types_1.isClass)(argType) && (0, typeUtils_1.isTupleClass)(argType) && argType.isUnpacked;
|
8717
8756
|
const isUnpackedTypeVarTuple = (0, types_1.isUnpackedVariadicTypeVar)(argType);
|
8718
8757
|
if (!isUnpackedTuple && !isUnpackedTypeVarTuple) {
|
8719
|
-
addDiagnostic(
|
8758
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarTupleDefaultNotUnpacked(), node);
|
8720
8759
|
return undefined;
|
8721
8760
|
}
|
8722
8761
|
return (0, typeUtils_1.convertToInstance)(argType);
|
8723
8762
|
}
|
8724
8763
|
function createParamSpecType(errorNode, classType, argList) {
|
8725
8764
|
if (argList.length === 0) {
|
8726
|
-
addError(localize_1.
|
8765
|
+
addError(localize_1.LocMessage.paramSpecFirstArg(), errorNode);
|
8727
8766
|
return undefined;
|
8728
8767
|
}
|
8729
8768
|
const firstArg = argList[0];
|
@@ -8732,9 +8771,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8732
8771
|
paramSpecName = firstArg.valueExpression.strings.map((s) => s.value).join('');
|
8733
8772
|
}
|
8734
8773
|
else {
|
8735
|
-
addError(localize_1.
|
8774
|
+
addError(localize_1.LocMessage.paramSpecFirstArg(), firstArg.valueExpression || errorNode);
|
8736
8775
|
}
|
8737
|
-
const paramSpec = types_1.TypeVarType.createInstantiable(paramSpecName, /* isParamSpec */ true, classType);
|
8776
|
+
const paramSpec = types_1.TypeBase.cloneAsSpecialForm(types_1.TypeVarType.createInstantiable(paramSpecName, /* isParamSpec */ true), types_1.ClassType.cloneAsInstance(classType));
|
8738
8777
|
// Parse the remaining parameters.
|
8739
8778
|
for (let i = 1; i < argList.length; i++) {
|
8740
8779
|
const paramNameNode = argList[i].name;
|
@@ -8749,15 +8788,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8749
8788
|
if (!fileInfo.isStubFile &&
|
8750
8789
|
fileInfo.executionEnvironment.pythonVersion < pythonVersion_1.PythonVersion.V3_13 &&
|
8751
8790
|
classType.details.moduleName !== 'typing_extensions') {
|
8752
|
-
addError(localize_1.
|
8791
|
+
addError(localize_1.LocMessage.typeVarDefaultIllegal(), expr);
|
8753
8792
|
}
|
8754
8793
|
}
|
8755
8794
|
else {
|
8756
|
-
addError(localize_1.
|
8795
|
+
addError(localize_1.LocMessage.paramSpecUnknownParam().format({ name: paramName }), paramNameNode || argList[i].valueExpression || errorNode);
|
8757
8796
|
}
|
8758
8797
|
}
|
8759
8798
|
else {
|
8760
|
-
addError(localize_1.
|
8799
|
+
addError(localize_1.LocMessage.paramSpecUnknownArg(), argList[i].valueExpression || errorNode);
|
8761
8800
|
break;
|
8762
8801
|
}
|
8763
8802
|
}
|
@@ -8806,7 +8845,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8806
8845
|
return functionType;
|
8807
8846
|
}
|
8808
8847
|
}
|
8809
|
-
addDiagnostic(
|
8848
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.paramSpecDefaultNotTuple(), node);
|
8810
8849
|
return undefined;
|
8811
8850
|
}
|
8812
8851
|
// Handles a call to TypeAliasType(). This special form allows a caller to programmatically
|
@@ -8820,7 +8859,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8820
8859
|
if (errorNode.parent.nodeType !== 3 /* ParseNodeType.Assignment */ ||
|
8821
8860
|
errorNode.parent.rightExpression !== errorNode ||
|
8822
8861
|
errorNode.parent.leftExpression.nodeType !== 38 /* ParseNodeType.Name */) {
|
8823
|
-
addDiagnostic(
|
8862
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAliasTypeMustBeAssigned(), errorNode);
|
8824
8863
|
return undefined;
|
8825
8864
|
}
|
8826
8865
|
const nameNode = errorNode.parent.leftExpression;
|
@@ -8828,11 +8867,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8828
8867
|
if (firstArg.valueExpression && firstArg.valueExpression.nodeType === 48 /* ParseNodeType.StringList */) {
|
8829
8868
|
const typeAliasName = firstArg.valueExpression.strings.map((s) => s.value).join('');
|
8830
8869
|
if (typeAliasName !== nameNode.value) {
|
8831
|
-
addDiagnostic(
|
8870
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAliasTypeNameMismatch(), firstArg.valueExpression);
|
8832
8871
|
}
|
8833
8872
|
}
|
8834
8873
|
else {
|
8835
|
-
addDiagnostic(
|
8874
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAliasTypeNameArg(), firstArg.valueExpression || errorNode);
|
8836
8875
|
return undefined;
|
8837
8876
|
}
|
8838
8877
|
let valueExpr;
|
@@ -8866,7 +8905,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8866
8905
|
let typeParameters;
|
8867
8906
|
if (typeParamsExpr) {
|
8868
8907
|
if (typeParamsExpr.nodeType !== 52 /* ParseNodeType.Tuple */) {
|
8869
|
-
addError(localize_1.
|
8908
|
+
addError(localize_1.LocMessage.typeAliasTypeParamInvalid(), typeParamsExpr);
|
8870
8909
|
return undefined;
|
8871
8910
|
}
|
8872
8911
|
typeParameters = [];
|
@@ -8887,7 +8926,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8887
8926
|
}
|
8888
8927
|
});
|
8889
8928
|
if (!isTypeParamListValid) {
|
8890
|
-
addDiagnostic(
|
8929
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAliasTypeParamInvalid(), typeParamsExpr);
|
8891
8930
|
return undefined;
|
8892
8931
|
}
|
8893
8932
|
}
|
@@ -8904,7 +8943,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8904
8943
|
return true;
|
8905
8944
|
}
|
8906
8945
|
}
|
8907
|
-
addDiagnostic(
|
8946
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.expectedBoolLiteral(), node);
|
8908
8947
|
return false;
|
8909
8948
|
}
|
8910
8949
|
function getFunctionFullName(functionNode, moduleName, functionName) {
|
@@ -8928,7 +8967,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8928
8967
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
8929
8968
|
let className = '';
|
8930
8969
|
if (argList.length !== 2) {
|
8931
|
-
addDiagnostic(
|
8970
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.newTypeParamCount(), errorNode);
|
8932
8971
|
return undefined;
|
8933
8972
|
}
|
8934
8973
|
const nameArg = argList[0];
|
@@ -8938,13 +8977,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8938
8977
|
className = nameArg.valueExpression.strings.map((s) => s.value).join('');
|
8939
8978
|
}
|
8940
8979
|
if (!className) {
|
8941
|
-
addDiagnostic(
|
8980
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportArgumentType, localize_1.LocMessage.newTypeBadName(), (_a = argList[0].node) !== null && _a !== void 0 ? _a : errorNode);
|
8942
8981
|
return undefined;
|
8943
8982
|
}
|
8944
8983
|
if (((_b = errorNode.parent) === null || _b === void 0 ? void 0 : _b.nodeType) === 3 /* ParseNodeType.Assignment */ &&
|
8945
8984
|
errorNode.parent.leftExpression.nodeType === 38 /* ParseNodeType.Name */ &&
|
8946
8985
|
errorNode.parent.leftExpression.value !== className) {
|
8947
|
-
addDiagnostic(
|
8986
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.newTypeNameMismatch(), errorNode.parent.leftExpression);
|
8948
8987
|
return undefined;
|
8949
8988
|
}
|
8950
8989
|
let baseClass = getTypeOfArgumentExpectingType(argList[1]).type;
|
@@ -8953,18 +8992,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8953
8992
|
if (objectType && (0, types_1.isClassInstance)(objectType)) {
|
8954
8993
|
baseClass = types_1.ClassType.cloneAsInstantiable(objectType);
|
8955
8994
|
}
|
8956
|
-
addDiagnostic(
|
8995
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.newTypeAnyOrUnknown(), (_c = argList[1].node) !== null && _c !== void 0 ? _c : errorNode);
|
8957
8996
|
isBaseClassAny = true;
|
8958
8997
|
}
|
8959
8998
|
if (!(0, types_1.isInstantiableClass)(baseClass)) {
|
8960
|
-
addDiagnostic(
|
8999
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.newTypeNotAClass(), argList[1].node || errorNode);
|
8961
9000
|
return undefined;
|
8962
9001
|
}
|
8963
9002
|
if (types_1.ClassType.isProtocolClass(baseClass) || types_1.ClassType.isTypedDictClass(baseClass)) {
|
8964
|
-
addDiagnostic(
|
9003
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.newTypeProtocolClass(), argList[1].node || errorNode);
|
8965
9004
|
}
|
8966
9005
|
else if (baseClass.literalValue !== undefined) {
|
8967
|
-
addDiagnostic(
|
9006
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.newTypeLiteral(), argList[1].node || errorNode);
|
8968
9007
|
}
|
8969
9008
|
let classFlags = baseClass.details.flags & ~(1 /* ClassTypeFlags.BuiltInClass */ | 2 /* ClassTypeFlags.SpecialBuiltIn */);
|
8970
9009
|
classFlags |= 4096 /* ClassTypeFlags.Final */ | 268435456 /* ClassTypeFlags.NewTypeClass */ | 536870912 /* ClassTypeFlags.ValidTypeAliasClass */;
|
@@ -9028,7 +9067,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9028
9067
|
}
|
9029
9068
|
});
|
9030
9069
|
if (!(0, typeUtils_1.computeMroLinearization)(classType)) {
|
9031
|
-
addError(localize_1.
|
9070
|
+
addError(localize_1.LocMessage.methodOrdering(), errorNode);
|
9032
9071
|
}
|
9033
9072
|
return classType;
|
9034
9073
|
}
|
@@ -9127,8 +9166,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9127
9166
|
if ((flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0 &&
|
9128
9167
|
((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) !== 1 /* ParseNodeType.Argument */) {
|
9129
9168
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
9130
|
-
diag.addMessage(localize_1.
|
9131
|
-
addDiagnostic(
|
9169
|
+
diag.addMessage(localize_1.LocAddendum.useDictInstead());
|
9170
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.dictInAnnotation() + diag.getString(), node);
|
9132
9171
|
}
|
9133
9172
|
// If the expected type is a union, analyze for each of the subtypes
|
9134
9173
|
// to find one that matches.
|
@@ -9413,8 +9452,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9413
9452
|
}
|
9414
9453
|
}
|
9415
9454
|
else {
|
9416
|
-
|
9417
|
-
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.dictUnpackIsNotMapping(), entryNode);
|
9455
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.dictUnpackIsNotMapping(), entryNode);
|
9418
9456
|
}
|
9419
9457
|
}
|
9420
9458
|
}
|
@@ -9451,8 +9489,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9451
9489
|
node.nodeType === 31 /* ParseNodeType.List */ &&
|
9452
9490
|
((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) !== 1 /* ParseNodeType.Argument */) {
|
9453
9491
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
9454
|
-
diag.addMessage(localize_1.
|
9455
|
-
addDiagnostic(
|
9492
|
+
diag.addMessage(localize_1.LocAddendum.useListInstead());
|
9493
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.listInAnnotation() + diag.getString(), node);
|
9456
9494
|
}
|
9457
9495
|
// If the expected type is a union, recursively call for each of the subtypes
|
9458
9496
|
// to find one that matches.
|
@@ -9627,13 +9665,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9627
9665
|
function verifySetEntryOrDictKeyIsHashable(entry, type, isDictKey) {
|
9628
9666
|
// Verify that the type is hashable.
|
9629
9667
|
if (!isTypeHashable(type)) {
|
9630
|
-
const fileInfo = AnalyzerNodeInfo.getFileInfo(entry);
|
9631
9668
|
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);
|
9669
|
+
diag.addMessage(localize_1.LocAddendum.unhashableType().format({ type: printType(type) }));
|
9670
|
+
const message = isDictKey ? localize_1.LocMessage.unhashableDictKey() : localize_1.LocMessage.unhashableSetEntry();
|
9671
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, message + diag.getString(), entry);
|
9637
9672
|
}
|
9638
9673
|
}
|
9639
9674
|
function inferTypeArgFromExpectedEntryType(inferenceContext, entryTypes, isNarrowable) {
|
@@ -9882,6 +9917,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9882
9917
|
}
|
9883
9918
|
}, {
|
9884
9919
|
dependentType: expectedType,
|
9920
|
+
allowDiagnostics: !forceSpeculative && !isDiagnosticSuppressedForNode(node) && !(inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete),
|
9885
9921
|
});
|
9886
9922
|
// Mark the function type as no longer being evaluated.
|
9887
9923
|
functionType.details.flags &= ~131072 /* FunctionTypeFlags.PartiallyEvaluated */;
|
@@ -9895,13 +9931,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9895
9931
|
let isIncomplete = false;
|
9896
9932
|
let typeErrors = false;
|
9897
9933
|
// 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) => {
|
9934
|
+
// or any clause other than the leftmost "for" contain an "await" operator,
|
9935
|
+
// it is treated as an async generator.
|
9936
|
+
let isAsync = node.forIfNodes.some((comp, index) => {
|
9901
9937
|
if (comp.nodeType === 33 /* ParseNodeType.ListComprehensionFor */ && comp.isAsync) {
|
9902
9938
|
return true;
|
9903
9939
|
}
|
9904
|
-
return ParseTreeUtils.containsAwaitNode(comp);
|
9940
|
+
return index > 0 && ParseTreeUtils.containsAwaitNode(comp);
|
9905
9941
|
});
|
9906
9942
|
let type = types_1.UnknownType.create();
|
9907
9943
|
if (ParseTreeUtils.containsAwaitNode(node.expression)) {
|
@@ -9934,7 +9970,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9934
9970
|
// to avoid confusion.
|
9935
9971
|
const simplifiedType = (0, types_1.removeUnbound)(type);
|
9936
9972
|
if ((0, types_1.isUnknown)(simplifiedType)) {
|
9937
|
-
addDiagnostic(
|
9973
|
+
addDiagnostic(rule, localize_1.LocMessage.typeUnknown().format({ name: nameValue }), errorNode);
|
9938
9974
|
}
|
9939
9975
|
else if ((0, typeUtils_1.isPartlyUnknown)(simplifiedType)) {
|
9940
9976
|
// If ignoreEmptyContainers is true, don't report the problem for
|
@@ -9942,11 +9978,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9942
9978
|
// only if the assigned value is used later.
|
9943
9979
|
if (!ignoreEmptyContainers || !(0, types_1.isClassInstance)(type) || !type.isEmptyContainer) {
|
9944
9980
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
9945
|
-
diagAddendum.addMessage(localize_1.
|
9981
|
+
diagAddendum.addMessage(localize_1.LocAddendum.typeOfSymbol().format({
|
9946
9982
|
name: nameValue,
|
9947
9983
|
type: printType(simplifiedType, { expandTypeAlias: true }),
|
9948
9984
|
}));
|
9949
|
-
addDiagnostic(
|
9985
|
+
addDiagnostic(rule, localize_1.LocMessage.typePartiallyUnknown().format({ name: nameValue }) + diagAddendum.getString(), errorNode);
|
9950
9986
|
}
|
9951
9987
|
}
|
9952
9988
|
}
|
@@ -10052,7 +10088,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10052
10088
|
function validateTypeArg(argResult, options) {
|
10053
10089
|
if (argResult.typeList) {
|
10054
10090
|
if (!(options === null || options === void 0 ? void 0 : options.allowTypeArgList)) {
|
10055
|
-
addError(localize_1.
|
10091
|
+
addError(localize_1.LocMessage.typeArgListNotAllowed(), argResult.node);
|
10056
10092
|
return false;
|
10057
10093
|
}
|
10058
10094
|
else {
|
@@ -10063,23 +10099,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10063
10099
|
}
|
10064
10100
|
if ((0, typeUtils_1.isEllipsisType)(argResult.type)) {
|
10065
10101
|
if (!(options === null || options === void 0 ? void 0 : options.allowTypeArgList)) {
|
10066
|
-
addError(localize_1.
|
10102
|
+
addError(localize_1.LocMessage.ellipsisContext(), argResult.node);
|
10067
10103
|
return false;
|
10068
10104
|
}
|
10069
10105
|
}
|
10070
10106
|
if ((0, types_1.isModule)(argResult.type)) {
|
10071
|
-
addError(localize_1.
|
10107
|
+
addError(localize_1.LocMessage.moduleAsType(), argResult.node);
|
10072
10108
|
return false;
|
10073
10109
|
}
|
10074
10110
|
if ((0, types_1.isParamSpec)(argResult.type)) {
|
10075
10111
|
if (!(options === null || options === void 0 ? void 0 : options.allowParamSpec)) {
|
10076
|
-
addError(localize_1.
|
10112
|
+
addError(localize_1.LocMessage.paramSpecContext(), argResult.node);
|
10077
10113
|
return false;
|
10078
10114
|
}
|
10079
10115
|
}
|
10080
10116
|
if ((0, types_1.isVariadicTypeVar)(argResult.type) && !argResult.type.isVariadicInUnion) {
|
10081
10117
|
if (!(options === null || options === void 0 ? void 0 : options.allowVariadicTypeVar)) {
|
10082
|
-
addError(localize_1.
|
10118
|
+
addError(localize_1.LocMessage.typeVarTupleContext(), argResult.node);
|
10083
10119
|
return false;
|
10084
10120
|
}
|
10085
10121
|
else {
|
@@ -10087,12 +10123,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10087
10123
|
}
|
10088
10124
|
}
|
10089
10125
|
if (!(options === null || options === void 0 ? void 0 : options.allowEmptyTuple) && argResult.isEmptyTupleShorthand) {
|
10090
|
-
addError(localize_1.
|
10126
|
+
addError(localize_1.LocMessage.zeroLengthTupleNotAllowed(), argResult.node);
|
10091
10127
|
return false;
|
10092
10128
|
}
|
10093
10129
|
if ((0, types_1.isUnpackedClass)(argResult.type)) {
|
10094
10130
|
if (!(options === null || options === void 0 ? void 0 : options.allowUnpackedTuples)) {
|
10095
|
-
addError(localize_1.
|
10131
|
+
addError(localize_1.LocMessage.unpackedArgInTypeArgument(), argResult.node);
|
10096
10132
|
return false;
|
10097
10133
|
}
|
10098
10134
|
}
|
@@ -10117,13 +10153,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10117
10153
|
// Make sure we have at most one unpacked variadic type variable.
|
10118
10154
|
if (sawUnpacked) {
|
10119
10155
|
if (!reportedUnpackedError) {
|
10120
|
-
addError(localize_1.
|
10156
|
+
addError(localize_1.LocMessage.variadicTypeArgsTooMany(), entry.node);
|
10121
10157
|
reportedUnpackedError = true;
|
10122
10158
|
}
|
10123
10159
|
}
|
10124
10160
|
sawUnpacked = true;
|
10125
10161
|
};
|
10126
10162
|
typeList.forEach((entry, index) => {
|
10163
|
+
var _a;
|
10127
10164
|
let entryType = entry.type;
|
10128
10165
|
let paramCategory = 0 /* ParameterCategory.Simple */;
|
10129
10166
|
const paramName = `__p${index.toString()}`;
|
@@ -10135,7 +10172,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10135
10172
|
else if (validateTypeArg(entry, { allowUnpackedTuples: true })) {
|
10136
10173
|
if ((0, types_1.isUnpackedClass)(entryType)) {
|
10137
10174
|
paramCategory = 1 /* ParameterCategory.ArgsList */;
|
10138
|
-
|
10175
|
+
if ((_a = entryType.tupleTypeArguments) === null || _a === void 0 ? void 0 : _a.some((typeArg) => (0, types_1.isVariadicTypeVar)(typeArg.type) || typeArg.isUnbounded)) {
|
10176
|
+
noteSawUnpacked(entry);
|
10177
|
+
}
|
10139
10178
|
}
|
10140
10179
|
}
|
10141
10180
|
else {
|
@@ -10188,7 +10227,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10188
10227
|
}
|
10189
10228
|
}
|
10190
10229
|
else {
|
10191
|
-
addError(localize_1.
|
10230
|
+
addError(localize_1.LocMessage.callableFirstArg(), typeArgs[0].node);
|
10192
10231
|
}
|
10193
10232
|
}
|
10194
10233
|
if (typeArgs.length > 1) {
|
@@ -10199,12 +10238,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10199
10238
|
functionType.details.declaredReturnType = (0, typeUtils_1.convertToInstance)(typeArg1Type);
|
10200
10239
|
}
|
10201
10240
|
else {
|
10202
|
-
|
10203
|
-
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.callableSecondArg(), errorNode);
|
10241
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportMissingTypeArgument, localize_1.LocMessage.callableSecondArg(), errorNode);
|
10204
10242
|
functionType.details.declaredReturnType = types_1.UnknownType.create();
|
10205
10243
|
}
|
10206
10244
|
if (typeArgs.length > 2) {
|
10207
|
-
addError(localize_1.
|
10245
|
+
addError(localize_1.LocMessage.callableExtraArgs(), typeArgs[2].node);
|
10208
10246
|
}
|
10209
10247
|
}
|
10210
10248
|
else {
|
@@ -10220,13 +10258,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10220
10258
|
// depends on whether we're evaluating a type annotation or
|
10221
10259
|
// we're in some other context.
|
10222
10260
|
if ((flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0) {
|
10223
|
-
addError(localize_1.
|
10261
|
+
addError(localize_1.LocMessage.optionalExtraArgs(), errorNode);
|
10224
10262
|
return types_1.UnknownType.create();
|
10225
10263
|
}
|
10226
10264
|
return classType;
|
10227
10265
|
}
|
10228
10266
|
if (typeArgs.length > 1) {
|
10229
|
-
addError(localize_1.
|
10267
|
+
addError(localize_1.LocMessage.optionalExtraArgs(), errorNode);
|
10230
10268
|
return types_1.UnknownType.create();
|
10231
10269
|
}
|
10232
10270
|
let typeArg0Type = typeArgs[0].type;
|
@@ -10239,7 +10277,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10239
10277
|
}
|
10240
10278
|
let optionalType = (0, types_1.combineTypes)([typeArg0Type, noneClassType !== null && noneClassType !== void 0 ? noneClassType : types_1.UnknownType.create()]);
|
10241
10279
|
if (unionClassType && (0, types_1.isInstantiableClass)(unionClassType)) {
|
10242
|
-
optionalType = types_1.TypeBase.cloneAsSpecialForm(optionalType, unionClassType);
|
10280
|
+
optionalType = types_1.TypeBase.cloneAsSpecialForm(optionalType, types_1.ClassType.cloneAsInstance(unionClassType));
|
10243
10281
|
}
|
10244
10282
|
return optionalType;
|
10245
10283
|
}
|
@@ -10262,7 +10300,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10262
10300
|
// Creates a type that represents a Literal.
|
10263
10301
|
function createLiteralType(classType, node, flags) {
|
10264
10302
|
if (node.items.length === 0) {
|
10265
|
-
addError(localize_1.
|
10303
|
+
addError(localize_1.LocMessage.literalEmptyArgs(), node.baseExpression);
|
10266
10304
|
return types_1.UnknownType.create();
|
10267
10305
|
}
|
10268
10306
|
// As per the specification, we support None, int, bool, str, bytes literals
|
@@ -10272,11 +10310,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10272
10310
|
let type;
|
10273
10311
|
const itemExpr = item.valueExpression;
|
10274
10312
|
if (item.argumentCategory !== 0 /* ArgumentCategory.Simple */) {
|
10275
|
-
addError(localize_1.
|
10313
|
+
addError(localize_1.LocMessage.unpackedArgInTypeArgument(), itemExpr);
|
10276
10314
|
type = types_1.UnknownType.create();
|
10277
10315
|
}
|
10278
10316
|
else if (item.name) {
|
10279
|
-
addError(localize_1.
|
10317
|
+
addError(localize_1.LocMessage.keywordArgInTypeArgument(), itemExpr);
|
10280
10318
|
type = types_1.UnknownType.create();
|
10281
10319
|
}
|
10282
10320
|
else if (itemExpr.nodeType === 48 /* ParseNodeType.StringList */) {
|
@@ -10340,7 +10378,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10340
10378
|
}
|
10341
10379
|
}
|
10342
10380
|
if (!type) {
|
10343
|
-
addError(localize_1.
|
10381
|
+
addError(localize_1.LocMessage.literalUnsupportedType(), item);
|
10344
10382
|
type = types_1.UnknownType.create();
|
10345
10383
|
}
|
10346
10384
|
literalTypes.push(type);
|
@@ -10351,26 +10389,25 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10351
10389
|
function createClassVarType(classType, errorNode, typeArgs, flags) {
|
10352
10390
|
var _a;
|
10353
10391
|
if (flags & 131072 /* EvaluatorFlags.DisallowClassVar */) {
|
10354
|
-
addError(localize_1.
|
10392
|
+
addError(localize_1.LocMessage.classVarNotAllowed(), errorNode);
|
10355
10393
|
return types_1.AnyType.create();
|
10356
10394
|
}
|
10357
10395
|
if (!typeArgs) {
|
10358
10396
|
return classType;
|
10359
10397
|
}
|
10360
10398
|
else if (typeArgs.length === 0) {
|
10361
|
-
addError(localize_1.
|
10399
|
+
addError(localize_1.LocMessage.classVarFirstArgMissing(), errorNode);
|
10362
10400
|
return types_1.UnknownType.create();
|
10363
10401
|
}
|
10364
10402
|
else if (typeArgs.length > 1) {
|
10365
|
-
addError(localize_1.
|
10403
|
+
addError(localize_1.LocMessage.classVarTooManyArgs(), typeArgs[1].node);
|
10366
10404
|
return types_1.UnknownType.create();
|
10367
10405
|
}
|
10368
10406
|
const type = typeArgs[0].type;
|
10369
10407
|
// A ClassVar should not allow TypeVars or generic types parameterized
|
10370
10408
|
// by TypeVars.
|
10371
10409
|
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);
|
10410
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.classVarWithTypeVar(), (_a = typeArgs[0].node) !== null && _a !== void 0 ? _a : errorNode);
|
10374
10411
|
}
|
10375
10412
|
return type;
|
10376
10413
|
}
|
@@ -10378,18 +10415,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10378
10415
|
// isn't a generic type and therefore doesn't have a typeParameter.
|
10379
10416
|
// We'll abuse our internal types a bit by specializing it with
|
10380
10417
|
// a type argument anyway.
|
10381
|
-
function createTypeGuardType(
|
10418
|
+
function createTypeGuardType(classType, errorNode, typeArgs, flags) {
|
10382
10419
|
// If no type arguments are provided, the resulting type
|
10383
10420
|
// depends on whether we're evaluating a type annotation or
|
10384
10421
|
// we're in some other context.
|
10385
10422
|
if (!typeArgs) {
|
10386
10423
|
if ((flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0) {
|
10387
|
-
addError(localize_1.
|
10424
|
+
addError(localize_1.LocMessage.typeGuardArgCount(), errorNode);
|
10388
10425
|
}
|
10389
10426
|
return classType;
|
10390
10427
|
}
|
10391
10428
|
else if (typeArgs.length !== 1) {
|
10392
|
-
addError(localize_1.
|
10429
|
+
addError(localize_1.LocMessage.typeGuardArgCount(), errorNode);
|
10393
10430
|
return types_1.UnknownType.create();
|
10394
10431
|
}
|
10395
10432
|
const convertedTypeArgs = typeArgs.map((typeArg) => {
|
@@ -10399,10 +10436,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10399
10436
|
}
|
10400
10437
|
function createSelfType(classType, errorNode, typeArgs, flags) {
|
10401
10438
|
var _a;
|
10402
|
-
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
10403
10439
|
// Self doesn't support any type arguments.
|
10404
10440
|
if (typeArgs) {
|
10405
|
-
addDiagnostic(
|
10441
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeArguments, localize_1.LocMessage.typeArgsExpectingNone().format({
|
10406
10442
|
name: classType.details.name,
|
10407
10443
|
}), (_a = typeArgs[0].node) !== null && _a !== void 0 ? _a : errorNode);
|
10408
10444
|
}
|
@@ -10416,13 +10452,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10416
10452
|
const enclosingClassTypeResult = enclosingClass ? getTypeOfClass(enclosingClass) : undefined;
|
10417
10453
|
if (!enclosingClassTypeResult) {
|
10418
10454
|
if ((flags & (256 /* EvaluatorFlags.ExpectingTypeAnnotation */ | 128 /* EvaluatorFlags.ExpectingInstantiableType */)) !== 0) {
|
10419
|
-
addDiagnostic(
|
10455
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.selfTypeContext(), errorNode);
|
10420
10456
|
}
|
10421
10457
|
return types_1.UnknownType.create();
|
10422
10458
|
}
|
10423
10459
|
else if ((0, typeUtils_1.isInstantiableMetaclass)(enclosingClassTypeResult.classType)) {
|
10424
10460
|
// If `Self` appears within a metaclass, it is considered illegal.
|
10425
|
-
addDiagnostic(
|
10461
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.selfTypeMetaclass(), errorNode);
|
10426
10462
|
return types_1.UnknownType.create();
|
10427
10463
|
}
|
10428
10464
|
const enclosingFunction = ParseTreeUtils.getEnclosingFunction(errorNode);
|
@@ -10433,7 +10469,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10433
10469
|
if (!isInnerFunction) {
|
10434
10470
|
// Check for static methods.
|
10435
10471
|
if (functionInfo.flags & 4 /* FunctionTypeFlags.StaticMethod */) {
|
10436
|
-
addDiagnostic(
|
10472
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.selfTypeContext(), errorNode);
|
10437
10473
|
return types_1.UnknownType.create();
|
10438
10474
|
}
|
10439
10475
|
if (enclosingFunction.parameters.length > 0) {
|
@@ -10444,7 +10480,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10444
10480
|
associateTypeVarsWithScope: true,
|
10445
10481
|
});
|
10446
10482
|
if (!(0, types_1.isTypeVar)(annotationType) || !annotationType.details.isSynthesizedSelf) {
|
10447
|
-
addDiagnostic(
|
10483
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.selfTypeWithTypedSelfOrCls(), errorNode);
|
10448
10484
|
}
|
10449
10485
|
}
|
10450
10486
|
}
|
@@ -10461,10 +10497,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10461
10497
|
}
|
10462
10498
|
if (!typeArgs || typeArgs.length !== 1) {
|
10463
10499
|
addError(classType.details.name === 'ReadOnly'
|
10464
|
-
? localize_1.
|
10500
|
+
? localize_1.LocMessage.readOnlyArgCount()
|
10465
10501
|
: classType.details.name === 'Required'
|
10466
|
-
? localize_1.
|
10467
|
-
: localize_1.
|
10502
|
+
? localize_1.LocMessage.requiredArgCount()
|
10503
|
+
: localize_1.LocMessage.notRequiredArgCount(), errorNode);
|
10468
10504
|
return { type: classType };
|
10469
10505
|
}
|
10470
10506
|
const typeArgType = typeArgs[0].type;
|
@@ -10503,10 +10539,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10503
10539
|
}
|
10504
10540
|
if (!isUsageLegal) {
|
10505
10541
|
addError(classType.details.name === 'ReadOnly'
|
10506
|
-
? localize_1.
|
10542
|
+
? localize_1.LocMessage.readOnlyNotInTypedDict()
|
10507
10543
|
: classType.details.name === 'Required'
|
10508
|
-
? localize_1.
|
10509
|
-
: localize_1.
|
10544
|
+
? localize_1.LocMessage.requiredNotInTypedDict()
|
10545
|
+
: localize_1.LocMessage.notRequiredNotInTypedDict(), errorNode);
|
10510
10546
|
return { type: types_1.ClassType.cloneForSpecialization(classType, [(0, typeUtils_1.convertToInstance)(typeArgType)], !!typeArgs) };
|
10511
10547
|
}
|
10512
10548
|
return { type: typeArgType, isReadOnly, isRequired, isNotRequired };
|
@@ -10519,14 +10555,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10519
10555
|
return classType;
|
10520
10556
|
}
|
10521
10557
|
if (!typeArgs || typeArgs.length !== 1) {
|
10522
|
-
addError(localize_1.
|
10558
|
+
addError(localize_1.LocMessage.unpackArgCount(), errorNode);
|
10523
10559
|
return types_1.UnknownType.create();
|
10524
10560
|
}
|
10525
10561
|
let typeArgType = typeArgs[0].type;
|
10526
10562
|
if ((0, types_1.isUnion)(typeArgType) && typeArgType.subtypes.length === 1) {
|
10527
10563
|
typeArgType = typeArgType.subtypes[0];
|
10528
10564
|
}
|
10529
|
-
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
10530
10565
|
if ((flags & 2097152 /* EvaluatorFlags.AllowUnpackedTupleOrTypeVarTuple */) !== 0) {
|
10531
10566
|
if ((0, types_1.isInstantiableClass)(typeArgType) && !typeArgType.includeSubclasses && (0, typeUtils_1.isTupleClass)(typeArgType)) {
|
10532
10567
|
return types_1.ClassType.cloneForUnpacked(typeArgType);
|
@@ -10534,75 +10569,75 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10534
10569
|
if ((0, types_1.isVariadicTypeVar)(typeArgType) && !typeArgType.isVariadicUnpacked) {
|
10535
10570
|
return types_1.TypeVarType.cloneForUnpacked(typeArgType);
|
10536
10571
|
}
|
10537
|
-
addDiagnostic(
|
10572
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.unpackExpectedTypeVarTuple(), errorNode);
|
10538
10573
|
return types_1.UnknownType.create();
|
10539
10574
|
}
|
10540
10575
|
if ((flags & 8388608 /* EvaluatorFlags.AllowUnpackedTypedDict */) !== 0) {
|
10541
10576
|
if ((0, types_1.isInstantiableClass)(typeArgType) && types_1.ClassType.isTypedDictClass(typeArgType)) {
|
10542
10577
|
return types_1.ClassType.cloneForUnpacked(typeArgType);
|
10543
10578
|
}
|
10544
|
-
addDiagnostic(
|
10579
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.unpackExpectedTypedDict(), errorNode);
|
10545
10580
|
return types_1.UnknownType.create();
|
10546
10581
|
}
|
10547
|
-
addDiagnostic(
|
10582
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.unpackNotAllowed(), errorNode);
|
10548
10583
|
return types_1.UnknownType.create();
|
10549
10584
|
}
|
10550
10585
|
// Creates a "Final" type.
|
10551
10586
|
function createFinalType(classType, errorNode, typeArgs, flags) {
|
10552
10587
|
if (flags & 16 /* EvaluatorFlags.DisallowFinal */) {
|
10553
|
-
addError(localize_1.
|
10554
|
-
return
|
10588
|
+
addError(localize_1.LocMessage.finalContext(), errorNode);
|
10589
|
+
return classType;
|
10555
10590
|
}
|
10556
10591
|
if (!typeArgs || typeArgs.length === 0) {
|
10557
10592
|
return classType;
|
10558
10593
|
}
|
10559
10594
|
if (typeArgs.length > 1) {
|
10560
|
-
addError(localize_1.
|
10595
|
+
addError(localize_1.LocMessage.finalTooManyArgs(), errorNode);
|
10561
10596
|
}
|
10562
|
-
return typeArgs[0].type;
|
10597
|
+
return types_1.TypeBase.cloneAsSpecialForm(typeArgs[0].type, classType);
|
10563
10598
|
}
|
10564
|
-
function createConcatenateType(
|
10599
|
+
function createConcatenateType(classType, errorNode, typeArgs, flags) {
|
10565
10600
|
if ((flags & 134217728 /* EvaluatorFlags.AllowConcatenate */) === 0) {
|
10566
|
-
addError(localize_1.
|
10601
|
+
addError(localize_1.LocMessage.concatenateContext(), errorNode);
|
10567
10602
|
return types_1.AnyType.create();
|
10568
10603
|
}
|
10569
10604
|
if (!typeArgs || typeArgs.length === 0) {
|
10570
|
-
addError(localize_1.
|
10605
|
+
addError(localize_1.LocMessage.concatenateTypeArgsMissing(), errorNode);
|
10571
10606
|
}
|
10572
10607
|
else {
|
10573
10608
|
typeArgs.forEach((typeArg, index) => {
|
10574
10609
|
if (index === typeArgs.length - 1) {
|
10575
10610
|
if (!(0, types_1.isParamSpec)(typeArg.type) && !(0, typeUtils_1.isEllipsisType)(typeArg.type)) {
|
10576
|
-
addError(localize_1.
|
10611
|
+
addError(localize_1.LocMessage.concatenateParamSpecMissing(), typeArg.node);
|
10577
10612
|
}
|
10578
10613
|
}
|
10579
10614
|
else {
|
10580
10615
|
if ((0, types_1.isParamSpec)(typeArg.type)) {
|
10581
|
-
addError(localize_1.
|
10616
|
+
addError(localize_1.LocMessage.paramSpecContext(), typeArg.node);
|
10582
10617
|
}
|
10583
10618
|
else if ((0, types_1.isUnpackedVariadicTypeVar)(typeArg.type)) {
|
10584
|
-
addError(localize_1.
|
10619
|
+
addError(localize_1.LocMessage.typeVarTupleContext(), typeArg.node);
|
10585
10620
|
}
|
10586
10621
|
else if ((0, types_1.isUnpackedClass)(typeArg.type)) {
|
10587
|
-
addError(localize_1.
|
10622
|
+
addError(localize_1.LocMessage.unpackedArgInTypeArgument(), typeArg.node);
|
10588
10623
|
}
|
10589
10624
|
}
|
10590
10625
|
});
|
10591
10626
|
}
|
10592
10627
|
return createSpecialType(classType, typeArgs, /* paramLimit */ undefined, /* allowParamSpec */ true);
|
10593
10628
|
}
|
10594
|
-
function createAnnotatedType(errorNode, typeArgs) {
|
10629
|
+
function createAnnotatedType(classType, errorNode, typeArgs) {
|
10595
10630
|
if (typeArgs && typeArgs.length < 2) {
|
10596
|
-
addError(localize_1.
|
10631
|
+
addError(localize_1.LocMessage.annotatedTypeArgMissing(), errorNode);
|
10597
10632
|
}
|
10598
10633
|
if (!typeArgs || typeArgs.length === 0) {
|
10599
10634
|
return { type: types_1.AnyType.create() };
|
10600
10635
|
}
|
10601
10636
|
if (typeArgs[0].typeList) {
|
10602
|
-
addError(localize_1.
|
10637
|
+
addError(localize_1.LocMessage.typeArgListNotAllowed(), typeArgs[0].node);
|
10603
10638
|
}
|
10604
10639
|
return {
|
10605
|
-
type: types_1.TypeBase.
|
10640
|
+
type: types_1.TypeBase.cloneAsSpecialForm(typeArgs[0].type, classType),
|
10606
10641
|
isReadOnly: typeArgs[0].isReadOnly,
|
10607
10642
|
isRequired: typeArgs[0].isRequired,
|
10608
10643
|
isNotRequired: typeArgs[0].isNotRequired,
|
@@ -10622,7 +10657,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10622
10657
|
const noteSawUnpacked = (typeArg) => {
|
10623
10658
|
if (sawUnpacked) {
|
10624
10659
|
if (!reportedUnpackedError) {
|
10625
|
-
addError(localize_1.
|
10660
|
+
addError(localize_1.LocMessage.variadicTypeArgsTooMany(), typeArg.node);
|
10626
10661
|
reportedUnpackedError = true;
|
10627
10662
|
}
|
10628
10663
|
}
|
@@ -10631,33 +10666,39 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10631
10666
|
let reportedUnpackedError = false;
|
10632
10667
|
// Verify that we didn't receive any inappropriate types.
|
10633
10668
|
typeArgs.forEach((typeArg, index) => {
|
10669
|
+
var _a;
|
10634
10670
|
(0, debug_1.assert)(typeArgs !== undefined);
|
10635
10671
|
if ((0, typeUtils_1.isEllipsisType)(typeArg.type)) {
|
10636
10672
|
if (!isTupleTypeParam) {
|
10637
10673
|
if (!allowParamSpec) {
|
10638
|
-
addError(localize_1.
|
10674
|
+
addError(localize_1.LocMessage.ellipsisContext(), typeArg.node);
|
10639
10675
|
}
|
10640
10676
|
}
|
10641
10677
|
else if (typeArgs.length !== 2 || index !== 1) {
|
10642
|
-
addError(localize_1.
|
10678
|
+
addError(localize_1.LocMessage.ellipsisSecondArg(), typeArg.node);
|
10643
10679
|
}
|
10644
10680
|
else {
|
10645
|
-
if ((0, types_1.
|
10646
|
-
(
|
10647
|
-
|
10648
|
-
|
10681
|
+
if ((0, types_1.isVariadicTypeVar)(typeArgs[0].type) && !typeArgs[0].type.isVariadicInUnion) {
|
10682
|
+
addError(localize_1.LocMessage.typeVarTupleContext(), typeArgs[0].node);
|
10683
|
+
}
|
10684
|
+
else if ((0, types_1.isUnpackedClass)(typeArgs[0].type)) {
|
10685
|
+
addError(localize_1.LocMessage.ellipsisAfterUnpacked(), typeArg.node);
|
10649
10686
|
}
|
10650
10687
|
}
|
10651
10688
|
}
|
10652
10689
|
else if ((0, types_1.isParamSpec)(typeArg.type) && allowParamSpec) {
|
10653
10690
|
// Nothing to do - this is allowed.
|
10654
10691
|
}
|
10655
|
-
else if ((0, types_1.isVariadicTypeVar)(typeArg.type)
|
10656
|
-
|
10692
|
+
else if (paramLimit === undefined && (0, types_1.isVariadicTypeVar)(typeArg.type)) {
|
10693
|
+
if (!typeArg.type.isVariadicInUnion) {
|
10694
|
+
noteSawUnpacked(typeArg);
|
10695
|
+
}
|
10657
10696
|
validateVariadicTypeVarIsUnpacked(typeArg.type, typeArg.node);
|
10658
10697
|
}
|
10659
|
-
else if (paramLimit === undefined && (0, types_1.
|
10660
|
-
|
10698
|
+
else if (paramLimit === undefined && (0, types_1.isUnpackedClass)(typeArg.type)) {
|
10699
|
+
if ((_a = typeArg.type.tupleTypeArguments) === null || _a === void 0 ? void 0 : _a.some((typeArg) => (0, types_1.isVariadicTypeVar)(typeArg.type) || typeArg.isUnbounded)) {
|
10700
|
+
noteSawUnpacked(typeArg);
|
10701
|
+
}
|
10661
10702
|
validateTypeArg(typeArg, { allowUnpackedTuples: true });
|
10662
10703
|
}
|
10663
10704
|
else {
|
@@ -10670,7 +10711,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10670
10711
|
// Make sure the argument list count is correct.
|
10671
10712
|
if (paramLimit !== undefined) {
|
10672
10713
|
if (typeArgs && typeArgTypes.length > paramLimit) {
|
10673
|
-
addError(localize_1.
|
10714
|
+
addError(localize_1.LocMessage.typeArgsTooMany().format({
|
10674
10715
|
name: classType.aliasName || classType.details.name,
|
10675
10716
|
expected: paramLimit,
|
10676
10717
|
received: typeArgTypes.length,
|
@@ -10698,9 +10739,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10698
10739
|
if (tupleTypeArgTypes.length === 1 && !tupleTypeArgTypes[0].isUnbounded) {
|
10699
10740
|
tupleTypeArgTypes[0] = { type: tupleTypeArgTypes[0].type, isUnbounded: true };
|
10700
10741
|
}
|
10701
|
-
else {
|
10702
|
-
addError(localize_1.Localizer.Diagnostic.ellipsisSecondArg(), typeArg.node);
|
10703
|
-
}
|
10704
10742
|
}
|
10705
10743
|
else if ((0, types_1.isUnpackedClass)(typeArg.type) && typeArg.type.tupleTypeArguments) {
|
10706
10744
|
(0, collectionUtils_1.appendArray)(tupleTypeArgTypes, typeArg.type.tupleTypeArguments);
|
@@ -10730,7 +10768,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10730
10768
|
// depends on whether we're evaluating a type annotation or
|
10731
10769
|
// we're in some other context.
|
10732
10770
|
if ((flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0) {
|
10733
|
-
addError(localize_1.
|
10771
|
+
addError(localize_1.LocMessage.unionTypeArgCount(), errorNode);
|
10734
10772
|
return types_1.NeverType.createNever();
|
10735
10773
|
}
|
10736
10774
|
return classType;
|
@@ -10753,7 +10791,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10753
10791
|
allowSingleTypeArg = true;
|
10754
10792
|
}
|
10755
10793
|
else {
|
10756
|
-
addDiagnostic(
|
10794
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.unionUnpackedTuple(), errorNode);
|
10757
10795
|
types.push(types_1.UnknownType.create());
|
10758
10796
|
}
|
10759
10797
|
}
|
@@ -10766,7 +10804,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10766
10804
|
allowSingleTypeArg = true;
|
10767
10805
|
}
|
10768
10806
|
else {
|
10769
|
-
addDiagnostic(
|
10807
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.unionUnpackedTypeVarTuple(), errorNode);
|
10770
10808
|
typeArgType = types_1.UnknownType.create();
|
10771
10809
|
}
|
10772
10810
|
}
|
@@ -10777,11 +10815,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10777
10815
|
// is allowed if it's an unpacked variadic type var or tuple. None is also allowed
|
10778
10816
|
// since it is used to define NoReturn in typeshed stubs).
|
10779
10817
|
if (types.length === 1 && !allowSingleTypeArg && !(0, typeUtils_1.isNoneInstance)(types[0])) {
|
10780
|
-
addDiagnostic(
|
10818
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeArguments, localize_1.LocMessage.unionTypeArgCount(), errorNode);
|
10781
10819
|
}
|
10782
10820
|
let unionType = (0, types_1.combineTypes)(types);
|
10783
10821
|
if (unionClassType && (0, types_1.isInstantiableClass)(unionClassType)) {
|
10784
|
-
unionType = types_1.TypeBase.cloneAsSpecialForm(unionType, unionClassType);
|
10822
|
+
unionType = types_1.TypeBase.cloneAsSpecialForm(unionType, types_1.ClassType.cloneAsInstance(unionClassType));
|
10785
10823
|
}
|
10786
10824
|
return unionType;
|
10787
10825
|
}
|
@@ -10793,7 +10831,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10793
10831
|
// depends on whether we're evaluating a type annotation or
|
10794
10832
|
// we're in some other context.
|
10795
10833
|
if ((flags & (256 /* EvaluatorFlags.ExpectingTypeAnnotation */ | 262144 /* EvaluatorFlags.DisallowNakedGeneric */)) !== 0) {
|
10796
|
-
addError(localize_1.
|
10834
|
+
addError(localize_1.LocMessage.genericTypeArgMissing(), errorNode);
|
10797
10835
|
}
|
10798
10836
|
return classType;
|
10799
10837
|
}
|
@@ -10801,16 +10839,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10801
10839
|
if (typeArgs) {
|
10802
10840
|
// Make sure there's at least one type arg.
|
10803
10841
|
if (typeArgs.length === 0) {
|
10804
|
-
addError(localize_1.
|
10842
|
+
addError(localize_1.LocMessage.genericTypeArgMissing(), errorNode);
|
10805
10843
|
}
|
10806
10844
|
// Make sure that all of the type args are typeVars and are unique.
|
10807
10845
|
typeArgs.forEach((typeArg) => {
|
10808
10846
|
if (!(0, types_1.isTypeVar)(typeArg.type)) {
|
10809
|
-
addError(localize_1.
|
10847
|
+
addError(localize_1.LocMessage.genericTypeArgTypeVar(), typeArg.node);
|
10810
10848
|
}
|
10811
10849
|
else {
|
10812
10850
|
if (uniqueTypeVars.some((t) => (0, types_1.isTypeSame)(t, typeArg.type))) {
|
10813
|
-
addError(localize_1.
|
10851
|
+
addError(localize_1.LocMessage.genericTypeArgUnique(), typeArg.node);
|
10814
10852
|
}
|
10815
10853
|
uniqueTypeVars.push(typeArg.type);
|
10816
10854
|
}
|
@@ -10859,14 +10897,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10859
10897
|
// Verify that we have at most one variadic type variable.
|
10860
10898
|
const variadics = typeParameters.filter((param) => (0, types_1.isVariadicTypeVar)(param));
|
10861
10899
|
if (variadics.length > 1) {
|
10862
|
-
addError(localize_1.
|
10900
|
+
addError(localize_1.LocMessage.variadicTypeParamTooManyAlias().format({
|
10863
10901
|
names: variadics.map((v) => `"${v.details.name}"`).join(', '),
|
10864
10902
|
}), errorNode);
|
10865
10903
|
}
|
10866
10904
|
if (!isPep695Syntax && !isPep695TypeVarType) {
|
10867
10905
|
const boundTypeVars = typeParameters.filter((typeVar) => typeVar.scopeId !== typeAliasScopeId && typeVar.scopeType === 0 /* TypeVarScopeType.Class */);
|
10868
10906
|
if (boundTypeVars.length > 0) {
|
10869
|
-
addError(localize_1.
|
10907
|
+
addError(localize_1.LocMessage.genericTypeAliasBoundTypeVar().format({
|
10870
10908
|
names: boundTypeVars.map((t) => `${t.details.name}`).join(', '),
|
10871
10909
|
}), errorNode);
|
10872
10910
|
}
|
@@ -11081,7 +11119,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11081
11119
|
if (isDeclaredTypeAlias(node.leftExpression)) {
|
11082
11120
|
typeAliasNameNode = node.leftExpression.valueExpression;
|
11083
11121
|
if (!isLegalTypeAliasExpressionForm(node.rightExpression)) {
|
11084
|
-
addDiagnostic(
|
11122
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.typeAliasIllegalExpressionForm(), node.rightExpression);
|
11085
11123
|
}
|
11086
11124
|
}
|
11087
11125
|
else if (node.leftExpression.nodeType === 38 /* ParseNodeType.Name */) {
|
@@ -11132,7 +11170,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11132
11170
|
rightHandType = srcType;
|
11133
11171
|
if (node.leftExpression.nodeType === 38 /* ParseNodeType.Name */ && !node.typeAnnotationComment) {
|
11134
11172
|
rightHandType =
|
11135
|
-
(_a = (0, enums_1.transformTypeForPossibleEnumClass)(evaluatorInterface, node.leftExpression, () => rightHandType)) !== null && _a !== void 0 ? _a : rightHandType;
|
11173
|
+
(_a = (0, enums_1.transformTypeForPossibleEnumClass)(evaluatorInterface, node, node.leftExpression, () => rightHandType)) !== null && _a !== void 0 ? _a : rightHandType;
|
11136
11174
|
}
|
11137
11175
|
if (typeAliasNameNode) {
|
11138
11176
|
// If this was a speculative type alias, it becomes a real type alias
|
@@ -11144,7 +11182,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11144
11182
|
/* isPep695TypeVarType */ false);
|
11145
11183
|
(0, debug_1.assert)(typeAliasTypeVar !== undefined);
|
11146
11184
|
if ((0, typeUtils_1.isTypeAliasRecursive)(typeAliasTypeVar, rightHandType)) {
|
11147
|
-
addDiagnostic(
|
11185
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAliasIsRecursiveDirect().format({
|
11148
11186
|
name: typeAliasNameNode.value,
|
11149
11187
|
}), node.rightExpression);
|
11150
11188
|
rightHandType = types_1.UnknownType.create();
|
@@ -11243,7 +11281,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11243
11281
|
aliasType = transformTypeForTypeAlias(aliasType, nameNode, nameNode, isPep695Syntax,
|
11244
11282
|
/* isPep695TypeVarType */ true, typeParameters, typeParamNodes);
|
11245
11283
|
if ((0, typeUtils_1.isTypeAliasRecursive)(typeAliasTypeVar, aliasType)) {
|
11246
|
-
addDiagnostic(
|
11284
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAliasIsRecursiveDirect().format({
|
11247
11285
|
name: nameNode.value,
|
11248
11286
|
}), valueNode);
|
11249
11287
|
aliasType = types_1.UnknownType.create();
|
@@ -11364,7 +11402,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11364
11402
|
argType = types_1.UnknownType.create();
|
11365
11403
|
}
|
11366
11404
|
else {
|
11367
|
-
argType =
|
11405
|
+
argType = getTypeOfExpression(arg.valueExpression, exprFlags).type;
|
11406
|
+
if ((0, types_1.isTypeVar)(argType) && argType.specialForm && types_1.TypeBase.isInstance(argType.specialForm)) {
|
11407
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.baseClassInvalid(), arg);
|
11408
|
+
argType = types_1.UnknownType.create();
|
11409
|
+
}
|
11410
|
+
argType = makeTopLevelTypeVarsConcrete(argType);
|
11368
11411
|
}
|
11369
11412
|
// In some stub files, classes are conditionally defined (e.g. based
|
11370
11413
|
// on platform type). We'll assume that the conditional logic is correct
|
@@ -11386,7 +11429,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11386
11429
|
: types_1.UnknownType.create();
|
11387
11430
|
}
|
11388
11431
|
else if (!(0, types_1.isInstantiableClass)(argType)) {
|
11389
|
-
addDiagnostic(
|
11432
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.baseClassInvalid(), arg);
|
11390
11433
|
argType = types_1.UnknownType.create();
|
11391
11434
|
}
|
11392
11435
|
else {
|
@@ -11401,7 +11444,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11401
11444
|
if (!fileInfo.isStubFile &&
|
11402
11445
|
!types_1.ClassType.isTypingExtensionClass(argType) &&
|
11403
11446
|
fileInfo.executionEnvironment.pythonVersion < pythonVersion_1.PythonVersion.V3_7) {
|
11404
|
-
addError(localize_1.
|
11447
|
+
addError(localize_1.LocMessage.protocolIllegal(), arg.valueExpression);
|
11405
11448
|
}
|
11406
11449
|
classType.details.flags |= 8192 /* ClassTypeFlags.ProtocolClass */;
|
11407
11450
|
}
|
@@ -11426,19 +11469,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11426
11469
|
// Validate that the class isn't deriving from itself, creating a
|
11427
11470
|
// circular dependency.
|
11428
11471
|
if ((0, typeUtils_1.derivesFromClassRecursive)(argType, classType, /* ignoreUnknown */ true)) {
|
11429
|
-
addError(localize_1.
|
11472
|
+
addError(localize_1.LocMessage.baseClassCircular(), arg);
|
11430
11473
|
argType = types_1.UnknownType.create();
|
11431
11474
|
}
|
11432
11475
|
// If the class is attempting to derive from a TypeAliasType,
|
11433
11476
|
// generate an error.
|
11434
11477
|
if (argType.specialForm && types_1.ClassType.isBuiltIn(argType.specialForm, 'TypeAliasType')) {
|
11435
|
-
addError(localize_1.
|
11478
|
+
addError(localize_1.LocMessage.typeAliasTypeBaseClass(), arg);
|
11436
11479
|
argType = types_1.UnknownType.create();
|
11437
11480
|
}
|
11438
11481
|
}
|
11439
11482
|
}
|
11440
11483
|
if ((0, types_1.isUnknown)(argType)) {
|
11441
|
-
addDiagnostic(
|
11484
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUntypedBaseClass, localize_1.LocMessage.baseClassUnknown(), arg);
|
11442
11485
|
}
|
11443
11486
|
// Check for a duplicate class.
|
11444
11487
|
if (classType.details.baseClasses.some((prevBaseClass) => {
|
@@ -11446,7 +11489,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11446
11489
|
(0, types_1.isInstantiableClass)(argType) &&
|
11447
11490
|
types_1.ClassType.isSameGenericClass(argType, prevBaseClass));
|
11448
11491
|
})) {
|
11449
|
-
addDiagnostic(
|
11492
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.duplicateBaseClass(), arg.name || arg);
|
11450
11493
|
}
|
11451
11494
|
classType.details.baseClasses.push(argType);
|
11452
11495
|
if ((0, types_1.isInstantiableClass)(argType)) {
|
@@ -11467,7 +11510,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11467
11510
|
}
|
11468
11511
|
if (types_1.ClassType.isFinal(argType)) {
|
11469
11512
|
const className = printObjectTypeForClass(argType);
|
11470
|
-
addError(localize_1.
|
11513
|
+
addError(localize_1.LocMessage.baseClassFinal().format({ type: className }), arg.valueExpression);
|
11471
11514
|
}
|
11472
11515
|
}
|
11473
11516
|
(0, typeUtils_1.addTypeVarsToListIfUnique)(typeParameters, (0, typeUtils_1.getTypeVarArgumentsRecursive)(argType));
|
@@ -11475,12 +11518,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11475
11518
|
if (types_1.ClassType.isBuiltIn(argType, 'Generic')) {
|
11476
11519
|
// 'Generic' is implicitly added if type parameter syntax is used.
|
11477
11520
|
if (node.typeParameters) {
|
11478
|
-
addDiagnostic(
|
11521
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.genericBaseClassNotAllowed(), arg.valueExpression);
|
11479
11522
|
}
|
11480
11523
|
else {
|
11481
11524
|
if (!genericTypeParameters) {
|
11482
11525
|
if (protocolTypeParameters) {
|
11483
|
-
addDiagnostic(
|
11526
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.duplicateGenericAndProtocolBase(), arg.valueExpression);
|
11484
11527
|
}
|
11485
11528
|
genericTypeParameters = [];
|
11486
11529
|
(0, typeUtils_1.addTypeVarsToListIfUnique)(genericTypeParameters, (0, typeUtils_1.getTypeVarArgumentsRecursive)(argType));
|
@@ -11492,12 +11535,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11492
11535
|
argType.typeArguments.length > 0) {
|
11493
11536
|
if (!protocolTypeParameters) {
|
11494
11537
|
if (genericTypeParameters) {
|
11495
|
-
addDiagnostic(
|
11538
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.duplicateGenericAndProtocolBase(), arg.valueExpression);
|
11496
11539
|
}
|
11497
11540
|
protocolTypeParameters = [];
|
11498
11541
|
(0, typeUtils_1.addTypeVarsToListIfUnique)(protocolTypeParameters, (0, typeUtils_1.getTypeVarArgumentsRecursive)(argType));
|
11499
11542
|
if (node.typeParameters && protocolTypeParameters.length > 0) {
|
11500
|
-
addDiagnostic(
|
11543
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.protocolBaseClassWithTypeArgs(), arg.valueExpression);
|
11501
11544
|
protocolTypeParameters = [];
|
11502
11545
|
}
|
11503
11546
|
}
|
@@ -11510,19 +11553,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11510
11553
|
// PEP 589 specifies that the parameter must be either True or False.
|
11511
11554
|
const constArgValue = (0, staticExpressions_1.evaluateStaticBoolExpression)(arg.valueExpression, fileInfo.executionEnvironment, fileInfo.definedConstants);
|
11512
11555
|
if (constArgValue === undefined) {
|
11513
|
-
addError(localize_1.
|
11556
|
+
addError(localize_1.LocMessage.typedDictBoolParam().format({ name: arg.name.value }), arg.valueExpression);
|
11514
11557
|
}
|
11515
11558
|
else if (arg.name.value === 'total' && !constArgValue) {
|
11516
11559
|
classType.details.flags |= 256 /* ClassTypeFlags.CanOmitDictValues */;
|
11517
11560
|
}
|
11518
11561
|
}
|
11519
11562
|
else {
|
11520
|
-
addError(localize_1.
|
11563
|
+
addError(localize_1.LocMessage.typedDictInitsubclassParameter().format({ name: arg.name.value }), arg);
|
11521
11564
|
}
|
11522
11565
|
}
|
11523
11566
|
else if (arg.name.value === 'metaclass') {
|
11524
11567
|
if (metaclassNode) {
|
11525
|
-
addError(localize_1.
|
11568
|
+
addError(localize_1.LocMessage.metaclassDuplicate(), arg);
|
11526
11569
|
}
|
11527
11570
|
else {
|
11528
11571
|
metaclassNode = arg.valueExpression;
|
@@ -11554,7 +11597,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11554
11597
|
}
|
11555
11598
|
});
|
11556
11599
|
if (derivesFromNamedTuple && foundIllegalBaseClass) {
|
11557
|
-
addDiagnostic(
|
11600
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.namedTupleMultipleInheritance(), node.name);
|
11558
11601
|
}
|
11559
11602
|
}
|
11560
11603
|
// Make sure we don't have 'object' derive from itself. Infinite
|
@@ -11578,7 +11621,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11578
11621
|
// Make sure there's at most one variadic type parameter.
|
11579
11622
|
const variadics = classType.details.typeParameters.filter((param) => (0, types_1.isVariadicTypeVar)(param));
|
11580
11623
|
if (variadics.length > 1) {
|
11581
|
-
addError(localize_1.
|
11624
|
+
addError(localize_1.LocMessage.variadicTypeParamTooManyClass().format({
|
11582
11625
|
names: variadics.map((v) => `"${v.details.name}"`).join(', '),
|
11583
11626
|
}), node.name, textRange_1.TextRange.combine(node.arguments) || node.name);
|
11584
11627
|
}
|
@@ -11593,7 +11636,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11593
11636
|
validateTypeParameterDefault(bestErrorNode, typeParam, classType.details.typeParameters.slice(0, index), classType.details.typeVarScopeId);
|
11594
11637
|
});
|
11595
11638
|
if (!(0, typeUtils_1.computeMroLinearization)(classType)) {
|
11596
|
-
addError(localize_1.
|
11639
|
+
addError(localize_1.LocMessage.methodOrdering(), node.name);
|
11597
11640
|
}
|
11598
11641
|
// The scope for this class becomes the "fields" for the corresponding type.
|
11599
11642
|
const innerScope = ScopeUtils.getScopeForNode(node.suite);
|
@@ -11663,14 +11706,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11663
11706
|
const metaclassType = getTypeOfExpression(metaclassNode, exprFlags).type;
|
11664
11707
|
if ((0, types_1.isInstantiableClass)(metaclassType) || (0, types_1.isUnknown)(metaclassType)) {
|
11665
11708
|
if ((0, typeUtils_1.requiresSpecialization)(metaclassType, { ignorePseudoGeneric: true })) {
|
11666
|
-
addDiagnostic(
|
11709
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.metaclassIsGeneric(), metaclassNode);
|
11667
11710
|
}
|
11668
11711
|
classType.details.declaredMetaclass = metaclassType;
|
11669
11712
|
if ((0, types_1.isInstantiableClass)(metaclassType)) {
|
11670
|
-
if (
|
11713
|
+
if ((0, enums_1.isEnumMetaclass)(metaclassType)) {
|
11671
11714
|
classType.details.flags |= 1048576 /* ClassTypeFlags.EnumClass */;
|
11672
11715
|
}
|
11673
|
-
|
11716
|
+
if (types_1.ClassType.isBuiltIn(metaclassType, 'ABCMeta')) {
|
11674
11717
|
classType.details.flags |= 1024 /* ClassTypeFlags.SupportsAbstractMethods */;
|
11675
11718
|
}
|
11676
11719
|
}
|
@@ -11689,7 +11732,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11689
11732
|
if (unknownOrAny && (0, types_1.isUnknown)(unknownOrAny)) {
|
11690
11733
|
// Report this error only on the first unknown type.
|
11691
11734
|
if (!foundUnknown) {
|
11692
|
-
addDiagnostic(
|
11735
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUntypedClassDecorator, localize_1.LocMessage.classDecoratorTypeUnknown(), node.decorators[i].expression);
|
11693
11736
|
foundUnknown = true;
|
11694
11737
|
}
|
11695
11738
|
}
|
@@ -11734,11 +11777,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11734
11777
|
!types_1.ClassType.isTypedDictClass(baseClass) &&
|
11735
11778
|
!types_1.ClassType.isBuiltIn(baseClass, ['_TypedDict', 'Generic'])) {
|
11736
11779
|
foundInvalidBaseClass = true;
|
11737
|
-
diag.addMessage(localize_1.
|
11780
|
+
diag.addMessage(localize_1.LocAddendum.typedDictBaseClass().format({ type: baseClass.details.name }));
|
11738
11781
|
}
|
11739
11782
|
});
|
11740
11783
|
if (foundInvalidBaseClass) {
|
11741
|
-
addError(localize_1.
|
11784
|
+
addError(localize_1.LocMessage.typedDictBaseClass() + diag.getString(), node.name);
|
11742
11785
|
}
|
11743
11786
|
(0, typedDicts_1.synthesizeTypedDictClassMethods)(evaluatorInterface, node, classType, (0, types_1.isClass)(decoratedType) && types_1.ClassType.isFinal(decoratedType));
|
11744
11787
|
}
|
@@ -11814,7 +11857,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11814
11857
|
!typeParam.details.isSynthesizedSelf) {
|
11815
11858
|
const typeVarWithDefault = otherLiveTypeParams.find((param) => param.details.defaultType && param.scopeId === scopeId);
|
11816
11859
|
if (typeVarWithDefault) {
|
11817
|
-
addDiagnostic(
|
11860
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarWithoutDefault().format({
|
11818
11861
|
name: typeParam.details.name,
|
11819
11862
|
other: typeVarWithDefault.details.name,
|
11820
11863
|
}), errorNode);
|
@@ -11827,9 +11870,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11827
11870
|
if (invalidTypeVars.size > 0) {
|
11828
11871
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
11829
11872
|
invalidTypeVars.forEach((name) => {
|
11830
|
-
diag.addMessage(localize_1.
|
11873
|
+
diag.addMessage(localize_1.LocAddendum.typeVarDefaultOutOfScope().format({ name }));
|
11831
11874
|
});
|
11832
|
-
addDiagnostic(
|
11875
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarDefaultInvalidTypeVar().format({
|
11833
11876
|
name: typeParam.details.name,
|
11834
11877
|
}) + diag.getString(), errorNode);
|
11835
11878
|
}
|
@@ -11851,11 +11894,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11851
11894
|
param.computedVariance = 1 /* Variance.Unknown */;
|
11852
11895
|
}
|
11853
11896
|
});
|
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
11897
|
const dummyTypeObject = types_1.ClassType.createInstantiable('__varianceDummy', '', '', uri_1.Uri.empty(), 0, 0, undefined, undefined);
|
11858
|
-
|
11898
|
+
classType.details.typeParameters.forEach((param, paramIndex) => {
|
11859
11899
|
// Skip variadics and ParamSpecs.
|
11860
11900
|
if (param.details.isVariadic || param.details.isParamSpec) {
|
11861
11901
|
return;
|
@@ -11866,7 +11906,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11866
11906
|
}
|
11867
11907
|
// Replace all type arguments with a dummy type except for the
|
11868
11908
|
// TypeVar of interest, which is replaced with an object instance.
|
11869
|
-
const srcTypeArgs =
|
11909
|
+
const srcTypeArgs = classType.details.typeParameters.map((p, i) => {
|
11870
11910
|
if (p.details.isVariadic) {
|
11871
11911
|
return p;
|
11872
11912
|
}
|
@@ -11875,20 +11915,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11875
11915
|
});
|
11876
11916
|
// Replace all type arguments with a dummy type except for the
|
11877
11917
|
// TypeVar of interest, which is replaced with itself.
|
11878
|
-
const destTypeArgs =
|
11918
|
+
const destTypeArgs = classType.details.typeParameters.map((p, i) => {
|
11879
11919
|
return i === paramIndex || p.details.isVariadic ? p : dummyTypeObject;
|
11880
11920
|
});
|
11881
|
-
const srcType = types_1.ClassType.cloneForSpecialization(
|
11882
|
-
|
11883
|
-
const destType = types_1.ClassType.cloneForSpecialization(updatedClassType, destTypeArgs,
|
11921
|
+
const srcType = types_1.ClassType.cloneForSpecialization(classType, srcTypeArgs, /* isTypeArgumentExplicit */ true);
|
11922
|
+
const destType = types_1.ClassType.cloneForSpecialization(classType, destTypeArgs,
|
11884
11923
|
/* isTypeArgumentExplicit */ true);
|
11885
|
-
const isDestSubtypeOfSrc = assignClassToSelf(srcType, destType, /*
|
11924
|
+
const isDestSubtypeOfSrc = assignClassToSelf(srcType, destType, 3 /* Variance.Covariant */,
|
11925
|
+
/* ignoreBaseClassVariance */ false);
|
11886
11926
|
let inferredVariance;
|
11887
11927
|
if (isDestSubtypeOfSrc) {
|
11888
11928
|
inferredVariance = 3 /* Variance.Covariant */;
|
11889
11929
|
}
|
11890
11930
|
else {
|
11891
|
-
const isSrcSubtypeOfDest = assignClassToSelf(destType, srcType, /*
|
11931
|
+
const isSrcSubtypeOfDest = assignClassToSelf(destType, srcType, 4 /* Variance.Contravariant */,
|
11932
|
+
/* ignoreBaseClassVariance */ false);
|
11892
11933
|
if (isSrcSubtypeOfDest) {
|
11893
11934
|
inferredVariance = 4 /* Variance.Contravariant */;
|
11894
11935
|
}
|
@@ -11938,11 +11979,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11938
11979
|
else if (!(0, typeUtils_1.derivesFromClassRecursive)(effectiveMetaclass, baseClassMeta, /* ignoreUnknown */ false)) {
|
11939
11980
|
if (!reportedMetaclassConflict) {
|
11940
11981
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
11941
|
-
diag.addMessage(localize_1.
|
11982
|
+
diag.addMessage(localize_1.LocAddendum.metaclassConflict().format({
|
11942
11983
|
metaclass1: printType((0, typeUtils_1.convertToInstance)(effectiveMetaclass)),
|
11943
11984
|
metaclass2: printType((0, typeUtils_1.convertToInstance)(baseClassMeta)),
|
11944
11985
|
}));
|
11945
|
-
addDiagnostic(
|
11986
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.metaclassConflict() + diag.getString(), errorNode);
|
11946
11987
|
// Don't report more than once.
|
11947
11988
|
reportedMetaclassConflict = true;
|
11948
11989
|
}
|
@@ -11952,9 +11993,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11952
11993
|
effectiveMetaclass = baseClassMeta ? types_1.UnknownType.create() : undefined;
|
11953
11994
|
break;
|
11954
11995
|
}
|
11955
|
-
if (types_1.ClassType.isEnumClass(baseClass)) {
|
11956
|
-
classType.details.flags |= 1048576 /* ClassTypeFlags.EnumClass */;
|
11957
|
-
}
|
11958
11996
|
}
|
11959
11997
|
else {
|
11960
11998
|
// If one of the base classes is unknown, then the effective
|
@@ -11984,10 +12022,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11984
12022
|
});
|
11985
12023
|
if (missingFromGeneric.length > 0) {
|
11986
12024
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
11987
|
-
diag.addMessage(localize_1.
|
12025
|
+
diag.addMessage(localize_1.LocAddendum.typeVarsMissing().format({
|
11988
12026
|
names: missingFromGeneric.map((typeVar) => `"${typeVar.details.name}"`).join(', '),
|
11989
12027
|
}));
|
11990
|
-
addDiagnostic(
|
12028
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarsNotInGenericOrProtocol() + diag.getString(), errorNode);
|
11991
12029
|
}
|
11992
12030
|
}
|
11993
12031
|
// Records the fact that the specified class requires "deferred completion" because
|
@@ -12033,7 +12071,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12033
12071
|
function completeClassTypeDeferred(type, errorNode) {
|
12034
12072
|
// Recompute the MRO linearization.
|
12035
12073
|
if (!(0, typeUtils_1.computeMroLinearization)(type)) {
|
12036
|
-
addError(localize_1.
|
12074
|
+
addError(localize_1.LocMessage.methodOrdering(), errorNode);
|
12037
12075
|
}
|
12038
12076
|
// Recompute the effective metaclass.
|
12039
12077
|
computeEffectiveMetaclass(type, errorNode);
|
@@ -12090,7 +12128,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12090
12128
|
paramMap.delete(arg.name.value);
|
12091
12129
|
}
|
12092
12130
|
else {
|
12093
|
-
addDiagnostic(
|
12131
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.paramNameMissing().format({ name: arg.name.value }), (_c = arg.name) !== null && _c !== void 0 ? _c : errorNode);
|
12094
12132
|
}
|
12095
12133
|
}
|
12096
12134
|
});
|
@@ -12105,9 +12143,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12105
12143
|
});
|
12106
12144
|
if (unassignedParams.length > 0) {
|
12107
12145
|
const missingParamNames = unassignedParams.map((p) => `"${p}"`).join(', ');
|
12108
|
-
addDiagnostic(
|
12109
|
-
? localize_1.
|
12110
|
-
: localize_1.
|
12146
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, unassignedParams.length === 1
|
12147
|
+
? localize_1.LocMessage.argMissingForParam().format({ name: missingParamNames })
|
12148
|
+
: localize_1.LocMessage.argMissingForParams().format({ names: missingParamNames }), errorNode);
|
12111
12149
|
}
|
12112
12150
|
}
|
12113
12151
|
}
|
@@ -12127,7 +12165,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12127
12165
|
/* typeVarContext */ undefined,
|
12128
12166
|
/* skipUnknownArgCheck */ false, (0, typeUtils_1.makeInferenceContext)(getNoneType()));
|
12129
12167
|
if (callResult.argumentErrors) {
|
12130
|
-
const diag = addDiagnostic(
|
12168
|
+
const diag = addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.initSubclassCallFailed(), node.name);
|
12131
12169
|
const initSubclassFunction = (0, types_1.isOverloadedFunction)(initSubclassMethodType)
|
12132
12170
|
? types_1.OverloadedFunctionType.getOverloads(initSubclassMethodType)[0]
|
12133
12171
|
: initSubclassMethodType;
|
@@ -12135,7 +12173,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12135
12173
|
? initSubclassFunction.details.declaration
|
12136
12174
|
: undefined;
|
12137
12175
|
if (diag && initSubclassDecl) {
|
12138
|
-
diag.addRelatedInfo(localize_1.
|
12176
|
+
diag.addRelatedInfo(localize_1.LocAddendum.initSubclassLocation().format({
|
12139
12177
|
name: printType((0, typeUtils_1.convertToInstance)(initSubclassMethodInfo.classType)),
|
12140
12178
|
}), initSubclassDecl.uri, initSubclassDecl.range);
|
12141
12179
|
}
|
@@ -12151,6 +12189,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12151
12189
|
});
|
12152
12190
|
}
|
12153
12191
|
function getTypeOfFunction(node) {
|
12192
|
+
var _a;
|
12154
12193
|
initializedBasicTypes(node);
|
12155
12194
|
// Is this predecorated function type cached?
|
12156
12195
|
let functionType = readTypeCache(node.name, 0 /* EvaluatorFlags.None */);
|
@@ -12189,8 +12228,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12189
12228
|
if (unknownOrAny && (0, types_1.isUnknown)(unknownOrAny)) {
|
12190
12229
|
// Report this error only on the first unknown type.
|
12191
12230
|
if (!foundUnknown) {
|
12192
|
-
|
12193
|
-
addDiagnostic(fileInfo.diagnosticRuleSet.reportUntypedFunctionDecorator, diagnosticRules_1.DiagnosticRule.reportUntypedFunctionDecorator, localize_1.Localizer.Diagnostic.functionDecoratorTypeUnknown(), node.decorators[i].expression);
|
12231
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUntypedFunctionDecorator, localize_1.LocMessage.functionDecoratorTypeUnknown(), node.decorators[i].expression);
|
12194
12232
|
foundUnknown = true;
|
12195
12233
|
}
|
12196
12234
|
}
|
@@ -12199,6 +12237,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12199
12237
|
decoratedType = newDecoratedType;
|
12200
12238
|
}
|
12201
12239
|
}
|
12240
|
+
// In case this is an enum class and a method wrapped in an enum.member.
|
12241
|
+
decoratedType =
|
12242
|
+
(_a = (0, enums_1.transformTypeForPossibleEnumClass)(evaluatorInterface, node, node.name, () => decoratedType)) !== null && _a !== void 0 ? _a : decoratedType;
|
12202
12243
|
// See if there are any overloads provided by previous function declarations.
|
12203
12244
|
if ((0, types_1.isFunction)(decoratedType)) {
|
12204
12245
|
decoratedType.details.deprecatedMessage = functionType.details.deprecatedMessage;
|
@@ -12295,7 +12336,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12295
12336
|
firstCommentAnnotationIndex = 0;
|
12296
12337
|
}
|
12297
12338
|
else if (received !== expected) {
|
12298
|
-
addError(localize_1.
|
12339
|
+
addError(localize_1.LocMessage.annotatedParamCountMismatch().format({
|
12299
12340
|
expected,
|
12300
12341
|
received,
|
12301
12342
|
}), node.functionAnnotationComment);
|
@@ -12347,9 +12388,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12347
12388
|
}
|
12348
12389
|
}
|
12349
12390
|
if (paramTypeNode) {
|
12350
|
-
|
12391
|
+
if ((functionInfo.flags & 524288 /* FunctionTypeFlags.NoTypeCheck */) !== 0) {
|
12392
|
+
annotatedType = types_1.UnknownType.create();
|
12393
|
+
}
|
12394
|
+
else {
|
12395
|
+
annotatedType = getTypeOfParameterAnnotation(paramTypeNode, param.category);
|
12396
|
+
}
|
12351
12397
|
if ((0, types_1.isVariadicTypeVar)(annotatedType) && !annotatedType.isVariadicUnpacked) {
|
12352
|
-
addError(localize_1.
|
12398
|
+
addError(localize_1.LocMessage.unpackedTypeVarTupleExpected().format({
|
12353
12399
|
name1: annotatedType.details.name,
|
12354
12400
|
name2: annotatedType.details.name,
|
12355
12401
|
}), paramTypeNode);
|
@@ -12394,7 +12440,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12394
12440
|
}
|
12395
12441
|
}
|
12396
12442
|
if (!assignType(annotatedType, defaultValueType, diagAddendum, typeVarContext)) {
|
12397
|
-
addDiagnostic(
|
12443
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportArgumentType, localize_1.LocMessage.paramAssignmentMismatch().format({
|
12398
12444
|
sourceType: printType(defaultValueType),
|
12399
12445
|
paramType: printType(annotatedType),
|
12400
12446
|
}) + diagAddendum.getString(), param.defaultValue);
|
@@ -12842,6 +12888,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12842
12888
|
isIncomplete = true;
|
12843
12889
|
}
|
12844
12890
|
let returnType = returnTypeResult.type;
|
12891
|
+
// If the type is a special form, use the special form instead.
|
12892
|
+
if (returnType.specialForm) {
|
12893
|
+
returnType = returnType.specialForm;
|
12894
|
+
}
|
12845
12895
|
// If the return type includes an instance of a class with isEmptyContainer
|
12846
12896
|
// set, clear that because we don't want this flag to "leak" into the
|
12847
12897
|
// inferred return type.
|
@@ -13039,8 +13089,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13039
13089
|
let exprType = exprTypeResult.type;
|
13040
13090
|
const isAsync = node.parent && node.parent.nodeType === 58 /* ParseNodeType.With */ && !!node.parent.isAsync;
|
13041
13091
|
if ((0, typeUtils_1.isOptionalType)(exprType)) {
|
13042
|
-
|
13043
|
-
addDiagnostic(fileInfo.diagnosticRuleSet.reportOptionalContextManager, diagnosticRules_1.DiagnosticRule.reportOptionalContextManager, localize_1.Localizer.Diagnostic.noneNotUsableWith(), node.expression);
|
13092
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportOptionalContextManager, localize_1.LocMessage.noneNotUsableWith(), node.expression);
|
13044
13093
|
exprType = (0, typeUtils_1.removeNoneFromUnion)(exprType);
|
13045
13094
|
}
|
13046
13095
|
// Verify that the target has an __enter__ or __aenter__ method defined.
|
@@ -13064,12 +13113,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13064
13113
|
if (!isAsync) {
|
13065
13114
|
if (getTypeOfMagicMethodCall(subtype, '__aenter__', [], node.expression,
|
13066
13115
|
/* inferenceContext */ undefined)) {
|
13067
|
-
additionalHelp.addMessage(localize_1.
|
13116
|
+
additionalHelp.addMessage(localize_1.LocAddendum.asyncHelp());
|
13068
13117
|
}
|
13069
13118
|
}
|
13070
13119
|
}
|
13071
|
-
|
13072
|
-
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeNotUsableWith().format({ type: printType(subtype), method: enterMethodName }) +
|
13120
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeNotUsableWith().format({ type: printType(subtype), method: enterMethodName }) +
|
13073
13121
|
additionalHelp.getString(), node.expression);
|
13074
13122
|
return types_1.UnknownType.create();
|
13075
13123
|
});
|
@@ -13088,8 +13136,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13088
13136
|
return;
|
13089
13137
|
}
|
13090
13138
|
}
|
13091
|
-
|
13092
|
-
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeNotUsableWith().format({ type: printType(subtype), method: exitMethodName }), node.expression);
|
13139
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeNotUsableWith().format({ type: printType(subtype), method: exitMethodName }), node.expression);
|
13093
13140
|
});
|
13094
13141
|
if (node.target) {
|
13095
13142
|
assignTypeToExpression(node.target, scopedType, !!exprTypeResult.isIncomplete, node.target);
|
@@ -13183,7 +13230,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13183
13230
|
reportError = true;
|
13184
13231
|
}
|
13185
13232
|
if (reportError) {
|
13186
|
-
addDiagnostic(
|
13233
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportAttributeAccessIssue, localize_1.LocMessage.importSymbolUnknown().format({ name: node.name.value }), node.name);
|
13187
13234
|
}
|
13188
13235
|
}
|
13189
13236
|
if (!symbolType) {
|
@@ -13264,7 +13311,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13264
13311
|
}
|
13265
13312
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
13266
13313
|
if (!assignType(declaredType, importedSymbolType, diagAddendum)) {
|
13267
|
-
addDiagnostic(
|
13314
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportAssignmentType, localize_1.LocMessage.typeAssignmentMismatchWildcard().format({
|
13268
13315
|
...printSrcDestTypes(importedSymbolType, declaredType),
|
13269
13316
|
name,
|
13270
13317
|
}) + diagAddendum.getString(), node, (_b = node.wildcardToken) !== null && _b !== void 0 ? _b : node);
|
@@ -13347,18 +13394,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13347
13394
|
}
|
13348
13395
|
if (node.nodeType === 23 /* ParseNodeType.ImportFromAs */) {
|
13349
13396
|
if (resolvedAliasInfo.isPrivate) {
|
13350
|
-
addDiagnostic(
|
13397
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportPrivateUsage, localize_1.LocMessage.privateUsedOutsideOfModule().format({
|
13351
13398
|
name: node.name.value,
|
13352
13399
|
}), node.name);
|
13353
13400
|
}
|
13354
13401
|
if (resolvedAliasInfo.privatePyTypedImporter) {
|
13355
13402
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
13356
13403
|
if (resolvedAliasInfo.privatePyTypedImported) {
|
13357
|
-
diag.addMessage(localize_1.
|
13404
|
+
diag.addMessage(localize_1.LocAddendum.privateImportFromPyTypedSource().format({
|
13358
13405
|
module: resolvedAliasInfo.privatePyTypedImported,
|
13359
13406
|
}));
|
13360
13407
|
}
|
13361
|
-
addDiagnostic(
|
13408
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportPrivateImportUsage, localize_1.LocMessage.privateImportFromPyTypedModule().format({
|
13362
13409
|
name: node.name.value,
|
13363
13410
|
module: resolvedAliasInfo.privatePyTypedImporter,
|
13364
13411
|
}) + diag.getString(), node.name);
|
@@ -13450,9 +13497,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13450
13497
|
// See if the expression is part of a pattern used in a case statement.
|
13451
13498
|
const possibleCaseNode = ParseTreeUtils.getParentNodeOfType(node, 64 /* ParseNodeType.Case */);
|
13452
13499
|
if (possibleCaseNode) {
|
13453
|
-
|
13454
|
-
|
13455
|
-
evaluateTypesForCaseStatement(caseNode);
|
13500
|
+
if (ParseTreeUtils.isNodeContainedWithin(node, possibleCaseNode.pattern)) {
|
13501
|
+
evaluateTypesForCaseStatement(possibleCaseNode);
|
13456
13502
|
return;
|
13457
13503
|
}
|
13458
13504
|
}
|
@@ -13856,13 +13902,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13856
13902
|
}
|
13857
13903
|
case 'Never': {
|
13858
13904
|
if (typeArgs && typeArgs.length > 0) {
|
13859
|
-
addError(localize_1.
|
13905
|
+
addError(localize_1.LocMessage.typeArgsExpectingNone().format({ name: 'Never' }), typeArgs[0].node);
|
13860
13906
|
}
|
13861
13907
|
return { type: types_1.NeverType.createNever() };
|
13862
13908
|
}
|
13863
13909
|
case 'NoReturn': {
|
13864
13910
|
if (typeArgs && typeArgs.length > 0) {
|
13865
|
-
addError(localize_1.
|
13911
|
+
addError(localize_1.LocMessage.typeArgsExpectingNone().format({ name: 'NoReturn' }), typeArgs[0].node);
|
13866
13912
|
}
|
13867
13913
|
return { type: types_1.NeverType.createNoReturn() };
|
13868
13914
|
}
|
@@ -13885,7 +13931,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13885
13931
|
if ((flags &
|
13886
13932
|
(67108864 /* EvaluatorFlags.DisallowNonTypeSpecialForms */ | 256 /* EvaluatorFlags.ExpectingTypeAnnotation */)) !==
|
13887
13933
|
0) {
|
13888
|
-
addError(localize_1.
|
13934
|
+
addError(localize_1.LocMessage.protocolNotAllowed(), errorNode);
|
13889
13935
|
}
|
13890
13936
|
return {
|
13891
13937
|
type: createSpecialType(classType, typeArgs,
|
@@ -13897,7 +13943,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13897
13943
|
if ((flags &
|
13898
13944
|
(67108864 /* EvaluatorFlags.DisallowNonTypeSpecialForms */ | 256 /* EvaluatorFlags.ExpectingTypeAnnotation */)) !==
|
13899
13945
|
0) {
|
13900
|
-
addError(localize_1.
|
13946
|
+
addError(localize_1.LocMessage.typedDictNotAllowed(), errorNode);
|
13901
13947
|
}
|
13902
13948
|
break;
|
13903
13949
|
}
|
@@ -13905,7 +13951,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13905
13951
|
if ((flags &
|
13906
13952
|
(67108864 /* EvaluatorFlags.DisallowNonTypeSpecialForms */ | 256 /* EvaluatorFlags.ExpectingTypeAnnotation */)) !==
|
13907
13953
|
0) {
|
13908
|
-
addError(localize_1.
|
13954
|
+
addError(localize_1.LocMessage.literalNotAllowed(), errorNode);
|
13909
13955
|
}
|
13910
13956
|
break;
|
13911
13957
|
}
|
@@ -13927,13 +13973,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13927
13973
|
return { type: createFinalType(classType, errorNode, typeArgs, flags) };
|
13928
13974
|
}
|
13929
13975
|
case 'Annotated': {
|
13930
|
-
return createAnnotatedType(errorNode, typeArgs);
|
13976
|
+
return createAnnotatedType(classType, errorNode, typeArgs);
|
13931
13977
|
}
|
13932
13978
|
case 'Concatenate': {
|
13933
|
-
return { type: createConcatenateType(
|
13979
|
+
return { type: createConcatenateType(classType, errorNode, typeArgs, flags) };
|
13934
13980
|
}
|
13935
13981
|
case 'TypeGuard': {
|
13936
|
-
return { type: createTypeGuardType(
|
13982
|
+
return { type: createTypeGuardType(classType, errorNode, typeArgs, flags) };
|
13937
13983
|
}
|
13938
13984
|
case 'Unpack': {
|
13939
13985
|
return { type: createUnpackType(classType, errorNode, typeArgs, flags) };
|
@@ -13967,7 +14013,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13967
14013
|
if (typeArgs.length >= 1) {
|
13968
14014
|
// Treat type[function] as illegal.
|
13969
14015
|
if ((0, types_1.isFunction)(typeArgs[0].type) || (0, types_1.isOverloadedFunction)(typeArgs[0].type)) {
|
13970
|
-
addDiagnostic(
|
14016
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.typeAnnotationWithCallable(), typeArgs[0].node);
|
13971
14017
|
return { type: types_1.UnknownType.create() };
|
13972
14018
|
}
|
13973
14019
|
}
|
@@ -14010,7 +14056,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14010
14056
|
// Classes that accept inlined type dict type args allow only one.
|
14011
14057
|
if (typeArgs[0].inlinedTypeDict) {
|
14012
14058
|
if (typeArgs.length > 1) {
|
14013
|
-
addDiagnostic(
|
14059
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeArguments, localize_1.LocMessage.typeArgsTooMany().format({
|
14014
14060
|
name: classType.aliasName || classType.details.name,
|
14015
14061
|
expected: 1,
|
14016
14062
|
received: typeArgCount,
|
@@ -14020,14 +14066,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14020
14066
|
}
|
14021
14067
|
else if (typeArgCount > typeParameters.length) {
|
14022
14068
|
if (!types_1.ClassType.isPartiallyEvaluated(classType) && !types_1.ClassType.isTupleClass(classType)) {
|
14023
|
-
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
14024
14069
|
if (typeParameters.length === 0) {
|
14025
|
-
addDiagnostic(
|
14070
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeArguments, localize_1.LocMessage.typeArgsExpectingNone().format({
|
14026
14071
|
name: classType.aliasName || classType.details.name,
|
14027
14072
|
}), typeArgs[typeParameters.length].node);
|
14028
14073
|
}
|
14029
14074
|
else if (typeParameters.length !== 1 || !(0, types_1.isParamSpec)(typeParameters[0])) {
|
14030
|
-
addDiagnostic(
|
14075
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeArguments, localize_1.LocMessage.typeArgsTooMany().format({
|
14031
14076
|
name: classType.aliasName || classType.details.name,
|
14032
14077
|
expected: typeParameters.length,
|
14033
14078
|
received: typeArgCount,
|
@@ -14037,8 +14082,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14037
14082
|
}
|
14038
14083
|
}
|
14039
14084
|
else if (typeArgCount < minTypeArgCount) {
|
14040
|
-
|
14041
|
-
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeArgsTooFew().format({
|
14085
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeArguments, localize_1.LocMessage.typeArgsTooFew().format({
|
14042
14086
|
name: classType.aliasName || classType.details.name,
|
14043
14087
|
expected: minTypeArgCount,
|
14044
14088
|
received: typeArgCount,
|
@@ -14089,11 +14133,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14089
14133
|
else if (typeArgs.length > 1) {
|
14090
14134
|
const paramSpecTypeArg = typeArgs.find((typeArg) => (0, types_1.isParamSpec)(typeArg.type));
|
14091
14135
|
if (paramSpecTypeArg) {
|
14092
|
-
addError(localize_1.
|
14136
|
+
addError(localize_1.LocMessage.paramSpecContext(), paramSpecTypeArg.node);
|
14093
14137
|
}
|
14094
14138
|
const listTypeArg = typeArgs.find((typeArg) => !!typeArg.typeList);
|
14095
14139
|
if (listTypeArg) {
|
14096
|
-
addError(localize_1.
|
14140
|
+
addError(localize_1.LocMessage.typeArgListNotAllowed(), listTypeArg.node);
|
14097
14141
|
}
|
14098
14142
|
}
|
14099
14143
|
}
|
@@ -14179,7 +14223,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14179
14223
|
const destType = typeParameters[index];
|
14180
14224
|
const declaredVariance = destType.details.declaredVariance;
|
14181
14225
|
if (!(0, typeUtils_1.isVarianceOfTypeArgumentCompatible)(adjustedTypeArgType, declaredVariance)) {
|
14182
|
-
diag.addMessage(localize_1.
|
14226
|
+
diag.addMessage(localize_1.LocAddendum.varianceMismatchForClass().format({
|
14183
14227
|
typeVarName: printType(adjustedTypeArgType),
|
14184
14228
|
className: classType.details.name,
|
14185
14229
|
}));
|
@@ -14193,8 +14237,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14193
14237
|
// Avoid emitting this error for a partially-constructed class.
|
14194
14238
|
if (!(0, types_1.isClassInstance)(typeArgType) || !types_1.ClassType.isPartiallyEvaluated(typeArgType)) {
|
14195
14239
|
(0, debug_1.assert)(typeArgs !== undefined);
|
14196
|
-
|
14197
|
-
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeVarAssignmentMismatch().format({
|
14240
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeArguments, localize_1.LocMessage.typeVarAssignmentMismatch().format({
|
14198
14241
|
type: printType(typeArgType),
|
14199
14242
|
name: types_1.TypeVarType.getReadableName(typeParameters[index]),
|
14200
14243
|
}) + diag.getString(), typeArgs[index].node);
|
@@ -14671,7 +14714,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14671
14714
|
return declarations;
|
14672
14715
|
}
|
14673
14716
|
function getTypeForDeclaration(declaration) {
|
14674
|
-
var _a, _b, _c;
|
14717
|
+
var _a, _b, _c, _d;
|
14675
14718
|
switch (declaration.type) {
|
14676
14719
|
case 0 /* DeclarationType.Intrinsic */: {
|
14677
14720
|
if (declaration.intrinsicType === 'Any') {
|
@@ -14780,8 +14823,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14780
14823
|
if (declaredType) {
|
14781
14824
|
// Apply enum transform if appropriate.
|
14782
14825
|
if (declaration.node.nodeType === 38 /* ParseNodeType.Name */) {
|
14783
|
-
|
14784
|
-
|
14826
|
+
const variableNode = (_c = ParseTreeUtils.getParentNodeOfType(declaration.node, 3 /* ParseNodeType.Assignment */)) !== null && _c !== void 0 ? _c : ParseTreeUtils.getParentNodeOfType(declaration.node, 54 /* ParseNodeType.TypeAnnotation */);
|
14827
|
+
if (variableNode) {
|
14828
|
+
declaredType =
|
14829
|
+
(_d = (0, enums_1.transformTypeForPossibleEnumClass)(evaluatorInterface, variableNode, declaration.node, () => declaredType)) !== null && _d !== void 0 ? _d : declaredType;
|
14830
|
+
}
|
14785
14831
|
}
|
14786
14832
|
if ((0, types_1.isClassInstance)(declaredType) && types_1.ClassType.isBuiltIn(declaredType, 'TypeAlias')) {
|
14787
14833
|
return { type: undefined, isTypeAlias: true };
|
@@ -14811,7 +14857,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14811
14857
|
}
|
14812
14858
|
const runtimeType = getTypingType(node, runtimeClassName);
|
14813
14859
|
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
|
14860
|
+
let typeVar = types_1.TypeVarType.createInstantiable(node.name.value, node.typeParamCategory === parseNodes_1.TypeParameterCategory.ParamSpec);
|
14861
|
+
if (runtimeClass) {
|
14862
|
+
typeVar = types_1.TypeBase.cloneAsSpecialForm(typeVar, types_1.ClassType.cloneAsInstance(runtimeClass));
|
14863
|
+
}
|
14815
14864
|
typeVar.details.isTypeParamSyntax = true;
|
14816
14865
|
if (node.typeParamCategory === parseNodes_1.TypeParameterCategory.TypeVarTuple) {
|
14817
14866
|
typeVar.details.isVariadic = true;
|
@@ -14830,12 +14879,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14830
14879
|
ignorePseudoGeneric: true,
|
14831
14880
|
ignoreImplicitTypeArgs: true,
|
14832
14881
|
})) {
|
14833
|
-
addError(localize_1.
|
14882
|
+
addError(localize_1.LocMessage.typeVarBoundGeneric(), constraint);
|
14834
14883
|
}
|
14835
14884
|
return (0, typeUtils_1.convertToInstance)(constraintType);
|
14836
14885
|
});
|
14837
14886
|
if (constraints.length < 2) {
|
14838
|
-
addDiagnostic(
|
14887
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarSingleConstraint(), node.boundExpression);
|
14839
14888
|
}
|
14840
14889
|
else if (node.typeParamCategory === parseNodes_1.TypeParameterCategory.TypeVar) {
|
14841
14890
|
typeVar.details.constraints = constraints;
|
@@ -14844,7 +14893,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14844
14893
|
else {
|
14845
14894
|
const boundType = getTypeOfExpressionExpectingType(node.boundExpression).type;
|
14846
14895
|
if ((0, typeUtils_1.requiresSpecialization)(boundType, { ignorePseudoGeneric: true })) {
|
14847
|
-
addError(localize_1.
|
14896
|
+
addError(localize_1.LocMessage.typeVarConstraintGeneric(), node.boundExpression);
|
14848
14897
|
}
|
14849
14898
|
if (node.typeParamCategory === parseNodes_1.TypeParameterCategory.TypeVar) {
|
14850
14899
|
typeVar.details.boundType = (0, typeUtils_1.convertToInstance)(boundType);
|
@@ -14871,12 +14920,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14871
14920
|
});
|
14872
14921
|
if (typeVar.details.boundType) {
|
14873
14922
|
if (!assignType(typeVar.details.boundType, concreteDefaultType)) {
|
14874
|
-
addDiagnostic(
|
14923
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarDefaultBoundMismatch(), node.defaultExpression);
|
14875
14924
|
}
|
14876
14925
|
}
|
14877
14926
|
else if (typeVar.details.constraints.length > 0) {
|
14878
14927
|
if (!typeVar.details.constraints.some((constraint) => (0, types_1.isTypeSame)(constraint, concreteDefaultType))) {
|
14879
|
-
addDiagnostic(
|
14928
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarDefaultConstraintMismatch(), node.defaultExpression);
|
14880
14929
|
}
|
14881
14930
|
}
|
14882
14931
|
}
|
@@ -14901,7 +14950,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14901
14950
|
return typeVar;
|
14902
14951
|
}
|
14903
14952
|
function getInferredTypeOfDeclaration(symbol, decl) {
|
14904
|
-
var _a, _b, _c;
|
14953
|
+
var _a, _b, _c, _d;
|
14905
14954
|
const resolvedDecl = resolveAliasDeclaration(decl, /* resolveLocalNames */ true, {
|
14906
14955
|
allowExternallyHiddenAccess: AnalyzerNodeInfo.getFileInfo(decl.node).isStubFile,
|
14907
14956
|
});
|
@@ -15025,17 +15074,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15025
15074
|
evaluateTypesForStatement(typeSource);
|
15026
15075
|
})) === null || _c === void 0 ? void 0 : _c.type;
|
15027
15076
|
if (inferredType && resolvedDecl.node.nodeType === 38 /* ParseNodeType.Name */) {
|
15028
|
-
|
15029
|
-
|
15030
|
-
|
15031
|
-
(0,
|
15032
|
-
|
15033
|
-
|
15034
|
-
|
15035
|
-
|
15036
|
-
|
15037
|
-
|
15038
|
-
|
15077
|
+
const variableNode = (_d = ParseTreeUtils.getParentNodeOfType(resolvedDecl.node, 3 /* ParseNodeType.Assignment */)) !== null && _d !== void 0 ? _d : ParseTreeUtils.getParentNodeOfType(resolvedDecl.node, 54 /* ParseNodeType.TypeAnnotation */);
|
15078
|
+
if (variableNode) {
|
15079
|
+
// See if this is an enum member. If so, we need to handle it as a special case.
|
15080
|
+
const enumMemberType = (0, enums_1.transformTypeForPossibleEnumClass)(evaluatorInterface, variableNode, resolvedDecl.node, () => {
|
15081
|
+
var _a, _b;
|
15082
|
+
(0, debug_1.assert)(resolvedDecl.inferredTypeSource !== undefined);
|
15083
|
+
const inferredTypeSource = resolvedDecl.inferredTypeSource;
|
15084
|
+
return ((_b = (_a = evaluateTypeForSubnode(inferredTypeSource, () => {
|
15085
|
+
evaluateTypesForStatement(inferredTypeSource);
|
15086
|
+
})) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.UnknownType.create());
|
15087
|
+
});
|
15088
|
+
if (enumMemberType) {
|
15089
|
+
inferredType = enumMemberType;
|
15090
|
+
}
|
15039
15091
|
}
|
15040
15092
|
}
|
15041
15093
|
if (inferredType && isTypeAlias && resolvedDecl.typeAliasName) {
|
@@ -15738,7 +15790,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15738
15790
|
}
|
15739
15791
|
return types_1.UnknownType.create();
|
15740
15792
|
}
|
15741
|
-
function getTypeOfMemberInternal(member, selfClass) {
|
15793
|
+
function getTypeOfMemberInternal(errorNode, member, selfClass, flags) {
|
15742
15794
|
if ((0, types_1.isInstantiableClass)(member.classType)) {
|
15743
15795
|
const typeResult = getEffectiveTypeOfSymbolForUsage(member.symbol);
|
15744
15796
|
if (typeResult) {
|
@@ -15746,6 +15798,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15746
15798
|
// and cache the return type if necessary. This needs to be done
|
15747
15799
|
// prior to specializing.
|
15748
15800
|
inferReturnTypeIfNecessary(typeResult.type);
|
15801
|
+
if (member.isInstanceMember &&
|
15802
|
+
(flags & 1024 /* MemberAccessFlags.DisallowGenericInstanceVariableAccess */) !== 0) {
|
15803
|
+
let isGenericNonCallable = false;
|
15804
|
+
(0, typeUtils_1.doForEachSubtype)(typeResult.type, (subtype) => {
|
15805
|
+
if (!(0, types_1.isAnyOrUnknown)(subtype) && !(0, types_1.isFunction)(subtype) && !(0, types_1.isOverloadedFunction)(subtype)) {
|
15806
|
+
if ((0, typeUtils_1.requiresSpecialization)(typeResult.type, {
|
15807
|
+
ignoreSelf: true,
|
15808
|
+
ignoreImplicitTypeArgs: true,
|
15809
|
+
})) {
|
15810
|
+
isGenericNonCallable = true;
|
15811
|
+
}
|
15812
|
+
}
|
15813
|
+
});
|
15814
|
+
if (isGenericNonCallable && errorNode) {
|
15815
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.genericInstanceVariableAccess(), errorNode);
|
15816
|
+
}
|
15817
|
+
}
|
15749
15818
|
return {
|
15750
15819
|
type: (0, typeUtils_1.partiallySpecializeType)(typeResult.type, member.classType, selfClass),
|
15751
15820
|
isIncomplete: !!typeResult.isIncomplete,
|
@@ -15776,7 +15845,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15776
15845
|
return false;
|
15777
15846
|
}
|
15778
15847
|
if (types_1.ClassType.isFinal(destType) !== types_1.ClassType.isFinal(srcType)) {
|
15779
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
15848
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typedDictFinalMismatch().format({
|
15780
15849
|
sourceType: printType((0, typeUtils_1.convertToInstance)(srcType)),
|
15781
15850
|
destType: printType((0, typeUtils_1.convertToInstance)(destType)),
|
15782
15851
|
}));
|
@@ -15809,7 +15878,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15809
15878
|
// testing to see if the metaclass matches the protocol.
|
15810
15879
|
if (types_1.ClassType.isProtocolClass(destType) && !isDerivedFrom) {
|
15811
15880
|
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.
|
15881
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.protocolIncompatible().format({
|
15813
15882
|
sourceType: printType((0, typeUtils_1.convertToInstance)(srcType)),
|
15814
15883
|
destType: printType((0, typeUtils_1.convertToInstance)(destType)),
|
15815
15884
|
}));
|
@@ -15840,7 +15909,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15840
15909
|
destErrorTypeText = destType.details.fullName;
|
15841
15910
|
srcErrorTypeText = srcType.details.fullName;
|
15842
15911
|
}
|
15843
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
15912
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeIncompatible().format({
|
15844
15913
|
sourceType: srcErrorTypeText,
|
15845
15914
|
destType: destErrorTypeText,
|
15846
15915
|
}));
|
@@ -15848,7 +15917,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15848
15917
|
if (types_1.ClassType.isBuiltIn(destType, 'bytes')) {
|
15849
15918
|
const promotions = typePromotions.get(destType.details.fullName);
|
15850
15919
|
if (promotions && promotions.some((name) => name === srcType.details.fullName)) {
|
15851
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
15920
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.bytesTypePromotions());
|
15852
15921
|
}
|
15853
15922
|
}
|
15854
15923
|
return false;
|
@@ -15858,98 +15927,109 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15858
15927
|
// the type parameters for the base class are honored. This is useful for
|
15859
15928
|
// variance inference (PEP 695). For validation of protocol variance, we
|
15860
15929
|
// want to ignore the variance for all base classes in the class hierarchy.
|
15861
|
-
function assignClassToSelf(destType, srcType, ignoreBaseClassVariance = true, recursionCount = 0) {
|
15930
|
+
function assignClassToSelf(destType, srcType, assumedVariance, ignoreBaseClassVariance = true, recursionCount = 0) {
|
15862
15931
|
(0, debug_1.assert)(types_1.ClassType.isSameGenericClass(destType, srcType));
|
15863
15932
|
(0, debug_1.assert)(destType.details.typeParameters.length > 0);
|
15864
15933
|
const typeVarContext = new typeVarContext_1.TypeVarContext();
|
15865
15934
|
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;
|
15935
|
+
// Use a try/catch block here to make sure that we reset
|
15936
|
+
// the assignClassToSelfClass to undefined if an exception occurs.
|
15937
|
+
try {
|
15938
|
+
// Stash the current class type so any references to it are treated
|
15939
|
+
// as though all TypeParameters are invariant.
|
15940
|
+
assignClassToSelfStack.push({ class: destType, assumedVariance });
|
15941
|
+
destType.details.fields.forEach((symbol, name) => {
|
15942
|
+
if (!isAssignable || symbol.isIgnoredForProtocolMatch()) {
|
15943
|
+
return;
|
15888
15944
|
}
|
15889
|
-
|
15890
|
-
|
15891
|
-
|
15892
|
-
|
15893
|
-
|
15894
|
-
|
15895
|
-
|
15896
|
-
|
15897
|
-
|
15898
|
-
|
15899
|
-
|
15900
|
-
|
15901
|
-
|
15945
|
+
// Constructor methods are exempt from variance calculations.
|
15946
|
+
if (name === '__new__' || name === '__init__') {
|
15947
|
+
return;
|
15948
|
+
}
|
15949
|
+
const memberInfo = (0, typeUtils_1.lookUpClassMember)(srcType, name);
|
15950
|
+
(0, debug_1.assert)(memberInfo !== undefined);
|
15951
|
+
let destMemberType = getEffectiveTypeOfSymbol(symbol);
|
15952
|
+
const srcMemberType = getTypeOfMember(memberInfo);
|
15953
|
+
destMemberType = (0, typeUtils_1.partiallySpecializeType)(destMemberType, destType);
|
15954
|
+
// Properties require special processing.
|
15955
|
+
if ((0, types_1.isClassInstance)(destMemberType) &&
|
15956
|
+
types_1.ClassType.isPropertyClass(destMemberType) &&
|
15957
|
+
(0, types_1.isClassInstance)(srcMemberType) &&
|
15958
|
+
types_1.ClassType.isPropertyClass(srcMemberType)) {
|
15959
|
+
if (!(0, properties_1.assignProperty)(evaluatorInterface, types_1.ClassType.cloneAsInstantiable(destMemberType), types_1.ClassType.cloneAsInstantiable(srcMemberType), destType, srcType,
|
15960
|
+
/* diag */ undefined, typeVarContext,
|
15961
|
+
/* selfTypeVarContext */ undefined, recursionCount)) {
|
15962
|
+
isAssignable = false;
|
15902
15963
|
}
|
15903
15964
|
}
|
15904
|
-
|
15905
|
-
|
15906
|
-
|
15907
|
-
|
15965
|
+
else {
|
15966
|
+
const primaryDecl = symbol.getDeclarations()[0];
|
15967
|
+
let flags = 0 /* AssignTypeFlags.Default */;
|
15968
|
+
if ((primaryDecl === null || primaryDecl === void 0 ? void 0 : primaryDecl.type) === 1 /* DeclarationType.Variable */ &&
|
15969
|
+
!isFinalVariableDeclaration(primaryDecl) &&
|
15970
|
+
!types_1.ClassType.isFrozenDataClass(destType)) {
|
15971
|
+
// Class and instance variables that are mutable need to
|
15972
|
+
// enforce invariance. We will exempt variables that are
|
15973
|
+
// private or protected, since these are presumably
|
15974
|
+
// not modifiable outside of the class.
|
15975
|
+
if (!(0, symbolNameUtils_1.isPrivateOrProtectedName)(name)) {
|
15976
|
+
flags |= 1 /* AssignTypeFlags.EnforceInvariance */;
|
15977
|
+
}
|
15978
|
+
}
|
15979
|
+
if (!assignType(destMemberType, srcMemberType,
|
15980
|
+
/* diag */ undefined, typeVarContext,
|
15981
|
+
/* srcTypeVarContext */ undefined, flags | 65536 /* AssignTypeFlags.IgnoreSelfClsParamCompatibility */, recursionCount)) {
|
15982
|
+
isAssignable = false;
|
15983
|
+
}
|
15908
15984
|
}
|
15985
|
+
});
|
15986
|
+
if (!isAssignable) {
|
15987
|
+
return false;
|
15909
15988
|
}
|
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;
|
15989
|
+
// Now handle generic base classes.
|
15990
|
+
destType.details.baseClasses.forEach((baseClass) => {
|
15991
|
+
if ((0, types_1.isInstantiableClass)(baseClass) &&
|
15992
|
+
!types_1.ClassType.isBuiltIn(baseClass, 'object') &&
|
15993
|
+
!types_1.ClassType.isBuiltIn(baseClass, 'Protocol') &&
|
15994
|
+
!types_1.ClassType.isBuiltIn(baseClass, 'Generic') &&
|
15995
|
+
baseClass.details.typeParameters.length > 0) {
|
15996
|
+
const specializedDestBaseClass = (0, typeUtils_1.specializeForBaseClass)(destType, baseClass);
|
15997
|
+
const specializedSrcBaseClass = (0, typeUtils_1.specializeForBaseClass)(srcType, baseClass);
|
15998
|
+
if (!ignoreBaseClassVariance) {
|
15999
|
+
specializedDestBaseClass.details.typeParameters.forEach((param, index) => {
|
16000
|
+
if (!param.details.isParamSpec &&
|
16001
|
+
!param.details.isVariadic &&
|
16002
|
+
!param.details.isSynthesized &&
|
16003
|
+
specializedSrcBaseClass.typeArguments &&
|
16004
|
+
index < specializedSrcBaseClass.typeArguments.length &&
|
16005
|
+
specializedDestBaseClass.typeArguments &&
|
16006
|
+
index < specializedDestBaseClass.typeArguments.length) {
|
16007
|
+
const paramVariance = param.details.declaredVariance;
|
16008
|
+
if ((0, types_1.isTypeVar)(specializedSrcBaseClass.typeArguments[index])) {
|
16009
|
+
if (paramVariance === 2 /* Variance.Invariant */ ||
|
16010
|
+
paramVariance === 4 /* Variance.Contravariant */) {
|
16011
|
+
isAssignable = false;
|
16012
|
+
}
|
15936
16013
|
}
|
15937
|
-
|
15938
|
-
|
15939
|
-
|
15940
|
-
|
16014
|
+
else if ((0, types_1.isTypeVar)(specializedDestBaseClass.typeArguments[index])) {
|
16015
|
+
if (paramVariance === 2 /* Variance.Invariant */ || paramVariance === 3 /* Variance.Covariant */) {
|
16016
|
+
isAssignable = false;
|
16017
|
+
}
|
15941
16018
|
}
|
15942
16019
|
}
|
15943
|
-
}
|
15944
|
-
}
|
15945
|
-
|
15946
|
-
|
15947
|
-
|
15948
|
-
|
16020
|
+
});
|
16021
|
+
}
|
16022
|
+
if (isAssignable &&
|
16023
|
+
!assignClassToSelf(specializedDestBaseClass, specializedSrcBaseClass, assumedVariance, ignoreBaseClassVariance, recursionCount)) {
|
16024
|
+
isAssignable = false;
|
16025
|
+
}
|
15949
16026
|
}
|
15950
|
-
}
|
15951
|
-
|
15952
|
-
|
16027
|
+
});
|
16028
|
+
return isAssignable;
|
16029
|
+
}
|
16030
|
+
finally {
|
16031
|
+
assignClassToSelfStack.pop();
|
16032
|
+
}
|
15953
16033
|
}
|
15954
16034
|
// Adjusts the source and/or dest type arguments list to attempt to match
|
15955
16035
|
// the length of the src type arguments list if the dest or source contain
|
@@ -15959,9 +16039,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15959
16039
|
const destUnboundedOrVariadicIndex = destTypeArgs.findIndex((t) => t.isUnbounded || (0, types_1.isVariadicTypeVar)(t.type));
|
15960
16040
|
const srcUnboundedIndex = srcTypeArgs.findIndex((t) => t.isUnbounded);
|
15961
16041
|
const srcVariadicIndex = srcTypeArgs.findIndex((t) => (0, types_1.isVariadicTypeVar)(t.type));
|
16042
|
+
let isSrcVariadicAny = false;
|
15962
16043
|
// If the src contains an unbounded type but the dest does not, it's incompatible.
|
15963
16044
|
if (srcUnboundedIndex >= 0 && destUnboundedOrVariadicIndex < 0) {
|
15964
|
-
|
16045
|
+
// Unless the source contains an [Any, ...].
|
16046
|
+
if ((0, types_1.isAnyOrUnknown)(srcTypeArgs[srcUnboundedIndex].type)) {
|
16047
|
+
isSrcVariadicAny = true;
|
16048
|
+
}
|
16049
|
+
else {
|
16050
|
+
return false;
|
16051
|
+
}
|
15965
16052
|
}
|
15966
16053
|
if (srcUnboundedIndex >= 0) {
|
15967
16054
|
// The source is unbounded, so expand the unbounded argument to try
|
@@ -15970,6 +16057,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15970
16057
|
while (srcTypeArgs.length < destTypeArgs.length) {
|
15971
16058
|
srcTypeArgs.splice(srcUnboundedIndex, 0, { type: typeToReplicate, isUnbounded: true });
|
15972
16059
|
}
|
16060
|
+
if (isSrcVariadicAny && srcTypeArgs.length > destTypeArgs.length) {
|
16061
|
+
srcTypeArgs.splice(srcUnboundedIndex, 1);
|
16062
|
+
}
|
15973
16063
|
}
|
15974
16064
|
// Remove any optional parameters from the end of the two lists until the lengths match.
|
15975
16065
|
while (srcTypeArgs.length > destTypeArgs.length && srcTypeArgs[srcTypeArgs.length - 1].isOptional) {
|
@@ -16049,7 +16139,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16049
16139
|
const entryDiag = diag === null || diag === void 0 ? void 0 : diag.createAddendum();
|
16050
16140
|
if (!assignType(destTypeArgs[argIndex].type, srcTypeArgs[argIndex].type, entryDiag === null || entryDiag === void 0 ? void 0 : entryDiag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
|
16051
16141
|
if (entryDiag) {
|
16052
|
-
entryDiag.addMessage(localize_1.
|
16142
|
+
entryDiag.addMessage(localize_1.LocAddendum.tupleEntryTypeMismatch().format({
|
16053
16143
|
entry: argIndex + 1,
|
16054
16144
|
}));
|
16055
16145
|
}
|
@@ -16059,12 +16149,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16059
16149
|
}
|
16060
16150
|
else {
|
16061
16151
|
if (srcTypeArgs.find((t) => t.isUnbounded)) {
|
16062
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
16152
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.tupleSizeIndeterminate().format({
|
16063
16153
|
expected: destTypeArgs.length,
|
16064
16154
|
}));
|
16065
16155
|
}
|
16066
16156
|
else {
|
16067
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
16157
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.tupleSizeMismatch().format({
|
16068
16158
|
expected: destTypeArgs.length,
|
16069
16159
|
received: srcTypeArgs.length,
|
16070
16160
|
}));
|
@@ -16180,6 +16270,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16180
16270
|
const destTypeParams = types_1.ClassType.getTypeParameters(destType);
|
16181
16271
|
let destTypeArgs;
|
16182
16272
|
let srcTypeArgs;
|
16273
|
+
// Are we performing protocol variance validation for this class? If so,
|
16274
|
+
// treat all of the type parameters as invariant even if they are declared
|
16275
|
+
// otherwise.
|
16276
|
+
const assignClassToSelfInfo = assignClassToSelfStack.find((info) => types_1.ClassType.isSameGenericClass(info.class, destType));
|
16277
|
+
const assumedVariance = assignClassToSelfInfo === null || assignClassToSelfInfo === void 0 ? void 0 : assignClassToSelfInfo.assumedVariance;
|
16183
16278
|
// If either source or dest type arguments are missing, they are
|
16184
16279
|
// treated as "Any", so they are assumed to be assignable.
|
16185
16280
|
if (!destType.typeArguments || !srcType.typeArguments) {
|
@@ -16202,22 +16297,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16202
16297
|
const destTypeArg = destArgIndex >= 0 ? destTypeArgs[destArgIndex] : types_1.UnknownType.create();
|
16203
16298
|
const destTypeParam = destArgIndex < destTypeParams.length ? destTypeParams[destArgIndex] : undefined;
|
16204
16299
|
const assignmentDiag = new diagnostic_1.DiagnosticAddendum();
|
16205
|
-
const variance = destTypeParam ? types_1.TypeVarType.getVariance(destTypeParam) : 3 /* Variance.Covariant
|
16300
|
+
const variance = assumedVariance !== null && assumedVariance !== void 0 ? assumedVariance : (destTypeParam ? types_1.TypeVarType.getVariance(destTypeParam) : 3 /* Variance.Covariant */);
|
16206
16301
|
let effectiveFlags;
|
16207
16302
|
let errorSource;
|
16208
16303
|
let includeDiagAddendum = true;
|
16209
16304
|
if (variance === 3 /* Variance.Covariant */) {
|
16210
16305
|
effectiveFlags = flags | 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */;
|
16211
|
-
errorSource = localize_1.
|
16306
|
+
errorSource = localize_1.LocAddendum.typeVarIsCovariant;
|
16212
16307
|
}
|
16213
16308
|
else if (variance === 4 /* Variance.Contravariant */) {
|
16214
16309
|
effectiveFlags =
|
16215
16310
|
(flags ^ 2 /* AssignTypeFlags.ReverseTypeVarMatching */) | 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */;
|
16216
|
-
errorSource = localize_1.
|
16311
|
+
errorSource = localize_1.LocAddendum.typeVarIsContravariant;
|
16217
16312
|
}
|
16218
16313
|
else {
|
16219
16314
|
effectiveFlags = flags | 1 /* AssignTypeFlags.EnforceInvariance */ | 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */;
|
16220
|
-
errorSource = localize_1.
|
16315
|
+
errorSource = localize_1.LocAddendum.typeVarIsInvariant;
|
16221
16316
|
// Omit the diagnostic addendum for the invariant case because it's obvious
|
16222
16317
|
// why two types are not the same.
|
16223
16318
|
includeDiagAddendum = false;
|
@@ -16239,13 +16334,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16239
16334
|
if (isCompatible && types_1.ClassType.isSameGenericClass(destType, srcType)) {
|
16240
16335
|
// Add additional notes to help the user if this is a common type mismatch.
|
16241
16336
|
if (types_1.ClassType.isBuiltIn(destType, 'dict') && srcArgIndex === 1) {
|
16242
|
-
childDiag.addMessage(localize_1.
|
16337
|
+
childDiag.addMessage(localize_1.LocAddendum.invariantSuggestionDict());
|
16243
16338
|
}
|
16244
16339
|
else if (types_1.ClassType.isBuiltIn(destType, 'list')) {
|
16245
|
-
childDiag.addMessage(localize_1.
|
16340
|
+
childDiag.addMessage(localize_1.LocAddendum.invariantSuggestionList());
|
16246
16341
|
}
|
16247
16342
|
else if (types_1.ClassType.isBuiltIn(destType, 'set')) {
|
16248
|
-
childDiag.addMessage(localize_1.
|
16343
|
+
childDiag.addMessage(localize_1.LocAddendum.invariantSuggestionSet());
|
16249
16344
|
}
|
16250
16345
|
}
|
16251
16346
|
}
|
@@ -16477,7 +16572,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16477
16572
|
return true;
|
16478
16573
|
}
|
16479
16574
|
if (!(0, types_1.isUnion)(destType)) {
|
16480
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
16575
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
|
16481
16576
|
return false;
|
16482
16577
|
}
|
16483
16578
|
}
|
@@ -16570,7 +16665,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16570
16665
|
if (assignType(destType, (0, typeUtils_1.convertToInstantiable)(typeTypeArg), diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
|
16571
16666
|
return true;
|
16572
16667
|
}
|
16573
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
16668
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
|
16574
16669
|
return false;
|
16575
16670
|
}
|
16576
16671
|
}
|
@@ -16583,7 +16678,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16583
16678
|
if (types_1.ClassType.isProtocolClass(expandedSrcType) &&
|
16584
16679
|
(0, types_1.isInstantiableClass)(srcType) &&
|
16585
16680
|
!srcType.includeSubclasses) {
|
16586
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
16681
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.protocolSourceIsNotConcrete().format({
|
16587
16682
|
sourceType: printType((0, typeUtils_1.convertToInstance)(srcType)),
|
16588
16683
|
destType: printType(destType),
|
16589
16684
|
}));
|
@@ -16595,7 +16690,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16595
16690
|
/* reportErrorsUsingObjType */ false)) {
|
16596
16691
|
return true;
|
16597
16692
|
}
|
16598
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
16693
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
|
16599
16694
|
return false;
|
16600
16695
|
}
|
16601
16696
|
else if ((0, types_1.isClassInstance)(expandedSrcType) && (0, typeUtils_1.isMetaclassInstance)(expandedSrcType)) {
|
@@ -16607,7 +16702,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16607
16702
|
/* reportErrorsUsingObjType */ false)) {
|
16608
16703
|
return true;
|
16609
16704
|
}
|
16610
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
16705
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
|
16611
16706
|
return false;
|
16612
16707
|
}
|
16613
16708
|
}
|
@@ -16646,7 +16741,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16646
16741
|
if (destType.literalValue !== undefined) {
|
16647
16742
|
const srcLiteral = concreteSrcType.literalValue;
|
16648
16743
|
if (srcLiteral === undefined || !types_1.ClassType.isLiteralValueSame(concreteSrcType, destType)) {
|
16649
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
16744
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.literalAssignmentMismatch().format({
|
16650
16745
|
sourceType: printType(srcType),
|
16651
16746
|
destType: printType(destType),
|
16652
16747
|
}));
|
@@ -16768,7 +16863,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16768
16863
|
}
|
16769
16864
|
});
|
16770
16865
|
if (filteredOverloads.length === 0) {
|
16771
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
16866
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.noOverloadAssignable().format({ type: printType(destType) }));
|
16772
16867
|
return false;
|
16773
16868
|
}
|
16774
16869
|
if (destTypeVarContext) {
|
@@ -16813,7 +16908,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16813
16908
|
});
|
16814
16909
|
if (!isAssignable) {
|
16815
16910
|
if (overloadDiag) {
|
16816
|
-
overloadDiag.addMessage(localize_1.
|
16911
|
+
overloadDiag.addMessage(localize_1.LocAddendum.overloadNotAssignable().format({
|
16817
16912
|
name: destType.overloads[0].details.name,
|
16818
16913
|
}));
|
16819
16914
|
}
|
@@ -16836,10 +16931,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16836
16931
|
}
|
16837
16932
|
}
|
16838
16933
|
if ((0, typeUtils_1.isNoneInstance)(destType)) {
|
16839
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
16934
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.assignToNone());
|
16840
16935
|
return false;
|
16841
16936
|
}
|
16842
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
16937
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
|
16843
16938
|
return false;
|
16844
16939
|
}
|
16845
16940
|
function assignFromUnionType(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount) {
|
@@ -17014,7 +17109,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17014
17109
|
if ((flags & 32 /* AssignTypeFlags.PartialOverloadOverlapCheck */) !== 0 && matchedSomeSubtypes) {
|
17015
17110
|
return true;
|
17016
17111
|
}
|
17017
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
17112
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
|
17018
17113
|
return false;
|
17019
17114
|
}
|
17020
17115
|
return true;
|
@@ -17105,7 +17200,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17105
17200
|
}
|
17106
17201
|
});
|
17107
17202
|
if (isIncompatible) {
|
17108
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
17203
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
|
17109
17204
|
return false;
|
17110
17205
|
}
|
17111
17206
|
return true;
|
@@ -17185,7 +17280,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17185
17280
|
}
|
17186
17281
|
if (!foundMatch) {
|
17187
17282
|
if (diag && diagAddendum) {
|
17188
|
-
diag.addMessage(localize_1.
|
17283
|
+
diag.addMessage(localize_1.LocAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
|
17189
17284
|
diag.addAddendum(diagAddendum);
|
17190
17285
|
}
|
17191
17286
|
return false;
|
@@ -17308,7 +17403,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17308
17403
|
// of the lambda itself.
|
17309
17404
|
if (!(0, types_1.isTypeSame)(destType, srcType)) {
|
17310
17405
|
if (diag && paramIndex !== undefined) {
|
17311
|
-
diag.addMessage(localize_1.
|
17406
|
+
diag.addMessage(localize_1.LocAddendum.paramAssignment().format({
|
17312
17407
|
index: paramIndex + 1,
|
17313
17408
|
sourceType: printType(destType),
|
17314
17409
|
destType: printType(srcType),
|
@@ -17420,6 +17515,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17420
17515
|
const positionalsToMatch = Math.min(destPositionalCount, srcPositionalCount);
|
17421
17516
|
// Match positional parameters.
|
17422
17517
|
for (let paramIndex = 0; paramIndex < positionalsToMatch; paramIndex++) {
|
17518
|
+
if (paramIndex === 0 &&
|
17519
|
+
destType.details.methodClass &&
|
17520
|
+
(flags & 65536 /* AssignTypeFlags.IgnoreSelfClsParamCompatibility */) !== 0) {
|
17521
|
+
if (types_1.FunctionType.isInstanceMethod(destType) || types_1.FunctionType.isClassMethod(destType)) {
|
17522
|
+
continue;
|
17523
|
+
}
|
17524
|
+
}
|
17423
17525
|
// Skip over the *args parameter since it's handled separately below.
|
17424
17526
|
if (paramIndex === destParamDetails.argsIndex) {
|
17425
17527
|
continue;
|
@@ -17438,13 +17540,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17438
17540
|
destParam.param.category !== 1 /* ParameterCategory.ArgsList */ &&
|
17439
17541
|
srcParam.param.category !== 1 /* ParameterCategory.ArgsList */) {
|
17440
17542
|
if (srcParam.source === parameterUtils_1.ParameterSource.PositionOnly) {
|
17441
|
-
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.
|
17543
|
+
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.functionParamPositionOnly().format({
|
17442
17544
|
name: destParamName,
|
17443
17545
|
}));
|
17444
17546
|
canAssign = false;
|
17445
17547
|
}
|
17446
17548
|
else if (destParamName !== srcParamName) {
|
17447
|
-
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.
|
17549
|
+
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.functionParamName().format({
|
17448
17550
|
srcName: srcParamName,
|
17449
17551
|
destName: destParamName,
|
17450
17552
|
}));
|
@@ -17455,7 +17557,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17455
17557
|
if (!!destParam.param.hasDefault &&
|
17456
17558
|
!srcParam.param.hasDefault &&
|
17457
17559
|
paramIndex !== srcParamDetails.argsIndex) {
|
17458
|
-
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.
|
17560
|
+
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.functionParamDefaultMissing().format({
|
17459
17561
|
name: srcParamName,
|
17460
17562
|
}));
|
17461
17563
|
canAssign = false;
|
@@ -17484,7 +17586,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17484
17586
|
if (!types_1.FunctionType.shouldSkipArgsKwargsCompatibilityCheck(destType) &&
|
17485
17587
|
destParamDetails.firstPositionOrKeywordIndex < srcParamDetails.positionOnlyParamCount &&
|
17486
17588
|
!targetIncludesParamSpec) {
|
17487
|
-
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.
|
17589
|
+
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.argsPositionOnly().format({
|
17488
17590
|
expected: srcParamDetails.positionOnlyParamCount,
|
17489
17591
|
received: destParamDetails.firstPositionOrKeywordIndex,
|
17490
17592
|
}));
|
@@ -17499,7 +17601,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17499
17601
|
if (destPositionalCount < nonDefaultSrcParamCount) {
|
17500
17602
|
if (destParamDetails.firstPositionOrKeywordIndex > 0 &&
|
17501
17603
|
destParamDetails.firstPositionOrKeywordIndex < srcPositionalCount) {
|
17502
|
-
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.
|
17604
|
+
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.functionTooFewParams().format({
|
17503
17605
|
expected: nonDefaultSrcParamCount,
|
17504
17606
|
received: destPositionalCount,
|
17505
17607
|
}));
|
@@ -17533,7 +17635,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17533
17635
|
}
|
17534
17636
|
const destParamType = destParamDetails.params[paramIndex].type;
|
17535
17637
|
if ((0, types_1.isVariadicTypeVar)(destParamType) && !(0, types_1.isVariadicTypeVar)(srcArgsType)) {
|
17536
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
17638
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeVarTupleRequiresKnownLength());
|
17537
17639
|
canAssign = false;
|
17538
17640
|
}
|
17539
17641
|
else {
|
@@ -17542,7 +17644,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17542
17644
|
}
|
17543
17645
|
if (destParamDetails.params[paramIndex].source !== parameterUtils_1.ParameterSource.PositionOnly &&
|
17544
17646
|
srcParamDetails.kwargsIndex === undefined) {
|
17545
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
17647
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.namedParamMissingInSource().format({
|
17546
17648
|
name: (_e = destParamDetails.params[paramIndex].param.name) !== null && _e !== void 0 ? _e : '',
|
17547
17649
|
}));
|
17548
17650
|
canAssign = false;
|
@@ -17558,7 +17660,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17558
17660
|
adjDestPositionalCount--;
|
17559
17661
|
}
|
17560
17662
|
if (srcPositionalCount < adjDestPositionalCount) {
|
17561
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
17663
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.functionTooManyParams().format({
|
17562
17664
|
expected: srcPositionalCount,
|
17563
17665
|
received: destPositionalCount,
|
17564
17666
|
}));
|
@@ -17594,7 +17696,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17594
17696
|
srcType.details.paramSpec === undefined &&
|
17595
17697
|
destParamDetails.argsIndex !== undefined &&
|
17596
17698
|
!destParamDetails.hasUnpackedVariadicTypeVar) {
|
17597
|
-
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.
|
17699
|
+
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.argsParamMissing().format({
|
17598
17700
|
paramName: (_f = destParamDetails.params[destParamDetails.argsIndex].param.name) !== null && _f !== void 0 ? _f : '',
|
17599
17701
|
}));
|
17600
17702
|
canAssign = false;
|
@@ -17630,7 +17732,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17630
17732
|
if (!destParamInfo) {
|
17631
17733
|
if (destParamDetails.kwargsIndex === undefined && !srcParamInfo.param.hasDefault) {
|
17632
17734
|
if (paramDiag && srcParamDetails.firstKeywordOnlyIndex !== undefined) {
|
17633
|
-
paramDiag.addMessage(localize_1.
|
17735
|
+
paramDiag.addMessage(localize_1.LocAddendum.namedParamMissingInDest().format({
|
17634
17736
|
name: srcParamInfo.param.name,
|
17635
17737
|
}));
|
17636
17738
|
}
|
@@ -17651,7 +17753,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17651
17753
|
if (!assignFunctionParameter(destParamInfo.type, srcParamType,
|
17652
17754
|
/* paramIndex */ undefined, paramDiag === null || paramDiag === void 0 ? void 0 : paramDiag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
|
17653
17755
|
if (paramDiag) {
|
17654
|
-
paramDiag.addMessage(localize_1.
|
17756
|
+
paramDiag.addMessage(localize_1.LocAddendum.namedParamTypeMismatch().format({
|
17655
17757
|
name: srcParamInfo.param.name,
|
17656
17758
|
sourceType: printType(specializedDestParamType),
|
17657
17759
|
destType: printType(srcParamType),
|
@@ -17660,7 +17762,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17660
17762
|
canAssign = false;
|
17661
17763
|
}
|
17662
17764
|
if (!!destParamInfo.param.hasDefault && !srcParamInfo.param.hasDefault) {
|
17663
|
-
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.
|
17765
|
+
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.functionParamDefaultMissing().format({
|
17664
17766
|
name: srcParamInfo.param.name,
|
17665
17767
|
}));
|
17666
17768
|
canAssign = false;
|
@@ -17681,7 +17783,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17681
17783
|
destParamMap.delete(paramName);
|
17682
17784
|
}
|
17683
17785
|
else {
|
17684
|
-
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.
|
17786
|
+
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.namedParamMissingInSource().format({ name: paramName }));
|
17685
17787
|
canAssign = false;
|
17686
17788
|
}
|
17687
17789
|
});
|
@@ -17697,7 +17799,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17697
17799
|
srcParamDetails.kwargsIndex === undefined &&
|
17698
17800
|
srcType.details.paramSpec === undefined &&
|
17699
17801
|
destParamDetails.kwargsIndex !== undefined) {
|
17700
|
-
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.
|
17802
|
+
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.kwargsParamMissing().format({
|
17701
17803
|
paramName: destParamDetails.params[destParamDetails.kwargsIndex].param.name,
|
17702
17804
|
}));
|
17703
17805
|
canAssign = false;
|
@@ -17828,7 +17930,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17828
17930
|
}
|
17829
17931
|
if (!isReturnTypeCompatible) {
|
17830
17932
|
if (returnDiag) {
|
17831
|
-
returnDiag.addMessage(localize_1.
|
17933
|
+
returnDiag.addMessage(localize_1.LocAddendum.functionReturnTypeMismatch().format({
|
17832
17934
|
sourceType: printType(srcReturnType),
|
17833
17935
|
destType: printType(destReturnType),
|
17834
17936
|
}));
|
@@ -17967,7 +18069,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17967
18069
|
// If we're overriding a non-method with a method, report it as an error.
|
17968
18070
|
// This occurs when a non-property overrides a property.
|
17969
18071
|
if (!(0, types_1.isFunction)(baseMethod) && !(0, types_1.isOverloadedFunction)(baseMethod)) {
|
17970
|
-
diag.addMessage(localize_1.
|
18072
|
+
diag.addMessage(localize_1.LocAddendum.overrideType().format({ type: printType(baseMethod) }));
|
17971
18073
|
return false;
|
17972
18074
|
}
|
17973
18075
|
if ((0, types_1.isFunction)(baseMethod)) {
|
@@ -17983,7 +18085,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17983
18085
|
})) {
|
17984
18086
|
return true;
|
17985
18087
|
}
|
17986
|
-
diag.addMessage(localize_1.
|
18088
|
+
diag.addMessage(localize_1.LocAddendum.overrideNoOverloadMatches());
|
17987
18089
|
return false;
|
17988
18090
|
}
|
17989
18091
|
// For a non-overloaded method overriding an overloaded method, the
|
@@ -18028,7 +18130,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18028
18130
|
break;
|
18029
18131
|
}
|
18030
18132
|
if (matchIndex < previousMatchIndex) {
|
18031
|
-
diag.addMessage(localize_1.
|
18133
|
+
diag.addMessage(localize_1.LocAddendum.overrideOverloadOrder());
|
18032
18134
|
return false;
|
18033
18135
|
}
|
18034
18136
|
previousMatchIndex = matchIndex;
|
@@ -18041,7 +18143,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18041
18143
|
return isOverrideMethodApplicable(overload, baseClass);
|
18042
18144
|
})) {
|
18043
18145
|
// We didn't find matches for all of the base overloads.
|
18044
|
-
diag.addMessage(localize_1.
|
18146
|
+
diag.addMessage(localize_1.LocAddendum.overrideOverloadNoMatch());
|
18045
18147
|
return false;
|
18046
18148
|
}
|
18047
18149
|
}
|
@@ -18097,19 +18199,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18097
18199
|
// an incompatible type.
|
18098
18200
|
if (types_1.FunctionType.isStaticMethod(baseMethod)) {
|
18099
18201
|
if (!types_1.FunctionType.isStaticMethod(overrideMethod)) {
|
18100
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
18202
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideNotStaticMethod());
|
18101
18203
|
canOverride = false;
|
18102
18204
|
}
|
18103
18205
|
}
|
18104
18206
|
else if (types_1.FunctionType.isClassMethod(baseMethod)) {
|
18105
18207
|
if (!types_1.FunctionType.isClassMethod(overrideMethod)) {
|
18106
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
18208
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideNotClassMethod());
|
18107
18209
|
canOverride = false;
|
18108
18210
|
}
|
18109
18211
|
}
|
18110
18212
|
else if (types_1.FunctionType.isInstanceMethod(baseMethod)) {
|
18111
18213
|
if (!types_1.FunctionType.isInstanceMethod(overrideMethod)) {
|
18112
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
18214
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideNotInstanceMethod());
|
18113
18215
|
canOverride = false;
|
18114
18216
|
}
|
18115
18217
|
}
|
@@ -18124,7 +18226,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18124
18226
|
const overrideArgsType = overrideParamDetails.params[overrideParamDetails.argsIndex].type;
|
18125
18227
|
for (let i = overrideParamDetails.positionParamCount; i < baseParamDetails.positionParamCount; i++) {
|
18126
18228
|
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.
|
18229
|
+
localize_1.LocAddendum.overrideParamType().format({
|
18128
18230
|
index: i + 1,
|
18129
18231
|
baseType: printType(baseParamDetails.params[i].type),
|
18130
18232
|
overrideType: printType(overrideArgsType),
|
@@ -18148,7 +18250,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18148
18250
|
}
|
18149
18251
|
}
|
18150
18252
|
if (foundParamCountMismatch) {
|
18151
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
18253
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overridePositionalParamCount().format({
|
18152
18254
|
baseCount: baseParamDetails.params.length,
|
18153
18255
|
overrideCount: overrideParamDetails.params.length,
|
18154
18256
|
}));
|
@@ -18176,13 +18278,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18176
18278
|
if (overrideParam.category === 0 /* ParameterCategory.Simple */) {
|
18177
18279
|
if (enforceParamNames && !baseParam.isNameSynthesized) {
|
18178
18280
|
if (overrideParamDetails.params[i].source === parameterUtils_1.ParameterSource.PositionOnly) {
|
18179
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
18281
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamNamePositionOnly().format({
|
18180
18282
|
index: i + 1,
|
18181
18283
|
baseName: baseParam.name || '*',
|
18182
18284
|
}));
|
18183
18285
|
}
|
18184
18286
|
else {
|
18185
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
18287
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamName().format({
|
18186
18288
|
index: i + 1,
|
18187
18289
|
baseName: baseParam.name || '*',
|
18188
18290
|
overrideName: overrideParam.name || '*',
|
@@ -18196,7 +18298,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18196
18298
|
i >= baseParamDetails.positionOnlyParamCount) {
|
18197
18299
|
if (!baseParam.isNameSynthesized &&
|
18198
18300
|
baseParamDetails.params[i].source !== parameterUtils_1.ParameterSource.PositionOnly) {
|
18199
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
18301
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamNamePositionOnly().format({
|
18200
18302
|
index: i + 1,
|
18201
18303
|
baseName: baseParam.name || '*',
|
18202
18304
|
}));
|
@@ -18211,7 +18313,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18211
18313
|
if (!exemptSelfClsParam || (!baseIsSynthesizedTypeVar && !overrideIsSynthesizedTypeVar)) {
|
18212
18314
|
if (baseParam.category !== overrideParam.category ||
|
18213
18315
|
!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.
|
18316
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamType().format({
|
18215
18317
|
index: i + 1,
|
18216
18318
|
baseType: printType(baseParamType),
|
18217
18319
|
overrideType: printType(overrideParamType),
|
@@ -18221,7 +18323,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18221
18323
|
}
|
18222
18324
|
if (baseParamDetails.params[i].param.hasDefault &&
|
18223
18325
|
!overrideParamDetails.params[i].param.hasDefault) {
|
18224
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
18326
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamNoDefault().format({
|
18225
18327
|
index: i + 1,
|
18226
18328
|
}));
|
18227
18329
|
canOverride = false;
|
@@ -18231,7 +18333,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18231
18333
|
// Check for a *args match.
|
18232
18334
|
if (baseParamDetails.argsIndex !== undefined) {
|
18233
18335
|
if (overrideParamDetails.argsIndex === undefined) {
|
18234
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
18336
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamNameMissing().format({
|
18235
18337
|
name: (_a = baseParamDetails.params[baseParamDetails.argsIndex].param.name) !== null && _a !== void 0 ? _a : '?',
|
18236
18338
|
}));
|
18237
18339
|
canOverride = false;
|
@@ -18241,7 +18343,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18241
18343
|
const baseParamType = baseParamDetails.params[baseParamDetails.argsIndex].type;
|
18242
18344
|
if (!assignType(overrideParamType, baseParamType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overrideMethod)),
|
18243
18345
|
/* srcTypeVarContext */ undefined, 8 /* AssignTypeFlags.SkipSolveTypeVars */)) {
|
18244
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
18346
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamKeywordType().format({
|
18245
18347
|
name: (_b = overrideParamDetails.params[overrideParamDetails.argsIndex].param.name) !== null && _b !== void 0 ? _b : '?',
|
18246
18348
|
baseType: printType(baseParamType),
|
18247
18349
|
overrideType: printType(overrideParamType),
|
@@ -18259,7 +18361,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18259
18361
|
var _a, _b, _c;
|
18260
18362
|
const overrideParamInfo = overrideKwOnlyParams.find((pi) => paramInfo.param.name === pi.param.name);
|
18261
18363
|
if (!overrideParamInfo && overrideParamDetails.kwargsIndex === undefined) {
|
18262
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
18364
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamNameMissing().format({
|
18263
18365
|
name: (_a = paramInfo.param.name) !== null && _a !== void 0 ? _a : '?',
|
18264
18366
|
}));
|
18265
18367
|
canOverride = false;
|
@@ -18270,7 +18372,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18270
18372
|
targetParamType = overrideParamDetails.params[overrideParamDetails.kwargsIndex].type;
|
18271
18373
|
}
|
18272
18374
|
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.
|
18375
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamKeywordType().format({
|
18274
18376
|
name: (_b = paramInfo.param.name) !== null && _b !== void 0 ? _b : '?',
|
18275
18377
|
baseType: printType(paramInfo.type),
|
18276
18378
|
overrideType: printType(targetParamType),
|
@@ -18279,7 +18381,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18279
18381
|
}
|
18280
18382
|
if (overrideParamInfo) {
|
18281
18383
|
if (paramInfo.param.hasDefault && !overrideParamInfo.param.hasDefault) {
|
18282
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
18384
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamKeywordNoDefault().format({
|
18283
18385
|
name: (_c = overrideParamInfo.param.name) !== null && _c !== void 0 ? _c : '?',
|
18284
18386
|
}));
|
18285
18387
|
canOverride = false;
|
@@ -18295,7 +18397,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18295
18397
|
if (!baseParamInfo) {
|
18296
18398
|
if (baseParamDetails.kwargsIndex === undefined) {
|
18297
18399
|
if (!paramInfo.param.hasDefault) {
|
18298
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
18400
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamNameExtra().format({
|
18299
18401
|
name: (_a = paramInfo.param.name) !== null && _a !== void 0 ? _a : '?',
|
18300
18402
|
}));
|
18301
18403
|
canOverride = false;
|
@@ -18305,7 +18407,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18305
18407
|
});
|
18306
18408
|
// Verify that if the base method has a **kwargs parameter, the override does too.
|
18307
18409
|
if (baseParamDetails.kwargsIndex !== undefined && overrideParamDetails.kwargsIndex === undefined) {
|
18308
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
18410
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.kwargsParamMissing().format({
|
18309
18411
|
paramName: baseParamDetails.params[baseParamDetails.kwargsIndex].param.name,
|
18310
18412
|
}));
|
18311
18413
|
canOverride = false;
|
@@ -18320,7 +18422,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18320
18422
|
overrideParamDetails.kwargsIndex !== undefined &&
|
18321
18423
|
(0, types_1.isAnyOrUnknown)(overrideParamDetails.params[overrideParamDetails.kwargsIndex].type);
|
18322
18424
|
if (!overrideHasArgsKwargs) {
|
18323
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.
|
18425
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.paramSpecMissingInOverride());
|
18324
18426
|
canOverride = false;
|
18325
18427
|
}
|
18326
18428
|
}
|
@@ -18328,7 +18430,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18328
18430
|
const baseReturnType = getFunctionEffectiveReturnType(baseMethod);
|
18329
18431
|
const overrideReturnType = getFunctionEffectiveReturnType(overrideMethod);
|
18330
18432
|
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.
|
18433
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideReturnType().format({
|
18332
18434
|
baseType: printType(baseReturnType),
|
18333
18435
|
overrideType: printType(overrideReturnType),
|
18334
18436
|
}));
|
@@ -18364,7 +18466,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18364
18466
|
// Avoid adding a message that will confuse users if the TypeVar was
|
18365
18467
|
// synthesized for internal purposes.
|
18366
18468
|
if (!destType.details.isSynthesized) {
|
18367
|
-
diag.addMessage(localize_1.
|
18469
|
+
diag.addMessage(localize_1.LocAddendum.typeBound().format({
|
18368
18470
|
sourceType: printType(effectiveSrcType),
|
18369
18471
|
destType: printType(destType.details.boundType),
|
18370
18472
|
name: types_1.TypeVarType.getReadableName(destType),
|
@@ -18383,14 +18485,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18383
18485
|
if ((0, types_1.isClassInstance)(srcType) && types_1.ClassType.isBuiltIn(srcType, 'Concatenate')) {
|
18384
18486
|
return srcType;
|
18385
18487
|
}
|
18386
|
-
diag.addMessage(localize_1.
|
18488
|
+
diag.addMessage(localize_1.LocAddendum.typeParamSpec().format({
|
18387
18489
|
type: printType(srcType),
|
18388
18490
|
name: types_1.TypeVarType.getReadableName(destType),
|
18389
18491
|
}));
|
18390
18492
|
return undefined;
|
18391
18493
|
}
|
18392
18494
|
if ((0, types_1.isTypeVar)(srcType) && srcType.details.isParamSpec) {
|
18393
|
-
diag.addMessage(localize_1.
|
18495
|
+
diag.addMessage(localize_1.LocMessage.paramSpecContext());
|
18394
18496
|
return undefined;
|
18395
18497
|
}
|
18396
18498
|
// If there are no constraints, we're done.
|
@@ -18424,61 +18526,38 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18424
18526
|
return bestConstraintSoFar;
|
18425
18527
|
}
|
18426
18528
|
}
|
18427
|
-
diag.addMessage(localize_1.
|
18529
|
+
diag.addMessage(localize_1.LocAddendum.typeConstrainedTypeVar().format({
|
18428
18530
|
type: printType(srcType),
|
18429
18531
|
name: types_1.TypeVarType.getReadableName(destType),
|
18430
18532
|
}));
|
18431
18533
|
return undefined;
|
18432
18534
|
}
|
18433
|
-
|
18535
|
+
// Returns a list of unimplemented abstract symbols (methods or variables) for
|
18536
|
+
// the specified class.
|
18537
|
+
function getAbstractSymbols(classType) {
|
18434
18538
|
const symbolTable = new Map();
|
18435
18539
|
types_1.ClassType.getReverseMro(classType).forEach((mroClass) => {
|
18436
18540
|
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
|
18541
|
+
// See if this class is introducing a new abstract symbol that has not been
|
18542
|
+
// introduced previously or if it is overriding an abstract symbol with
|
18439
18543
|
// a non-abstract one.
|
18440
18544
|
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
|
-
}
|
18545
|
+
const abstractSymbolInfo = getAbstractSymbolInfo(mroClass, symbolName);
|
18546
|
+
if (abstractSymbolInfo) {
|
18547
|
+
symbolTable.set(symbolName, abstractSymbolInfo);
|
18548
|
+
}
|
18549
|
+
else {
|
18550
|
+
symbolTable.delete(symbolName);
|
18472
18551
|
}
|
18473
18552
|
});
|
18474
18553
|
}
|
18475
18554
|
});
|
18476
|
-
// Create a final list of
|
18477
|
-
const
|
18555
|
+
// Create a final list of symbols that are abstract.
|
18556
|
+
const symbolList = [];
|
18478
18557
|
symbolTable.forEach((method) => {
|
18479
|
-
|
18558
|
+
symbolList.push(method);
|
18480
18559
|
});
|
18481
|
-
return
|
18560
|
+
return symbolList;
|
18482
18561
|
}
|
18483
18562
|
// If the memberType is an instance or class method, creates a new
|
18484
18563
|
// version of the function that has the "self" or "cls" parameter bound
|
@@ -18553,7 +18632,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18553
18632
|
!memberTypeFirstParam.isNameSynthesized &&
|
18554
18633
|
memberTypeFirstParam.hasDeclaredType) {
|
18555
18634
|
if (diag) {
|
18556
|
-
diag.addMessage(localize_1.
|
18635
|
+
diag.addMessage(localize_1.LocMessage.bindTypeMismatch().format({
|
18557
18636
|
type: printType(baseType),
|
18558
18637
|
methodName: memberType.details.name || '<anonymous>',
|
18559
18638
|
paramName: memberTypeFirstParam.name,
|
@@ -18821,7 +18900,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18821
18900
|
getTypeOfMagicMethodCall,
|
18822
18901
|
bindFunctionToClassOrObject,
|
18823
18902
|
getCallSignatureInfo,
|
18824
|
-
|
18903
|
+
getAbstractSymbols,
|
18825
18904
|
narrowConstrainedTypeVar,
|
18826
18905
|
assignType,
|
18827
18906
|
validateOverrideMethod,
|
@@ -18843,8 +18922,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18843
18922
|
isFinalVariable,
|
18844
18923
|
isFinalVariableDeclaration,
|
18845
18924
|
isExplicitTypeAliasDeclaration,
|
18846
|
-
addError,
|
18847
|
-
addWarning,
|
18848
18925
|
addInformation,
|
18849
18926
|
addUnusedCode,
|
18850
18927
|
addUnreachableCode,
|