@zzzen/pyright-internal 1.2.0-dev.20250420 → 1.2.0-dev.20250803
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer/analyzerNodeInfo.js +1 -1
- package/dist/analyzer/analyzerNodeInfo.js.map +1 -1
- package/dist/analyzer/binder.d.ts +2 -1
- package/dist/analyzer/binder.js +33 -18
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.js +81 -44
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +19 -7
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/codeFlowTypes.d.ts +9 -8
- package/dist/analyzer/codeFlowTypes.js +9 -8
- package/dist/analyzer/codeFlowTypes.js.map +1 -1
- package/dist/analyzer/codeFlowUtils.js +4 -2
- package/dist/analyzer/codeFlowUtils.js.map +1 -1
- package/dist/analyzer/docStringUtils.js +3 -1
- package/dist/analyzer/docStringUtils.js.map +1 -1
- package/dist/analyzer/importStatementUtils.js +5 -3
- package/dist/analyzer/importStatementUtils.js.map +1 -1
- package/dist/analyzer/operations.js +1 -1
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.js +5 -3
- package/dist/analyzer/packageTypeVerifier.js.map +1 -1
- package/dist/analyzer/parameterUtils.js +10 -3
- package/dist/analyzer/parameterUtils.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.d.ts +3 -4
- package/dist/analyzer/parseTreeUtils.js +19 -225
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/patternMatching.js +4 -0
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.d.ts +12 -2
- package/dist/analyzer/program.js +74 -58
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/properties.js +3 -5
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.js +13 -3
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/sentinel.d.ts +4 -0
- package/dist/analyzer/sentinel.js +51 -0
- package/dist/analyzer/sentinel.js.map +1 -0
- package/dist/analyzer/service.d.ts +2 -2
- package/dist/analyzer/service.js +7 -6
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +4 -0
- package/dist/analyzer/sourceFile.js +52 -12
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceFileInfo.d.ts +10 -1
- package/dist/analyzer/sourceFileInfo.js +28 -0
- package/dist/analyzer/sourceFileInfo.js.map +1 -1
- package/dist/analyzer/sourceFileInfoUtils.js +4 -4
- package/dist/analyzer/sourceFileInfoUtils.js.map +1 -1
- package/dist/analyzer/sourceMapper.d.ts +1 -1
- package/dist/analyzer/sourceMapper.js +20 -20
- package/dist/analyzer/sourceMapper.js.map +1 -1
- package/dist/analyzer/symbol.d.ts +3 -0
- package/dist/analyzer/symbol.js +11 -0
- package/dist/analyzer/symbol.js.map +1 -1
- package/dist/analyzer/testWalker.js +2 -13
- package/dist/analyzer/testWalker.js.map +1 -1
- package/dist/analyzer/tracePrinter.js +1 -1
- package/dist/analyzer/tracePrinter.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +261 -137
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +8 -4
- package/dist/analyzer/typeEvaluatorTypes.js +15 -2
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +47 -13
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.js +10 -2
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typePrinterUtils.js +2 -2
- package/dist/analyzer/typePrinterUtils.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +2 -0
- package/dist/analyzer/typeUtils.js +10 -0
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typedDicts.js +9 -5
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +9 -2
- package/dist/analyzer/types.js +39 -1
- package/dist/analyzer/types.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.d.ts +96 -0
- package/dist/commands/dumpFileDebugInfoCommand.js +13 -2
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/common/cancellationUtils.d.ts +1 -1
- package/dist/common/cancellationUtils.js +2 -2
- package/dist/common/cancellationUtils.js.map +1 -1
- package/dist/common/charCodes.d.ts +1 -1
- package/dist/common/charCodes.js +1 -1
- package/dist/common/charCodes.js.map +1 -1
- package/dist/common/configOptions.d.ts +1 -0
- package/dist/common/configOptions.js +5 -0
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/core.d.ts +1 -3
- package/dist/common/core.js +3 -4
- package/dist/common/core.js.map +1 -1
- package/dist/common/diagnostic.d.ts +1 -1
- package/dist/common/diagnosticRules.d.ts +1 -0
- package/dist/common/diagnosticRules.js +1 -0
- package/dist/common/diagnosticRules.js.map +1 -1
- package/dist/common/docRange.d.ts +6 -0
- package/dist/common/docRange.js +10 -0
- package/dist/common/docRange.js.map +1 -0
- package/dist/common/envVarUtils.js +1 -6
- package/dist/common/envVarUtils.js.map +1 -1
- package/dist/common/extensibility.d.ts +11 -2
- package/dist/common/extensibility.js.map +1 -1
- package/dist/common/fileBasedCancellationUtils.d.ts +1 -0
- package/dist/common/fileBasedCancellationUtils.js +1 -0
- package/dist/common/fileBasedCancellationUtils.js.map +1 -1
- package/dist/common/logTracker.d.ts +5 -1
- package/dist/common/logTracker.js +43 -26
- package/dist/common/logTracker.js.map +1 -1
- package/dist/common/pathUtils.d.ts +1 -1
- package/dist/common/pathUtils.js +3 -2
- package/dist/common/pathUtils.js.map +1 -1
- package/dist/common/realFileSystem.d.ts +1 -1
- package/dist/common/realFileSystem.js +2 -1
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/common/stringUtils.d.ts +0 -1
- package/dist/common/stringUtils.js +0 -42
- package/dist/common/stringUtils.js.map +1 -1
- package/dist/common/textEditTracker.js +5 -3
- package/dist/common/textEditTracker.js.map +1 -1
- package/dist/common/textRange.d.ts +5 -11
- package/dist/common/textRange.js +31 -56
- package/dist/common/textRange.js.map +1 -1
- package/dist/common/textRangeCollection.js +3 -2
- package/dist/common/textRangeCollection.js.map +1 -1
- package/dist/common/uri/baseUri.js +2 -1
- package/dist/common/uri/baseUri.js.map +1 -1
- package/dist/common/uri/uri.d.ts +5 -2
- package/dist/common/uri/uri.js +21 -5
- package/dist/common/uri/uri.js.map +1 -1
- package/dist/common/uri/uriUtils.d.ts +2 -2
- package/dist/common/uri/uriUtils.js +4 -3
- package/dist/common/uri/uriUtils.js.map +1 -1
- package/dist/common/workspaceEditUtils.js +9 -9
- package/dist/common/workspaceEditUtils.js.map +1 -1
- package/dist/languageServerBase.d.ts +5 -3
- package/dist/languageServerBase.js +44 -37
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/analyzerServiceExecutor.d.ts +3 -0
- package/dist/languageService/analyzerServiceExecutor.js +1 -0
- package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
- package/dist/languageService/autoImporter.d.ts +2 -2
- package/dist/languageService/autoImporter.js +3 -3
- package/dist/languageService/autoImporter.js.map +1 -1
- package/dist/languageService/callHierarchyProvider.js +2 -3
- package/dist/languageService/callHierarchyProvider.js.map +1 -1
- package/dist/languageService/completionProvider.js +16 -13
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/definitionProvider.d.ts +2 -1
- package/dist/languageService/definitionProvider.js.map +1 -1
- package/dist/languageService/documentSymbolCollector.d.ts +4 -1
- package/dist/languageService/documentSymbolCollector.js +9 -7
- package/dist/languageService/documentSymbolCollector.js.map +1 -1
- package/dist/languageService/hoverProvider.js +1 -9
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/importSorter.js +1 -0
- package/dist/languageService/importSorter.js.map +1 -1
- package/dist/languageService/navigationUtils.d.ts +1 -1
- package/dist/languageService/referencesProvider.d.ts +2 -1
- package/dist/languageService/referencesProvider.js +8 -7
- package/dist/languageService/referencesProvider.js.map +1 -1
- package/dist/languageService/renameProvider.js +4 -19
- package/dist/languageService/renameProvider.js.map +1 -1
- package/dist/languageService/tooltipUtils.d.ts +2 -0
- package/dist/languageService/tooltipUtils.js +2 -0
- package/dist/languageService/tooltipUtils.js.map +1 -1
- package/dist/languageService/workspaceSymbolProvider.js +1 -1
- package/dist/languageService/workspaceSymbolProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +12 -2
- package/dist/localization/localize.js +12 -2
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +23 -9
- package/dist/localization/package.nls.de.json +18 -4
- package/dist/localization/package.nls.en-us.json +36 -2
- package/dist/localization/package.nls.es.json +18 -4
- package/dist/localization/package.nls.fr.json +22 -8
- package/dist/localization/package.nls.it.json +23 -9
- package/dist/localization/package.nls.ja.json +18 -4
- package/dist/localization/package.nls.ko.json +23 -9
- package/dist/localization/package.nls.pl.json +18 -4
- package/dist/localization/package.nls.pt-br.json +18 -4
- package/dist/localization/package.nls.qps-ploc.json +17 -3
- package/dist/localization/package.nls.ru.json +18 -4
- package/dist/localization/package.nls.tr.json +23 -9
- package/dist/localization/package.nls.zh-cn.json +18 -4
- package/dist/localization/package.nls.zh-tw.json +18 -4
- package/dist/parser/characters.d.ts +1 -8
- package/dist/parser/characters.js +6 -3
- package/dist/parser/characters.js.map +1 -1
- package/dist/parser/parseNodeUtils.d.ts +12 -0
- package/dist/parser/parseNodeUtils.js +136 -0
- package/dist/parser/parseNodeUtils.js.map +1 -0
- package/dist/parser/parseNodes.d.ts +12 -2
- package/dist/parser/parseNodes.js +17 -2
- package/dist/parser/parseNodes.js.map +1 -1
- package/dist/parser/parser.d.ts +3 -2
- package/dist/parser/parser.js +54 -47
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/tokenizer.d.ts +3 -3
- package/dist/parser/tokenizer.js +58 -38
- package/dist/parser/tokenizer.js.map +1 -1
- package/dist/parser/tokenizerTypes.d.ts +4 -3
- package/dist/parser/tokenizerTypes.js +4 -3
- package/dist/parser/tokenizerTypes.js.map +1 -1
- package/dist/pyright.js +1 -1
- package/dist/pyright.js.map +1 -1
- package/dist/server.js +3 -3
- package/dist/server.js.map +1 -1
- package/dist/tests/checker.test.js +2 -2
- package/dist/tests/common.test.js +6 -6
- package/dist/tests/common.test.js.map +1 -1
- package/dist/tests/fourslash/completions.autoimport.unicode.fourslash.js +29 -0
- package/dist/tests/fourslash/completions.autoimport.unicode.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.declNames.method.fourslash.js +8 -8
- package/dist/tests/harness/fourslash/testState.d.ts +3 -2
- package/dist/tests/harness/fourslash/testState.js +9 -3
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/lsp/languageServer.js +1 -1
- package/dist/tests/lsp/languageServer.js.map +1 -1
- package/dist/tests/lsp/languageServerTestUtils.d.ts +1 -2
- package/dist/tests/lsp/languageServerTestUtils.js +2 -2
- package/dist/tests/lsp/languageServerTestUtils.js.map +1 -1
- package/dist/tests/positionUtils.test.js +1 -1
- package/dist/tests/service.test.js +4 -4
- package/dist/tests/service.test.js.map +1 -1
- package/dist/tests/sourceFile.test.js +19 -1
- package/dist/tests/sourceFile.test.js.map +1 -1
- package/dist/tests/stringUtils.test.js +0 -12
- package/dist/tests/stringUtils.test.js.map +1 -1
- package/dist/tests/testStateUtils.js +8 -3
- package/dist/tests/testStateUtils.js.map +1 -1
- package/dist/tests/tokenizer.test.js +5 -5
- package/dist/tests/tokenizer.test.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +11 -13
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +15 -1
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +16 -1
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +9 -3
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/dist/tests/typeEvaluator6.test.js +1 -1
- package/dist/tests/typeEvaluator7.test.js +9 -0
- package/dist/tests/typeEvaluator7.test.js.map +1 -1
- package/dist/tests/typeEvaluator8.test.js +4 -0
- package/dist/tests/typeEvaluator8.test.js.map +1 -1
- package/dist/tests/workspaceEditUtils.test.js +7 -9
- package/dist/tests/workspaceEditUtils.test.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/workspaceFactory.d.ts +12 -1
- package/dist/workspaceFactory.js.map +1 -1
- package/package.json +2 -3
- package/dist/tests/fourslash/rename.args.fourslash.js +0 -72
- package/dist/tests/fourslash/rename.args.fourslash.js.map +0 -1
- /package/dist/tests/fourslash/{rename.args.fourslash.d.ts → completions.autoimport.unicode.fourslash.d.ts} +0 -0
|
@@ -75,6 +75,7 @@ const patternMatching_1 = require("./patternMatching");
|
|
|
75
75
|
const properties_1 = require("./properties");
|
|
76
76
|
const protocols_1 = require("./protocols");
|
|
77
77
|
const ScopeUtils = __importStar(require("./scopeUtils"));
|
|
78
|
+
const sentinel_1 = require("./sentinel");
|
|
78
79
|
const staticExpressions_1 = require("./staticExpressions");
|
|
79
80
|
const symbol_1 = require("./symbol");
|
|
80
81
|
const symbolNameUtils_1 = require("./symbolNameUtils");
|
|
@@ -487,7 +488,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
487
488
|
prefetched = {};
|
|
488
489
|
prefetched.objectClass = getBuiltInType(node, 'object');
|
|
489
490
|
prefetched.typeClass = getBuiltInType(node, 'type');
|
|
490
|
-
prefetched.functionClass = getBuiltInType(node, 'function');
|
|
491
|
+
prefetched.functionClass = getTypesType(node, 'FunctionType') ?? getBuiltInType(node, 'function');
|
|
492
|
+
prefetched.methodClass = getTypesType(node, 'MethodType');
|
|
491
493
|
prefetched.unionTypeClass = getTypesType(node, 'UnionType');
|
|
492
494
|
if (prefetched.unionTypeClass && (0, types_1.isClass)(prefetched.unionTypeClass)) {
|
|
493
495
|
prefetched.unionTypeClass.shared.flags |= 8388608 /* ClassTypeFlags.SpecialFormClass */;
|
|
@@ -503,9 +505,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
503
505
|
prefetched.dictClass = getBuiltInType(node, 'dict');
|
|
504
506
|
prefetched.moduleTypeClass = getTypingType(node, 'ModuleType');
|
|
505
507
|
prefetched.typedDictClass = getTypingType(node, 'TypedDict');
|
|
506
|
-
prefetched.typedDictPrivateClass =
|
|
508
|
+
prefetched.typedDictPrivateClass =
|
|
509
|
+
getTypeCheckerInternalsType(node, 'TypedDictFallback') ?? getTypingType(node, '_TypedDict');
|
|
507
510
|
prefetched.awaitableClass = getTypingType(node, 'Awaitable');
|
|
508
511
|
prefetched.mappingClass = getTypingType(node, 'Mapping');
|
|
512
|
+
prefetched.templateClass = getTypeOfModule(node, 'Template', ['string', 'templatelib']);
|
|
509
513
|
prefetched.supportsKeysAndGetItemClass = getTypeshedType(node, 'SupportsKeysAndGetItem');
|
|
510
514
|
if (!prefetched.supportsKeysAndGetItemClass) {
|
|
511
515
|
// Fall back on 'Mapping' if 'SupportsKeysAndGetItem' is not available.
|
|
@@ -943,7 +947,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
943
947
|
const isBytes = firstBytesIndex >= 0;
|
|
944
948
|
let isLiteralString = true;
|
|
945
949
|
let isIncomplete = false;
|
|
950
|
+
let isTemplate = false;
|
|
946
951
|
node.d.strings.forEach((expr) => {
|
|
952
|
+
// Handle implicit concatenation.
|
|
947
953
|
const typeResult = getTypeOfString(expr);
|
|
948
954
|
if (typeResult.isIncomplete) {
|
|
949
955
|
isIncomplete = true;
|
|
@@ -956,13 +962,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
956
962
|
else if (types_1.ClassType.isBuiltIn(typeResult?.type, 'LiteralString')) {
|
|
957
963
|
isExprLiteralString = true;
|
|
958
964
|
}
|
|
965
|
+
if (typeResult.type.shared.name === 'Template') {
|
|
966
|
+
isTemplate = true;
|
|
967
|
+
}
|
|
959
968
|
}
|
|
960
969
|
if (!isExprLiteralString) {
|
|
961
970
|
isLiteralString = false;
|
|
962
971
|
}
|
|
963
972
|
});
|
|
964
|
-
|
|
965
|
-
|
|
973
|
+
if (isTemplate) {
|
|
974
|
+
const templateType = prefetched?.templateClass && (0, types_1.isInstantiableClass)(prefetched?.templateClass)
|
|
975
|
+
? types_1.ClassType.cloneAsInstance(prefetched.templateClass)
|
|
976
|
+
: types_1.UnknownType.create();
|
|
977
|
+
typeResult = { type: templateType, isIncomplete };
|
|
978
|
+
}
|
|
979
|
+
else if (node.d.strings.some((str) => str.nodeType === 30 /* ParseNodeType.FormatString */)) {
|
|
966
980
|
if (isLiteralString) {
|
|
967
981
|
const literalStringType = getTypingType(node, 'LiteralString');
|
|
968
982
|
if (literalStringType && (0, types_1.isInstantiableClass)(literalStringType)) {
|
|
@@ -992,7 +1006,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
992
1006
|
// TypeForm (really long, triple-quoted, etc.).
|
|
993
1007
|
const stringNode = node.d.strings[0];
|
|
994
1008
|
const tokenFlags = stringNode.d.token.flags;
|
|
995
|
-
const disallowedTokenFlags = 32 /* StringTokenFlags.Bytes */ |
|
|
1009
|
+
const disallowedTokenFlags = 32 /* StringTokenFlags.Bytes */ |
|
|
1010
|
+
8 /* StringTokenFlags.Raw */ |
|
|
1011
|
+
64 /* StringTokenFlags.Format */ |
|
|
1012
|
+
128 /* StringTokenFlags.Template */ |
|
|
1013
|
+
4 /* StringTokenFlags.Triplicate */;
|
|
996
1014
|
const maxTypeFormStringLength = 256;
|
|
997
1015
|
if ((tokenFlags & disallowedTokenFlags) !== 0 ||
|
|
998
1016
|
stringNode.d.token.escapedValue.length >= maxTypeFormStringLength) {
|
|
@@ -1037,6 +1055,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
1037
1055
|
}
|
|
1038
1056
|
return { type: types_1.UnknownType.create() };
|
|
1039
1057
|
}
|
|
1058
|
+
if (tokenFlags & 128 /* StringTokenFlags.Template */) {
|
|
1059
|
+
if (reportTypeErrors) {
|
|
1060
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.annotationTemplateString(), node);
|
|
1061
|
+
}
|
|
1062
|
+
return { type: types_1.UnknownType.create() };
|
|
1063
|
+
}
|
|
1040
1064
|
// We didn't know at parse time that this string node was going
|
|
1041
1065
|
// to be evaluated as a forward-referenced type. We need
|
|
1042
1066
|
// to re-invoke the parser at this stage.
|
|
@@ -1059,8 +1083,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
1059
1083
|
const isBytes = (node.d.token.flags & 32 /* StringTokenFlags.Bytes */) !== 0;
|
|
1060
1084
|
let typeResult;
|
|
1061
1085
|
let isIncomplete = false;
|
|
1062
|
-
|
|
1063
|
-
|
|
1086
|
+
if (node.nodeType === 49 /* ParseNodeType.String */) {
|
|
1087
|
+
typeResult = {
|
|
1088
|
+
type: cloneBuiltinObjectWithLiteral(node, isBytes ? 'bytes' : 'str', node.d.value),
|
|
1089
|
+
isIncomplete,
|
|
1090
|
+
};
|
|
1091
|
+
}
|
|
1092
|
+
else {
|
|
1093
|
+
const isTemplateString = (node.d.token.flags & 128 /* StringTokenFlags.Template */) !== 0;
|
|
1064
1094
|
let isLiteralString = true;
|
|
1065
1095
|
// If all of the format expressions are of type LiteralString, then
|
|
1066
1096
|
// the resulting formatted string is also LiteralString.
|
|
@@ -1084,7 +1114,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
1084
1114
|
isLiteralString = false;
|
|
1085
1115
|
});
|
|
1086
1116
|
});
|
|
1087
|
-
if (
|
|
1117
|
+
if (isTemplateString) {
|
|
1118
|
+
const templateType = prefetched?.templateClass && (0, types_1.isInstantiableClass)(prefetched?.templateClass)
|
|
1119
|
+
? types_1.ClassType.cloneAsInstance(prefetched.templateClass)
|
|
1120
|
+
: types_1.UnknownType.create();
|
|
1121
|
+
typeResult = { type: templateType, isIncomplete };
|
|
1122
|
+
}
|
|
1123
|
+
else if (!isBytes && isLiteralString) {
|
|
1088
1124
|
const literalStringType = getTypingType(node, 'LiteralString');
|
|
1089
1125
|
if (literalStringType && (0, types_1.isInstantiableClass)(literalStringType)) {
|
|
1090
1126
|
typeResult = { type: types_1.ClassType.cloneAsInstance(literalStringType), isIncomplete };
|
|
@@ -1100,12 +1136,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
1100
1136
|
}
|
|
1101
1137
|
}
|
|
1102
1138
|
}
|
|
1103
|
-
else {
|
|
1104
|
-
typeResult = {
|
|
1105
|
-
type: cloneBuiltinObjectWithLiteral(node, isBytes ? 'bytes' : 'str', node.d.value),
|
|
1106
|
-
isIncomplete,
|
|
1107
|
-
};
|
|
1108
|
-
}
|
|
1109
1139
|
return typeResult;
|
|
1110
1140
|
}
|
|
1111
1141
|
function stripLiteralValue(type) {
|
|
@@ -1205,6 +1235,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
1205
1235
|
if (types_1.TypeBase.isInstantiable(type)) {
|
|
1206
1236
|
return false;
|
|
1207
1237
|
}
|
|
1238
|
+
// Sentinels are always truthy.
|
|
1239
|
+
if ((0, typeUtils_1.isSentinelLiteral)(type)) {
|
|
1240
|
+
return false;
|
|
1241
|
+
}
|
|
1208
1242
|
// Handle tuples specially.
|
|
1209
1243
|
if ((0, typeUtils_1.isTupleClass)(type) && type.priv.tupleTypeArgs) {
|
|
1210
1244
|
return (0, typeUtils_1.isUnboundedTupleClass)(type) || type.priv.tupleTypeArgs.length === 0;
|
|
@@ -1363,6 +1397,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
1363
1397
|
// include, otherwise it should be removed.
|
|
1364
1398
|
return isLiteralFalsy ? subtype : undefined;
|
|
1365
1399
|
}
|
|
1400
|
+
// If the object is a sentinel, we can eliminate it.
|
|
1401
|
+
if ((0, typeUtils_1.isSentinelLiteral)(concreteSubtype)) {
|
|
1402
|
+
return undefined;
|
|
1403
|
+
}
|
|
1366
1404
|
// If the object is a bool, make it "false", since
|
|
1367
1405
|
// "true" is a truthy value.
|
|
1368
1406
|
if (types_1.ClassType.isBuiltIn(concreteSubtype, 'bool')) {
|
|
@@ -1399,6 +1437,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
1399
1437
|
if (concreteSubtype.priv.literalValue instanceof types_1.EnumLiteral) {
|
|
1400
1438
|
isLiteralTruthy = !canBeFalsy(concreteSubtype);
|
|
1401
1439
|
}
|
|
1440
|
+
else if (concreteSubtype.priv.literalValue instanceof types_1.SentinelLiteral) {
|
|
1441
|
+
isLiteralTruthy = true;
|
|
1442
|
+
}
|
|
1402
1443
|
else {
|
|
1403
1444
|
isLiteralTruthy = !!concreteSubtype.priv.literalValue;
|
|
1404
1445
|
}
|
|
@@ -1786,36 +1827,46 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
1786
1827
|
case 35 /* ParseNodeType.MemberAccess */: {
|
|
1787
1828
|
const baseType = getTypeOfExpression(expression.d.leftExpr, 2 /* EvalFlags.MemberAccessBaseDefaults */).type;
|
|
1788
1829
|
const baseTypeConcrete = makeTopLevelTypeVarsConcrete(baseType);
|
|
1789
|
-
|
|
1830
|
+
const memberName = expression.d.member.d.value;
|
|
1790
1831
|
// Normally, baseTypeConcrete will not be a composite type (a union),
|
|
1791
1832
|
// but this can occur. In this case, it's not clear how to handle this
|
|
1792
1833
|
// correctly. For now, we'll just loop through the subtypes and
|
|
1793
1834
|
// use one of them. We'll sort the subtypes for determinism.
|
|
1794
1835
|
(0, typeUtils_1.doForEachSubtype)(baseTypeConcrete, (baseSubtype) => {
|
|
1795
1836
|
if ((0, types_1.isClassInstance)(baseSubtype)) {
|
|
1796
|
-
classMemberInfo = (0, typeUtils_1.lookUpObjectMember)(baseSubtype,
|
|
1837
|
+
const classMemberInfo = (0, typeUtils_1.lookUpObjectMember)(baseSubtype, memberName, 64 /* MemberAccessFlags.DeclaredTypesOnly */);
|
|
1797
1838
|
classOrObjectBase = baseSubtype;
|
|
1798
1839
|
memberAccessClass = classMemberInfo?.classType;
|
|
1840
|
+
symbol = classMemberInfo?.symbol;
|
|
1841
|
+
useDescriptorSetterType = true;
|
|
1799
1842
|
// If this is an instance member (e.g. a dataclass field), don't
|
|
1800
1843
|
// bind it to the object if it's a function.
|
|
1801
|
-
|
|
1802
|
-
bindFunction = false;
|
|
1803
|
-
}
|
|
1804
|
-
useDescriptorSetterType = true;
|
|
1844
|
+
bindFunction = !classMemberInfo?.isInstanceMember;
|
|
1805
1845
|
}
|
|
1806
1846
|
else if ((0, types_1.isInstantiableClass)(baseSubtype)) {
|
|
1807
|
-
classMemberInfo = (0, typeUtils_1.lookUpClassMember)(baseSubtype,
|
|
1847
|
+
const classMemberInfo = (0, typeUtils_1.lookUpClassMember)(baseSubtype, memberName, 16 /* MemberAccessFlags.SkipInstanceMembers */ | 64 /* MemberAccessFlags.DeclaredTypesOnly */);
|
|
1808
1848
|
classOrObjectBase = baseSubtype;
|
|
1809
1849
|
memberAccessClass = classMemberInfo?.classType;
|
|
1850
|
+
symbol = classMemberInfo?.symbol;
|
|
1851
|
+
useDescriptorSetterType = false;
|
|
1852
|
+
bindFunction = true;
|
|
1853
|
+
}
|
|
1854
|
+
else if ((0, types_1.isModule)(baseSubtype)) {
|
|
1855
|
+
classOrObjectBase = undefined;
|
|
1856
|
+
memberAccessClass = undefined;
|
|
1857
|
+
symbol = types_1.ModuleType.getField(baseSubtype, memberName);
|
|
1858
|
+
if (symbol && !symbol.hasTypedDeclarations()) {
|
|
1859
|
+
// Do not use inferred types for the declared type.
|
|
1860
|
+
symbol = undefined;
|
|
1861
|
+
}
|
|
1862
|
+
useDescriptorSetterType = false;
|
|
1863
|
+
bindFunction = false;
|
|
1810
1864
|
}
|
|
1811
1865
|
},
|
|
1812
1866
|
/* sortSubtypes */ true);
|
|
1813
1867
|
if ((0, types_1.isTypeVar)(baseType)) {
|
|
1814
1868
|
selfType = baseType;
|
|
1815
1869
|
}
|
|
1816
|
-
if (classMemberInfo) {
|
|
1817
|
-
symbol = classMemberInfo.symbol;
|
|
1818
|
-
}
|
|
1819
1870
|
break;
|
|
1820
1871
|
}
|
|
1821
1872
|
case 27 /* ParseNodeType.Index */: {
|
|
@@ -1857,6 +1908,30 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
1857
1908
|
}
|
|
1858
1909
|
break;
|
|
1859
1910
|
}
|
|
1911
|
+
case 52 /* ParseNodeType.Tuple */: {
|
|
1912
|
+
// If this is a tuple expression with at least one item and no
|
|
1913
|
+
// unpacked items, and all of the items have declared types,
|
|
1914
|
+
// we can assume a declared type for the resulting tuple. This
|
|
1915
|
+
// is needed to enable bidirectional type inference when assigning
|
|
1916
|
+
// to an unpacked tuple.
|
|
1917
|
+
if (expression.d.items.length > 0 &&
|
|
1918
|
+
!expression.d.items.some((item) => item.nodeType === 56 /* ParseNodeType.Unpack */)) {
|
|
1919
|
+
const itemTypes = [];
|
|
1920
|
+
expression.d.items.forEach((expr) => {
|
|
1921
|
+
const itemType = getDeclaredTypeForExpression(expr, usage);
|
|
1922
|
+
if (itemType) {
|
|
1923
|
+
itemTypes.push(itemType);
|
|
1924
|
+
}
|
|
1925
|
+
});
|
|
1926
|
+
if (itemTypes.length === expression.d.items.length) {
|
|
1927
|
+
// If all items have a declared type, return a tuple of those types.
|
|
1928
|
+
return (0, tuples_1.makeTupleObject)(evaluatorInterface, itemTypes.map((t) => {
|
|
1929
|
+
return { type: t, isUnbounded: false };
|
|
1930
|
+
}));
|
|
1931
|
+
}
|
|
1932
|
+
}
|
|
1933
|
+
break;
|
|
1934
|
+
}
|
|
1860
1935
|
}
|
|
1861
1936
|
if (symbol) {
|
|
1862
1937
|
let declaredType = getDeclaredTypeOfSymbol(symbol)?.type;
|
|
@@ -2123,6 +2198,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2123
2198
|
function getTypingType(node, symbolName) {
|
|
2124
2199
|
return (getTypeOfModule(node, symbolName, ['typing']) ?? getTypeOfModule(node, symbolName, ['typing_extensions']));
|
|
2125
2200
|
}
|
|
2201
|
+
function getTypeCheckerInternalsType(node, symbolName) {
|
|
2202
|
+
return getTypeOfModule(node, symbolName, ['_typeshed', '_type_checker_internals']);
|
|
2203
|
+
}
|
|
2126
2204
|
function getTypesType(node, symbolName) {
|
|
2127
2205
|
return getTypeOfModule(node, symbolName, ['types']);
|
|
2128
2206
|
}
|
|
@@ -2173,7 +2251,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2173
2251
|
if (node.parent) {
|
|
2174
2252
|
return getNodeReachability(node.parent, sourceNode);
|
|
2175
2253
|
}
|
|
2176
|
-
return typeEvaluatorTypes_1.Reachability.
|
|
2254
|
+
return typeEvaluatorTypes_1.Reachability.UnreachableStructural;
|
|
2177
2255
|
}
|
|
2178
2256
|
const sourceFlowNode = sourceNode ? AnalyzerNodeInfo.getFlowNode(sourceNode) : undefined;
|
|
2179
2257
|
return codeFlowEngine.getFlowNodeReachability(flowNode, sourceFlowNode);
|
|
@@ -2181,7 +2259,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2181
2259
|
function getAfterNodeReachability(node) {
|
|
2182
2260
|
const returnFlowNode = AnalyzerNodeInfo.getAfterFlowNode(node);
|
|
2183
2261
|
if (!returnFlowNode) {
|
|
2184
|
-
return typeEvaluatorTypes_1.Reachability.
|
|
2262
|
+
return typeEvaluatorTypes_1.Reachability.UnreachableStructural;
|
|
2185
2263
|
}
|
|
2186
2264
|
if (checkCodeFlowTooComplex(node)) {
|
|
2187
2265
|
return typeEvaluatorTypes_1.Reachability.Reachable;
|
|
@@ -2190,7 +2268,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2190
2268
|
if (reachability !== typeEvaluatorTypes_1.Reachability.Reachable) {
|
|
2191
2269
|
return reachability;
|
|
2192
2270
|
}
|
|
2193
|
-
|
|
2271
|
+
const executionScopeNode = ParseTreeUtils.getExecutionScopeNode(node);
|
|
2272
|
+
if (!isFlowNodeReachableUsingNeverNarrowing(executionScopeNode, returnFlowNode)) {
|
|
2194
2273
|
return typeEvaluatorTypes_1.Reachability.UnreachableByAnalysis;
|
|
2195
2274
|
}
|
|
2196
2275
|
return typeEvaluatorTypes_1.Reachability.Reachable;
|
|
@@ -2198,7 +2277,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2198
2277
|
// Although isFlowNodeReachable indicates that the node is reachable, it
|
|
2199
2278
|
// may not be reachable if we apply "never narrowing".
|
|
2200
2279
|
function isFlowNodeReachableUsingNeverNarrowing(node, flowNode) {
|
|
2201
|
-
const analyzer = getCodeFlowAnalyzerForNode(node
|
|
2280
|
+
const analyzer = getCodeFlowAnalyzerForNode(node, /* typeAtStart */ undefined);
|
|
2202
2281
|
if (checkCodeFlowTooComplex(node)) {
|
|
2203
2282
|
return true;
|
|
2204
2283
|
}
|
|
@@ -2226,12 +2305,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2226
2305
|
function addInformation(message, node, range) {
|
|
2227
2306
|
return addDiagnosticWithSuppressionCheck('information', message, node, range);
|
|
2228
2307
|
}
|
|
2229
|
-
function addUnusedCode(node, textRange) {
|
|
2230
|
-
if (!isDiagnosticSuppressedForNode(node)) {
|
|
2231
|
-
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
|
2232
|
-
fileInfo.diagnosticSink.addUnusedCodeWithTextRange(localize_1.LocMessage.unreachableCode(), textRange);
|
|
2233
|
-
}
|
|
2234
|
-
}
|
|
2235
2308
|
function addUnreachableCode(node, reachability, textRange) {
|
|
2236
2309
|
if (reachability === typeEvaluatorTypes_1.Reachability.Reachable) {
|
|
2237
2310
|
return;
|
|
@@ -2239,10 +2312,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2239
2312
|
if (!isDiagnosticSuppressedForNode(node)) {
|
|
2240
2313
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
|
2241
2314
|
const reportTypeReachability = fileInfo.diagnosticRuleSet.enableReachabilityAnalysis;
|
|
2242
|
-
if (reachability === typeEvaluatorTypes_1.Reachability.
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2315
|
+
if (reachability === typeEvaluatorTypes_1.Reachability.UnreachableStructural ||
|
|
2316
|
+
reachability === typeEvaluatorTypes_1.Reachability.UnreachableStaticCondition ||
|
|
2317
|
+
reportTypeReachability) {
|
|
2318
|
+
fileInfo.diagnosticSink.addUnreachableCodeWithTextRange(reachability === typeEvaluatorTypes_1.Reachability.UnreachableStructural
|
|
2319
|
+
? localize_1.LocMessage.unreachableCodeStructure()
|
|
2320
|
+
: reachability === typeEvaluatorTypes_1.Reachability.UnreachableStaticCondition
|
|
2321
|
+
? localize_1.LocMessage.unreachableCodeCondition()
|
|
2322
|
+
: localize_1.LocMessage.unreachableCodeType(), textRange);
|
|
2246
2323
|
}
|
|
2247
2324
|
}
|
|
2248
2325
|
}
|
|
@@ -2659,7 +2736,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2659
2736
|
// If the type includes promotion types, expand these to their constituent types.
|
|
2660
2737
|
function expandPromotionTypes(node, type, excludeBytes = false) {
|
|
2661
2738
|
return (0, typeUtils_1.mapSubtypes)(type, (subtype) => {
|
|
2662
|
-
if (!(0, types_1.isClass)(subtype) || !subtype.priv.includePromotions) {
|
|
2739
|
+
if (!(0, types_1.isClass)(subtype) || !subtype.priv.includePromotions || subtype.priv.literalValue !== undefined) {
|
|
2663
2740
|
return subtype;
|
|
2664
2741
|
}
|
|
2665
2742
|
if (excludeBytes && types_1.ClassType.isBuiltIn(subtype, 'bytes')) {
|
|
@@ -3233,6 +3310,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
3233
3310
|
type = types_1.UnknownType.create();
|
|
3234
3311
|
}
|
|
3235
3312
|
}
|
|
3313
|
+
// If we're expecting a type expression and got a sentinel literal instance,
|
|
3314
|
+
// treat it as its instantiable counterpart. This is similar to how None
|
|
3315
|
+
// is treated in a type expression context.
|
|
3316
|
+
if ((flags & 128 /* EvalFlags.InstantiableType */) !== 0 && (0, types_1.isClassInstance)(type) && (0, typeUtils_1.isSentinelLiteral)(type)) {
|
|
3317
|
+
type = types_1.ClassType.cloneAsInstantiable(type);
|
|
3318
|
+
}
|
|
3236
3319
|
type = convertSpecialFormToRuntimeValue(type, flags);
|
|
3237
3320
|
if ((flags & 256 /* EvalFlags.TypeExpression */) === 0) {
|
|
3238
3321
|
reportUseOfTypeCheckOnly(type, node);
|
|
@@ -3306,6 +3389,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
3306
3389
|
if ((0, types_1.isClass)(type) && !type.priv.includeSubclasses && types_1.ClassType.isValidTypeAliasClass(type)) {
|
|
3307
3390
|
return true;
|
|
3308
3391
|
}
|
|
3392
|
+
if ((0, typeUtils_1.isSentinelLiteral)(type)) {
|
|
3393
|
+
return true;
|
|
3394
|
+
}
|
|
3309
3395
|
return false;
|
|
3310
3396
|
}
|
|
3311
3397
|
// Reports diagnostics if type isn't valid within a type expression.
|
|
@@ -3339,7 +3425,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
3339
3425
|
// Isinstance treats traditional (non-PEP 695) type aliases that are unions
|
|
3340
3426
|
// as tuples of classes rather than unions.
|
|
3341
3427
|
if ((flags & 536870912 /* EvalFlags.IsinstanceArg */) !== 0) {
|
|
3342
|
-
if ((0, types_1.isUnion)(type) && type.props?.typeAliasInfo && !type.props.typeAliasInfo.shared.
|
|
3428
|
+
if ((0, types_1.isUnion)(type) && type.props?.typeAliasInfo && !type.props.typeAliasInfo.shared.isTypeAliasType) {
|
|
3343
3429
|
return type;
|
|
3344
3430
|
}
|
|
3345
3431
|
}
|
|
@@ -3868,6 +3954,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
3868
3954
|
}
|
|
3869
3955
|
case 6 /* TypeCategory.Class */: {
|
|
3870
3956
|
let typeResult;
|
|
3957
|
+
// If this is a class-like function created via NewType, treat
|
|
3958
|
+
// it like a function for purposes of member accesses.
|
|
3959
|
+
if (types_1.ClassType.isNewTypeClass(baseType) &&
|
|
3960
|
+
!baseType.priv.includeSubclasses &&
|
|
3961
|
+
prefetched?.functionClass &&
|
|
3962
|
+
(0, types_1.isClass)(prefetched.functionClass)) {
|
|
3963
|
+
baseType = types_1.ClassType.cloneAsInstance(prefetched.functionClass);
|
|
3964
|
+
}
|
|
3871
3965
|
const enumMemberResult = (0, enums_1.getTypeOfEnumMember)(evaluatorInterface, node, baseType, memberName, isIncomplete);
|
|
3872
3966
|
if (enumMemberResult) {
|
|
3873
3967
|
if (usage.method === 'get') {
|
|
@@ -4026,9 +4120,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
4026
4120
|
}
|
|
4027
4121
|
case 4 /* TypeCategory.Function */:
|
|
4028
4122
|
case 5 /* TypeCategory.Overloaded */: {
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
//
|
|
4123
|
+
const hasSelf = (0, types_1.isMethodType)(baseType);
|
|
4124
|
+
if (memberName === '__self__' && hasSelf) {
|
|
4125
|
+
// Handle "__self__" specially because MethodType defines
|
|
4126
|
+
// it simply as "object". We can do better here.
|
|
4032
4127
|
let functionType;
|
|
4033
4128
|
if ((0, types_1.isFunction)(baseType)) {
|
|
4034
4129
|
functionType = baseType;
|
|
@@ -4039,18 +4134,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
4039
4134
|
functionType = overloads[0];
|
|
4040
4135
|
}
|
|
4041
4136
|
}
|
|
4042
|
-
|
|
4043
|
-
functionType.priv.preBoundFlags !== undefined &&
|
|
4044
|
-
(functionType.priv.preBoundFlags & 4 /* FunctionTypeFlags.StaticMethod */) === 0) {
|
|
4045
|
-
type = functionType.priv.boundToType;
|
|
4046
|
-
}
|
|
4137
|
+
type = functionType?.priv.boundToType;
|
|
4047
4138
|
}
|
|
4048
4139
|
else {
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
? (0, typeUtils_1.convertToInstance)(prefetched.functionClass)
|
|
4052
|
-
: types_1.UnknownType.create(),
|
|
4053
|
-
}, usage, flags).type;
|
|
4140
|
+
const altType = hasSelf ? prefetched?.methodClass : prefetched?.functionClass;
|
|
4141
|
+
type = getTypeOfMemberAccessWithBaseType(node, { type: altType ? (0, typeUtils_1.convertToInstance)(altType) : types_1.UnknownType.create() }, usage, flags).type;
|
|
4054
4142
|
}
|
|
4055
4143
|
break;
|
|
4056
4144
|
}
|
|
@@ -4061,7 +4149,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
4061
4149
|
// member could not be accessed.
|
|
4062
4150
|
if (!type) {
|
|
4063
4151
|
const isFunctionRule = (0, types_1.isFunctionOrOverloaded)(baseType) ||
|
|
4064
|
-
((0, types_1.isClassInstance)(baseType) && types_1.ClassType.isBuiltIn(baseType, 'function'));
|
|
4152
|
+
((0, types_1.isClassInstance)(baseType) && types_1.ClassType.isBuiltIn(baseType, ['function', 'FunctionType']));
|
|
4065
4153
|
if (!baseTypeResult.isIncomplete) {
|
|
4066
4154
|
let diagMessage = localize_1.LocMessage.memberAccess();
|
|
4067
4155
|
if (usage.method === 'set') {
|
|
@@ -4236,7 +4324,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
4236
4324
|
let memberAccessDeprecationInfo;
|
|
4237
4325
|
type = (0, typeUtils_1.mapSubtypes)(type, (subtype) => {
|
|
4238
4326
|
const concreteSubtype = makeTopLevelTypeVarsConcrete(subtype);
|
|
4239
|
-
const isClassMember = !memberInfo || memberInfo.isClassMember;
|
|
4327
|
+
const isClassMember = !memberInfo || (memberInfo.isClassMember && !memberInfo.isSlotsMember);
|
|
4240
4328
|
let resultType;
|
|
4241
4329
|
if ((0, types_1.isClass)(concreteSubtype) && isClassMember && errorNode) {
|
|
4242
4330
|
const descResult = applyDescriptorAccessMethod(subtype, concreteSubtype, memberInfo, classType, selfType, flags, errorNode, memberName, usage, diag);
|
|
@@ -6189,31 +6277,33 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
6189
6277
|
secondArgType = getTypeOfExpression(node.d.args[1].d.valueExpr).type;
|
|
6190
6278
|
const secondArgConcreteType = makeTopLevelTypeVarsConcrete(secondArgType);
|
|
6191
6279
|
let reportError = false;
|
|
6192
|
-
|
|
6193
|
-
|
|
6194
|
-
|
|
6195
|
-
else if ((0, types_1.isClassInstance)(secondArgConcreteType)) {
|
|
6196
|
-
if ((0, types_1.isInstantiableClass)(concreteTargetClassType)) {
|
|
6197
|
-
if (!(0, typeUtils_1.derivesFromClassRecursive)(types_1.ClassType.cloneAsInstantiable(secondArgConcreteType), concreteTargetClassType,
|
|
6198
|
-
/* ignoreUnknown */ true)) {
|
|
6199
|
-
reportError = true;
|
|
6200
|
-
}
|
|
6280
|
+
(0, typeUtils_1.doForEachSubtype)(secondArgConcreteType, (secondArgSubtype) => {
|
|
6281
|
+
if ((0, types_1.isAnyOrUnknown)(secondArgSubtype)) {
|
|
6282
|
+
// Ignore unknown or any types.
|
|
6201
6283
|
}
|
|
6202
|
-
|
|
6203
|
-
|
|
6204
|
-
|
|
6205
|
-
if ((0, types_1.isInstantiableClass)(concreteTargetClassType)) {
|
|
6206
|
-
if (!types_1.ClassType.isBuiltIn(concreteTargetClassType, 'type') &&
|
|
6207
|
-
!(0, typeUtils_1.derivesFromClassRecursive)(secondArgConcreteType, concreteTargetClassType,
|
|
6284
|
+
else if ((0, types_1.isClassInstance)(secondArgSubtype)) {
|
|
6285
|
+
if ((0, types_1.isInstantiableClass)(concreteTargetClassType)) {
|
|
6286
|
+
if (!(0, typeUtils_1.derivesFromClassRecursive)(types_1.ClassType.cloneAsInstantiable(secondArgSubtype), concreteTargetClassType,
|
|
6208
6287
|
/* ignoreUnknown */ true)) {
|
|
6209
|
-
|
|
6288
|
+
reportError = true;
|
|
6289
|
+
}
|
|
6210
6290
|
}
|
|
6291
|
+
bindToType = secondArgSubtype;
|
|
6211
6292
|
}
|
|
6212
|
-
|
|
6213
|
-
|
|
6214
|
-
|
|
6215
|
-
|
|
6216
|
-
|
|
6293
|
+
else if ((0, types_1.isInstantiableClass)(secondArgSubtype)) {
|
|
6294
|
+
if ((0, types_1.isInstantiableClass)(concreteTargetClassType)) {
|
|
6295
|
+
if (!types_1.ClassType.isBuiltIn(concreteTargetClassType, 'type') &&
|
|
6296
|
+
!(0, typeUtils_1.derivesFromClassRecursive)(secondArgSubtype, concreteTargetClassType,
|
|
6297
|
+
/* ignoreUnknown */ true)) {
|
|
6298
|
+
reportError = true;
|
|
6299
|
+
}
|
|
6300
|
+
}
|
|
6301
|
+
bindToType = secondArgSubtype;
|
|
6302
|
+
}
|
|
6303
|
+
else {
|
|
6304
|
+
reportError = true;
|
|
6305
|
+
}
|
|
6306
|
+
});
|
|
6217
6307
|
if (reportError) {
|
|
6218
6308
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportArgumentType, localize_1.LocMessage.superCallSecondArg().format({ type: printType(targetClassType) }), node.d.args[1].d.valueExpr);
|
|
6219
6309
|
return { type: types_1.UnknownType.create() };
|
|
@@ -7144,6 +7234,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
7144
7234
|
return subtype;
|
|
7145
7235
|
}
|
|
7146
7236
|
if ((0, types_1.isClass)(subtype)) {
|
|
7237
|
+
// Specifically handle the case where the subtype is a class-like
|
|
7238
|
+
// object created by calling NewType. At runtime, it's actually
|
|
7239
|
+
// a FunctionType object.
|
|
7240
|
+
if ((0, types_1.isClassInstance)(subtype) &&
|
|
7241
|
+
types_1.ClassType.isNewTypeClass(subtype) &&
|
|
7242
|
+
!subtype.priv.includeSubclasses) {
|
|
7243
|
+
if (prefetched?.functionClass) {
|
|
7244
|
+
return prefetched.functionClass;
|
|
7245
|
+
}
|
|
7246
|
+
}
|
|
7147
7247
|
return (0, typeUtils_1.convertToInstantiable)(stripLiteralValue(subtype));
|
|
7148
7248
|
}
|
|
7149
7249
|
if (types_1.TypeBase.isInstance(subtype)) {
|
|
@@ -7205,6 +7305,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
7205
7305
|
if (className === 'NewType') {
|
|
7206
7306
|
return { returnType: createNewType(errorNode, argList) };
|
|
7207
7307
|
}
|
|
7308
|
+
// Handle the Sentinel call specially.
|
|
7309
|
+
if (className === 'Sentinel') {
|
|
7310
|
+
if (AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.enableExperimentalFeatures) {
|
|
7311
|
+
return { returnType: (0, sentinel_1.createSentinelType)(evaluatorInterface, errorNode, argList) };
|
|
7312
|
+
}
|
|
7313
|
+
}
|
|
7208
7314
|
if (types_1.ClassType.isSpecialFormClass(expandedCallType)) {
|
|
7209
7315
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.typeNotIntantiable().format({ type: className }), errorNode);
|
|
7210
7316
|
return { returnType: types_1.UnknownType.create(), argumentErrors: true };
|
|
@@ -9355,7 +9461,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
9355
9461
|
}
|
|
9356
9462
|
}
|
|
9357
9463
|
return getTypeOfTypeAliasCommon(nameNode, nameNode, valueExpr,
|
|
9358
|
-
/* isPep695Syntax */
|
|
9464
|
+
/* isPep695Syntax */ false,
|
|
9359
9465
|
/* typeParamNodes */ undefined, () => typeParams);
|
|
9360
9466
|
}
|
|
9361
9467
|
function getBooleanValue(node) {
|
|
@@ -9440,13 +9546,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
9440
9546
|
if (!isBaseClassAny) {
|
|
9441
9547
|
// Synthesize an __init__ method that accepts only the specified type.
|
|
9442
9548
|
const initType = types_1.FunctionType.createSynthesizedInstance('__init__');
|
|
9443
|
-
types_1.FunctionType.addParam(initType, types_1.FunctionParam.create(0 /* ParamCategory.Simple */, types_1.
|
|
9549
|
+
types_1.FunctionType.addParam(initType, types_1.FunctionParam.create(0 /* ParamCategory.Simple */, types_1.AnyType.create(), types_1.FunctionParamFlags.TypeDeclared, 'self'));
|
|
9444
9550
|
types_1.FunctionType.addParam(initType, types_1.FunctionParam.create(0 /* ParamCategory.Simple */, types_1.ClassType.cloneAsInstance(baseClass), types_1.FunctionParamFlags.TypeDeclared, '_x'));
|
|
9445
9551
|
initType.shared.declaredReturnType = getNoneType();
|
|
9446
9552
|
types_1.ClassType.getSymbolTable(classType).set('__init__', symbol_1.Symbol.createWithType(4 /* SymbolFlags.ClassMember */, initType));
|
|
9447
9553
|
// Synthesize a trivial __new__ method.
|
|
9448
9554
|
const newType = types_1.FunctionType.createSynthesizedInstance('__new__', 1 /* FunctionTypeFlags.ConstructorMethod */);
|
|
9449
|
-
types_1.FunctionType.addParam(newType, types_1.FunctionParam.create(0 /* ParamCategory.Simple */,
|
|
9555
|
+
types_1.FunctionType.addParam(newType, types_1.FunctionParam.create(0 /* ParamCategory.Simple */, types_1.AnyType.create(), types_1.FunctionParamFlags.TypeDeclared, 'cls'));
|
|
9450
9556
|
types_1.FunctionType.addDefaultParams(newType);
|
|
9451
9557
|
newType.shared.declaredReturnType = types_1.ClassType.cloneAsInstance(classType);
|
|
9452
9558
|
newType.priv.constructorTypeVarScopeId = (0, typeUtils_1.getTypeVarScopeId)(classType);
|
|
@@ -10883,7 +10989,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
10883
10989
|
}
|
|
10884
10990
|
if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0) {
|
|
10885
10991
|
itemExpr.d.strings.forEach((stringNode) => {
|
|
10886
|
-
if ((stringNode.d.token.flags &
|
|
10992
|
+
if ((stringNode.d.token.flags & 1024 /* StringTokenFlags.NamedUnicodeEscape */) !== 0) {
|
|
10887
10993
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.literalNamedUnicodeEscape(), stringNode);
|
|
10888
10994
|
isValidTypeForm = false;
|
|
10889
10995
|
}
|
|
@@ -11552,7 +11658,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
11552
11658
|
names: variadics.map((v) => `"${v.shared.name}"`).join(', '),
|
|
11553
11659
|
}), errorNode);
|
|
11554
11660
|
}
|
|
11555
|
-
if (!sharedInfo.
|
|
11661
|
+
if (!sharedInfo.isTypeAliasType && !isPep695TypeVarType) {
|
|
11556
11662
|
const boundTypeVars = typeParams.filter((typeVar) => typeVar.priv.scopeId !== sharedInfo.typeVarScopeId &&
|
|
11557
11663
|
typeVar.priv.scopeType === 0 /* TypeVarScopeType.Class */);
|
|
11558
11664
|
if (boundTypeVars.length > 0) {
|
|
@@ -11571,7 +11677,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
11571
11677
|
});
|
|
11572
11678
|
// All PEP 695 type aliases are special forms because they are
|
|
11573
11679
|
// TypeAliasType objects at runtime.
|
|
11574
|
-
if (sharedInfo.
|
|
11680
|
+
if (sharedInfo.isTypeAliasType || isPep695TypeVarType) {
|
|
11575
11681
|
const typeAliasTypeClass = getTypingType(errorNode, 'TypeAliasType');
|
|
11576
11682
|
if (typeAliasTypeClass && (0, types_1.isInstantiableClass)(typeAliasTypeClass)) {
|
|
11577
11683
|
typeAlias = types_1.TypeBase.cloneAsSpecialForm(typeAlias, types_1.ClassType.cloneAsInstance(typeAliasTypeClass));
|
|
@@ -11625,7 +11731,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
11625
11731
|
// The _TypedDict class is marked as abstract, but the
|
|
11626
11732
|
// methods that are abstract are overridden and shouldn't
|
|
11627
11733
|
// cause the TypedDict to be marked as abstract.
|
|
11628
|
-
if ((0, types_1.isInstantiableClass)(baseClass) &&
|
|
11734
|
+
if ((0, types_1.isInstantiableClass)(baseClass) &&
|
|
11735
|
+
types_1.ClassType.isBuiltIn(baseClass, ['_TypedDict', 'TypedDictFallback'])) {
|
|
11629
11736
|
baseClass = types_1.ClassType.cloneWithNewFlags(baseClass, baseClass.shared.flags &
|
|
11630
11737
|
~(64 /* ClassTypeFlags.SupportsAbstractMethods */ | 1048576 /* ClassTypeFlags.TypeCheckOnly */));
|
|
11631
11738
|
}
|
|
@@ -11847,7 +11954,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
11847
11954
|
}
|
|
11848
11955
|
}
|
|
11849
11956
|
if (typeAliasNameNode) {
|
|
11850
|
-
typeAliasPlaceholder = synthesizeTypeAliasPlaceholder(typeAliasNameNode
|
|
11957
|
+
typeAliasPlaceholder = synthesizeTypeAliasPlaceholder(typeAliasNameNode);
|
|
11851
11958
|
writeTypeCache(node, { type: typeAliasPlaceholder }, /* flags */ undefined);
|
|
11852
11959
|
writeTypeCache(node.d.leftExpr, { type: typeAliasPlaceholder }, /* flags */ undefined);
|
|
11853
11960
|
if (node.d.leftExpr.nodeType === 54 /* ParseNodeType.TypeAnnotation */) {
|
|
@@ -11907,7 +12014,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
11907
12014
|
}
|
|
11908
12015
|
// Synthesize a TypeVar that acts as a placeholder for a type alias. This allows
|
|
11909
12016
|
// the type alias definition to refer to itself.
|
|
11910
|
-
function synthesizeTypeAliasPlaceholder(nameNode,
|
|
12017
|
+
function synthesizeTypeAliasPlaceholder(nameNode, isTypeAliasType = false) {
|
|
11911
12018
|
const placeholder = types_1.TypeVarType.createInstantiable(`__type_alias_${nameNode.d.value}`);
|
|
11912
12019
|
placeholder.shared.isSynthesized = true;
|
|
11913
12020
|
const typeVarScopeId = ParseTreeUtils.getScopeIdForNode(nameNode);
|
|
@@ -11918,7 +12025,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
11918
12025
|
moduleName: fileInfo.moduleName,
|
|
11919
12026
|
fileUri: fileInfo.fileUri,
|
|
11920
12027
|
typeVarScopeId,
|
|
11921
|
-
|
|
12028
|
+
isTypeAliasType,
|
|
11922
12029
|
typeParams: undefined,
|
|
11923
12030
|
computedVariance: undefined,
|
|
11924
12031
|
};
|
|
@@ -11946,7 +12053,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
11946
12053
|
}
|
|
11947
12054
|
// Synthesize a type variable that represents the type alias while we're
|
|
11948
12055
|
// evaluating it. This allows us to handle recursive definitions.
|
|
11949
|
-
const typeAliasTypeVar = synthesizeTypeAliasPlaceholder(nameNode,
|
|
12056
|
+
const typeAliasTypeVar = synthesizeTypeAliasPlaceholder(nameNode, /* isTypeAliasType */ true);
|
|
11950
12057
|
// Write the type to the type cache to support recursive type alias definitions.
|
|
11951
12058
|
writeTypeCache(nameNode, { type: typeAliasTypeVar }, /* flags */ undefined);
|
|
11952
12059
|
// Set a partial type to handle recursive (self-referential) type aliases.
|
|
@@ -11960,10 +12067,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
11960
12067
|
if (typeAliasTypeVar.shared.recursiveAlias) {
|
|
11961
12068
|
typeAliasTypeVar.shared.recursiveAlias.typeParams = typeParams ?? [];
|
|
11962
12069
|
}
|
|
11963
|
-
|
|
11964
|
-
|
|
11965
|
-
|
|
11966
|
-
|
|
12070
|
+
let aliasTypeResult;
|
|
12071
|
+
if (isPep695Syntax) {
|
|
12072
|
+
aliasTypeResult = getTypeOfExpressionExpectingType(valueNode, {
|
|
12073
|
+
forwardRefs: true,
|
|
12074
|
+
typeExpression: true,
|
|
12075
|
+
});
|
|
12076
|
+
}
|
|
12077
|
+
else {
|
|
12078
|
+
const flags = 128 /* EvalFlags.InstantiableType */ |
|
|
12079
|
+
256 /* EvalFlags.TypeExpression */ |
|
|
12080
|
+
8 /* EvalFlags.StrLiteralAsType */ |
|
|
12081
|
+
32 /* EvalFlags.NoParamSpec */ |
|
|
12082
|
+
64 /* EvalFlags.NoTypeVarTuple */ |
|
|
12083
|
+
131072 /* EvalFlags.NoClassVar */;
|
|
12084
|
+
aliasTypeResult = getTypeOfExpression(valueNode, flags);
|
|
12085
|
+
}
|
|
11967
12086
|
let isIncomplete = false;
|
|
11968
12087
|
let aliasType = aliasTypeResult.type;
|
|
11969
12088
|
if (aliasTypeResult.isIncomplete) {
|
|
@@ -12065,8 +12184,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
12065
12184
|
if (fileInfo.isStubFile) {
|
|
12066
12185
|
classFlags |= 262144 /* ClassTypeFlags.DefinedInStub */;
|
|
12067
12186
|
}
|
|
12068
|
-
const classType = types_1.ClassType.createInstantiable(node.d.name.d.value, ParseTreeUtils.getClassFullName(node, fileInfo.moduleName, node.d.name.d.value), fileInfo.moduleName, fileInfo.fileUri, classFlags,
|
|
12069
|
-
/* typeSourceId */ 0,
|
|
12187
|
+
const classType = types_1.ClassType.createInstantiable(node.d.name.d.value, ParseTreeUtils.getClassFullName(node, fileInfo.moduleName, node.d.name.d.value), fileInfo.moduleName, fileInfo.fileUri, classFlags, ParseTreeUtils.getTypeSourceId(node),
|
|
12070
12188
|
/* declaredMetaclass */ undefined,
|
|
12071
12189
|
/* effectiveMetaclass */ undefined, ParseTreeUtils.getDocString(node.d.suite.d.statements));
|
|
12072
12190
|
classType.shared.typeVarScopeId = ParseTreeUtils.getScopeIdForNode(node);
|
|
@@ -12238,11 +12356,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
12238
12356
|
}
|
|
12239
12357
|
// Determine if the class is abstract. Protocol classes support abstract methods
|
|
12240
12358
|
// because they are constructed by the _ProtocolMeta metaclass, which derives
|
|
12241
|
-
// from ABCMeta.
|
|
12242
|
-
|
|
12243
|
-
// because of dependencies on some of these built-in protocol classes.
|
|
12244
|
-
if (types_1.ClassType.supportsAbstractMethods(argType) ||
|
|
12245
|
-
(types_1.ClassType.isProtocolClass(argType) && !types_1.ClassType.isBuiltIn(argType))) {
|
|
12359
|
+
// from ABCMeta.
|
|
12360
|
+
if (types_1.ClassType.supportsAbstractMethods(argType) || types_1.ClassType.isProtocolClass(argType)) {
|
|
12246
12361
|
classType.shared.flags |= 64 /* ClassTypeFlags.SupportsAbstractMethods */;
|
|
12247
12362
|
}
|
|
12248
12363
|
if (types_1.ClassType.isPropertyClass(argType)) {
|
|
@@ -12393,8 +12508,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
12393
12508
|
}
|
|
12394
12509
|
else if (variadics.length > 0) {
|
|
12395
12510
|
// Make sure a TypeVar with a default doesn't come after a TypeVarTuple.
|
|
12396
|
-
const firstVariadicIndex =
|
|
12397
|
-
const typeVarWithDefaultIndex =
|
|
12511
|
+
const firstVariadicIndex = typeParams.findIndex((param) => (0, types_1.isTypeVarTuple)(param));
|
|
12512
|
+
const typeVarWithDefaultIndex = typeParams.findIndex((param, index) => index > firstVariadicIndex && !(0, types_1.isParamSpec)(param) && param.shared.isDefaultExplicit);
|
|
12398
12513
|
if (typeVarWithDefaultIndex >= 0) {
|
|
12399
12514
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarWithDefaultFollowsVariadic().format({
|
|
12400
12515
|
typeVarName: typeParams[typeVarWithDefaultIndex].shared.name,
|
|
@@ -12558,7 +12673,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
12558
12673
|
classType.shared.baseClasses.forEach((baseClass) => {
|
|
12559
12674
|
if ((0, types_1.isClass)(baseClass) &&
|
|
12560
12675
|
!types_1.ClassType.isTypedDictClass(baseClass) &&
|
|
12561
|
-
!types_1.ClassType.isBuiltIn(baseClass, ['_TypedDict', 'Generic'])) {
|
|
12676
|
+
!types_1.ClassType.isBuiltIn(baseClass, ['_TypedDict', 'TypedDictFallback', 'Generic'])) {
|
|
12562
12677
|
foundInvalidBaseClass = true;
|
|
12563
12678
|
diag.addMessage(localize_1.LocAddendum.typedDictBaseClass().format({ type: baseClass.shared.name }));
|
|
12564
12679
|
}
|
|
@@ -13479,11 +13594,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
13479
13594
|
function inferParamTypeFromDefaultValue(paramValueExpr) {
|
|
13480
13595
|
const defaultValueType = getTypeOfExpression(paramValueExpr, 1 /* EvalFlags.ConvertEllipsisToAny */).type;
|
|
13481
13596
|
let inferredParamType;
|
|
13482
|
-
// Is the default value a "None" or an instance of some private
|
|
13483
|
-
// whose name starts with an underscore)? If so, we will assume
|
|
13484
|
-
// value is a singleton sentinel. The actual supported type is
|
|
13485
|
-
// a union of this type and Unknown.
|
|
13597
|
+
// Is the default value a "None", a sentinel, or an instance of some private
|
|
13598
|
+
// class (one whose name starts with an underscore)? If so, we will assume
|
|
13599
|
+
// that the value is a singleton sentinel. The actual supported type is
|
|
13600
|
+
// going to be a union of this type and Unknown.
|
|
13486
13601
|
if ((0, typeUtils_1.isNoneInstance)(defaultValueType) ||
|
|
13602
|
+
(0, typeUtils_1.isSentinelLiteral)(defaultValueType) ||
|
|
13487
13603
|
((0, types_1.isClassInstance)(defaultValueType) && (0, symbolNameUtils_1.isPrivateOrProtectedName)(defaultValueType.shared.name))) {
|
|
13488
13604
|
inferredParamType = (0, types_1.combineTypes)([defaultValueType, types_1.UnknownType.create()]);
|
|
13489
13605
|
}
|
|
@@ -13755,7 +13871,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
13755
13871
|
const inferredYieldType = (0, types_1.combineTypes)(inferredYieldTypes);
|
|
13756
13872
|
// Inferred yield types need to be wrapped in a Generator or
|
|
13757
13873
|
// AwaitableGenerator to produce the final result.
|
|
13758
|
-
const generatorType =
|
|
13874
|
+
const generatorType = useAwaitableGenerator
|
|
13875
|
+
? getTypeCheckerInternalsType(node, 'AwaitableGenerator') ??
|
|
13876
|
+
getTypingType(node, 'AwaitableGenerator')
|
|
13877
|
+
: getTypingType(node, 'Generator');
|
|
13759
13878
|
if (generatorType && (0, types_1.isInstantiableClass)(generatorType)) {
|
|
13760
13879
|
const typeArgs = [];
|
|
13761
13880
|
// The "send type" for the generator (the second type argument) is
|
|
@@ -14695,8 +14814,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
14695
14814
|
}
|
|
14696
14815
|
return undefined;
|
|
14697
14816
|
}
|
|
14698
|
-
function getCodeFlowAnalyzerForNode(
|
|
14699
|
-
let entries = codeFlowAnalyzerCache.get(
|
|
14817
|
+
function getCodeFlowAnalyzerForNode(node, typeAtStart) {
|
|
14818
|
+
let entries = codeFlowAnalyzerCache.get(node.id);
|
|
14700
14819
|
if (entries) {
|
|
14701
14820
|
const cachedEntry = entries.find((entry) => {
|
|
14702
14821
|
if (!typeAtStart || !entry.typeAtStart) {
|
|
@@ -14718,7 +14837,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
14718
14837
|
}
|
|
14719
14838
|
else {
|
|
14720
14839
|
entries = [{ typeAtStart, codeFlowAnalyzer: analyzer }];
|
|
14721
|
-
codeFlowAnalyzerCache.set(
|
|
14840
|
+
codeFlowAnalyzerCache.set(node.id, entries);
|
|
14722
14841
|
}
|
|
14723
14842
|
return analyzer;
|
|
14724
14843
|
}
|
|
@@ -14754,7 +14873,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
14754
14873
|
analyzer = getCodeFlowAnalyzerForReturnTypeInferenceContext();
|
|
14755
14874
|
}
|
|
14756
14875
|
else {
|
|
14757
|
-
analyzer = getCodeFlowAnalyzerForNode(executionNode
|
|
14876
|
+
analyzer = getCodeFlowAnalyzerForNode(executionNode, options?.typeAtStart);
|
|
14758
14877
|
}
|
|
14759
14878
|
const flowNode = AnalyzerNodeInfo.getFlowNode(startNode ?? reference);
|
|
14760
14879
|
if (flowNode === undefined) {
|
|
@@ -15744,7 +15863,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
15744
15863
|
const classTypeInfo = getTypeOfClass(classNode);
|
|
15745
15864
|
return {
|
|
15746
15865
|
type: classTypeInfo
|
|
15747
|
-
? (0, typeUtils_1.synthesizeTypeVarForSelfCls)(classTypeInfo.classType, /* isClsParam */ true)
|
|
15866
|
+
? types_1.TypeVarType.cloneAsBound((0, typeUtils_1.synthesizeTypeVarForSelfCls)(classTypeInfo.classType, /* isClsParam */ true))
|
|
15748
15867
|
: types_1.UnknownType.create(),
|
|
15749
15868
|
};
|
|
15750
15869
|
}
|
|
@@ -16164,8 +16283,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
16164
16283
|
// in the event that its inferred type is instantiable or explicitly Any
|
|
16165
16284
|
// (but not an ellipsis).
|
|
16166
16285
|
if (isLegalImplicitTypeAliasType(inferredType)) {
|
|
16167
|
-
const typeAliasTypeVar = synthesizeTypeAliasPlaceholder(resolvedDecl.typeAliasName
|
|
16168
|
-
/* isPep695Syntax */ false);
|
|
16286
|
+
const typeAliasTypeVar = synthesizeTypeAliasPlaceholder(resolvedDecl.typeAliasName);
|
|
16169
16287
|
inferredType = transformTypeForTypeAlias(inferredType, resolvedDecl.node, typeAliasTypeVar,
|
|
16170
16288
|
/* isPep695TypeVarType */ false);
|
|
16171
16289
|
isUnambiguousType = true;
|
|
@@ -16959,7 +17077,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
16959
17077
|
if (errorNode &&
|
|
16960
17078
|
selfClass &&
|
|
16961
17079
|
(0, types_1.isClass)(selfClass) &&
|
|
16962
|
-
!selfClass.priv.includeSubclasses &&
|
|
16963
17080
|
member.isInstanceMember &&
|
|
16964
17081
|
(0, types_1.isClass)(member.unspecializedClassType) &&
|
|
16965
17082
|
(flags & 1024 /* MemberAccessFlags.DisallowGenericInstanceVariableAccess */) !== 0 &&
|
|
@@ -17428,6 +17545,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
17428
17545
|
}
|
|
17429
17546
|
}
|
|
17430
17547
|
}
|
|
17548
|
+
// If the source is a class-like type created by a call to NewType, treat it
|
|
17549
|
+
// as a FunctionClass instance rather than an instantiable class for
|
|
17550
|
+
// purposes of assignability. This reflects its actual runtime type.
|
|
17551
|
+
if ((0, types_1.isInstantiableClass)(srcType) && types_1.ClassType.isNewTypeClass(srcType) && !srcType.priv.includeSubclasses) {
|
|
17552
|
+
if (prefetched?.functionClass && (0, types_1.isInstantiableClass)(prefetched?.functionClass)) {
|
|
17553
|
+
srcType = types_1.ClassType.cloneAsInstance(prefetched.functionClass);
|
|
17554
|
+
}
|
|
17555
|
+
}
|
|
17431
17556
|
if (recursionCount > types_1.maxTypeRecursionCount) {
|
|
17432
17557
|
return true;
|
|
17433
17558
|
}
|
|
@@ -17755,16 +17880,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
17755
17880
|
concreteSrcType.priv.tupleTypeArgs) {
|
|
17756
17881
|
return assignType(destType, (0, typeUtils_1.combineTupleTypeArgs)(concreteSrcType.priv.tupleTypeArgs), diag, constraints, flags, recursionCount);
|
|
17757
17882
|
}
|
|
17758
|
-
// Handle enum literals that are assignable to another (non-Enum) literal.
|
|
17759
|
-
// This can happen for IntEnum and StrEnum members.
|
|
17760
|
-
if (types_1.ClassType.isEnumClass(concreteSrcType) &&
|
|
17761
|
-
concreteSrcType.priv.literalValue instanceof types_1.EnumLiteral &&
|
|
17762
|
-
concreteSrcType.shared.mro.some((base) => (0, types_1.isClass)(base) && types_1.ClassType.isBuiltIn(base, ['int', 'str', 'bytes'])) &&
|
|
17763
|
-
(0, types_1.isClassInstance)(concreteSrcType.priv.literalValue.itemType) &&
|
|
17764
|
-
(0, typeUtils_1.isLiteralType)(concreteSrcType.priv.literalValue.itemType) &&
|
|
17765
|
-
assignType(destType, concreteSrcType.priv.literalValue.itemType)) {
|
|
17766
|
-
return true;
|
|
17767
|
-
}
|
|
17768
17883
|
if (destType.priv.literalValue !== undefined &&
|
|
17769
17884
|
types_1.ClassType.isSameGenericClass(destType, concreteSrcType)) {
|
|
17770
17885
|
const srcLiteral = concreteSrcType.priv.literalValue;
|
|
@@ -17804,9 +17919,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
17804
17919
|
if (destCallbackType) {
|
|
17805
17920
|
return assignType(destCallbackType, concreteSrcType, diag, constraints, flags, recursionCount);
|
|
17806
17921
|
}
|
|
17807
|
-
// All functions are considered instances of "
|
|
17808
|
-
|
|
17809
|
-
|
|
17922
|
+
// All functions are considered instances of "types.FunctionType" or "types.MethodType".
|
|
17923
|
+
const altClass = (0, types_1.isMethodType)(concreteSrcType) ? prefetched?.methodClass : prefetched?.functionClass;
|
|
17924
|
+
if (altClass) {
|
|
17925
|
+
return assignType(destType, (0, typeUtils_1.convertToInstance)(altClass), diag, constraints, flags, recursionCount);
|
|
17810
17926
|
}
|
|
17811
17927
|
}
|
|
17812
17928
|
else if ((0, types_1.isModule)(concreteSrcType)) {
|
|
@@ -18749,8 +18865,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
18749
18865
|
if (srcParamSpec) {
|
|
18750
18866
|
srcType = types_1.FunctionType.cloneRemoveParamSpecArgsKwargs(srcType);
|
|
18751
18867
|
}
|
|
18752
|
-
const destParamDetails = (0, parameterUtils_1.getParamListDetails)(destType
|
|
18753
|
-
|
|
18868
|
+
const destParamDetails = (0, parameterUtils_1.getParamListDetails)(destType, {
|
|
18869
|
+
disallowExtraKwargsForTd: (flags & 131072 /* AssignTypeFlags.DisallowExtraKwargsForTd */) !== 0,
|
|
18870
|
+
});
|
|
18871
|
+
const srcParamDetails = (0, parameterUtils_1.getParamListDetails)(srcType, {
|
|
18872
|
+
disallowExtraKwargsForTd: (flags & 131072 /* AssignTypeFlags.DisallowExtraKwargsForTd */) !== 0,
|
|
18873
|
+
});
|
|
18754
18874
|
adjustSourceParamDetailsForDestVariadic(isContra ? destParamDetails : srcParamDetails, isContra ? srcParamDetails : destParamDetails);
|
|
18755
18875
|
const targetIncludesParamSpec = isContra ? !!srcParamSpec : !!destParamSpec;
|
|
18756
18876
|
const destPositionalCount = destParamDetails.firstKeywordOnlyIndex ?? destParamDetails.params.length;
|
|
@@ -19132,12 +19252,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
19132
19252
|
canAssign = false;
|
|
19133
19253
|
}
|
|
19134
19254
|
}
|
|
19135
|
-
|
|
19136
|
-
|
|
19137
|
-
|
|
19138
|
-
types_1.FunctionType.isGradualCallableForm(srcType) &&
|
|
19139
|
-
|
|
19140
|
-
|
|
19255
|
+
if ((flags & 16 /* AssignTypeFlags.OverloadOverlap */) !== 0) {
|
|
19256
|
+
// If we're checking for full overlapping overloads and the source is
|
|
19257
|
+
// a gradual form, the dest must also be a gradual form.
|
|
19258
|
+
if (types_1.FunctionType.isGradualCallableForm(srcType) && !types_1.FunctionType.isGradualCallableForm(destType)) {
|
|
19259
|
+
canAssign = false;
|
|
19260
|
+
}
|
|
19261
|
+
// If the src contains a ParamSpec the dest must also.
|
|
19262
|
+
if (srcParamSpec && !destParamSpec) {
|
|
19263
|
+
canAssign = false;
|
|
19264
|
+
}
|
|
19141
19265
|
}
|
|
19142
19266
|
// If the source and the dest are using the same ParamSpec, any additional
|
|
19143
19267
|
// concatenated parameters must match.
|
|
@@ -20302,7 +20426,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
20302
20426
|
getTypeClassType,
|
|
20303
20427
|
getBuiltInObject,
|
|
20304
20428
|
getTypingType,
|
|
20305
|
-
|
|
20429
|
+
getTypeCheckerInternalsType,
|
|
20430
|
+
assignTypeArgs,
|
|
20306
20431
|
reportMissingTypeArgs,
|
|
20307
20432
|
inferReturnTypeIfNecessary,
|
|
20308
20433
|
inferVarianceForClass,
|
|
@@ -20310,7 +20435,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
20310
20435
|
isFinalVariableDeclaration,
|
|
20311
20436
|
isExplicitTypeAliasDeclaration,
|
|
20312
20437
|
addInformation,
|
|
20313
|
-
addUnusedCode,
|
|
20314
20438
|
addUnreachableCode,
|
|
20315
20439
|
addDeprecated,
|
|
20316
20440
|
addDiagnostic,
|