@zzzen/pyright-internal 1.2.0-dev.20231029 → 1.2.0-dev.20231105

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.
Files changed (151) hide show
  1. package/dist/analyzer/analyzerFileInfo.d.ts +1 -0
  2. package/dist/analyzer/analyzerFileInfo.js.map +1 -1
  3. package/dist/analyzer/checker.js +57 -50
  4. package/dist/analyzer/checker.js.map +1 -1
  5. package/dist/analyzer/codeFlowEngine.js +4 -4
  6. package/dist/analyzer/codeFlowEngine.js.map +1 -1
  7. package/dist/analyzer/codeFlowUtils.js +4 -2
  8. package/dist/analyzer/codeFlowUtils.js.map +1 -1
  9. package/dist/analyzer/constraintSolver.js +2 -3
  10. package/dist/analyzer/constraintSolver.js.map +1 -1
  11. package/dist/analyzer/constructorTransform.js +1 -1
  12. package/dist/analyzer/constructorTransform.js.map +1 -1
  13. package/dist/analyzer/constructors.js +41 -36
  14. package/dist/analyzer/constructors.js.map +1 -1
  15. package/dist/analyzer/dataClasses.js +3 -3
  16. package/dist/analyzer/dataClasses.js.map +1 -1
  17. package/dist/analyzer/enums.d.ts +2 -5
  18. package/dist/analyzer/enums.js +4 -2
  19. package/dist/analyzer/enums.js.map +1 -1
  20. package/dist/analyzer/functionTransform.js +1 -1
  21. package/dist/analyzer/functionTransform.js.map +1 -1
  22. package/dist/analyzer/importResolver.d.ts +2 -1
  23. package/dist/analyzer/importResolver.js +13 -5
  24. package/dist/analyzer/importResolver.js.map +1 -1
  25. package/dist/analyzer/namedTuples.js +3 -2
  26. package/dist/analyzer/namedTuples.js.map +1 -1
  27. package/dist/analyzer/operations.js +22 -25
  28. package/dist/analyzer/operations.js.map +1 -1
  29. package/dist/analyzer/packageTypeVerifier.js +19 -21
  30. package/dist/analyzer/packageTypeVerifier.js.map +1 -1
  31. package/dist/analyzer/patternMatching.js +5 -5
  32. package/dist/analyzer/patternMatching.js.map +1 -1
  33. package/dist/analyzer/program.d.ts +1 -1
  34. package/dist/analyzer/program.js +17 -12
  35. package/dist/analyzer/program.js.map +1 -1
  36. package/dist/analyzer/properties.js +5 -5
  37. package/dist/analyzer/properties.js.map +1 -1
  38. package/dist/analyzer/protocols.js +1 -1
  39. package/dist/analyzer/protocols.js.map +1 -1
  40. package/dist/analyzer/service.js +11 -4
  41. package/dist/analyzer/service.js.map +1 -1
  42. package/dist/analyzer/sourceFile.d.ts +1 -0
  43. package/dist/analyzer/sourceFile.js +3 -0
  44. package/dist/analyzer/sourceFile.js.map +1 -1
  45. package/dist/analyzer/tracePrinter.js +11 -13
  46. package/dist/analyzer/tracePrinter.js.map +1 -1
  47. package/dist/analyzer/typeDocStringUtils.js +3 -3
  48. package/dist/analyzer/typeDocStringUtils.js.map +1 -1
  49. package/dist/analyzer/typeEvaluator.js +748 -805
  50. package/dist/analyzer/typeEvaluator.js.map +1 -1
  51. package/dist/analyzer/typeEvaluatorTypes.d.ts +12 -25
  52. package/dist/analyzer/typeEvaluatorTypes.js +1 -36
  53. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  54. package/dist/analyzer/typeGuards.js +27 -23
  55. package/dist/analyzer/typeGuards.js.map +1 -1
  56. package/dist/analyzer/typePrinter.js +19 -18
  57. package/dist/analyzer/typePrinter.js.map +1 -1
  58. package/dist/analyzer/typeUtils.d.ts +17 -8
  59. package/dist/analyzer/typeUtils.js +146 -93
  60. package/dist/analyzer/typeUtils.js.map +1 -1
  61. package/dist/analyzer/typeVarContext.js +6 -7
  62. package/dist/analyzer/typeVarContext.js.map +1 -1
  63. package/dist/analyzer/typeWalker.d.ts +1 -2
  64. package/dist/analyzer/typeWalker.js +7 -13
  65. package/dist/analyzer/typeWalker.js.map +1 -1
  66. package/dist/analyzer/typedDicts.js +10 -10
  67. package/dist/analyzer/typedDicts.js.map +1 -1
  68. package/dist/analyzer/types.d.ts +8 -19
  69. package/dist/analyzer/types.js +44 -76
  70. package/dist/analyzer/types.js.map +1 -1
  71. package/dist/commands/dumpFileDebugInfoCommand.js +7 -9
  72. package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
  73. package/dist/common/commandLineOptions.d.ts +2 -1
  74. package/dist/common/commandLineOptions.js +1 -1
  75. package/dist/common/commandLineOptions.js.map +1 -1
  76. package/dist/common/configOptions.d.ts +1 -1
  77. package/dist/common/configOptions.js +22 -24
  78. package/dist/common/configOptions.js.map +1 -1
  79. package/dist/common/pathUtils.d.ts +1 -1
  80. package/dist/common/pathUtils.js +11 -10
  81. package/dist/common/pathUtils.js.map +1 -1
  82. package/dist/common/realFileSystem.js +4 -6
  83. package/dist/common/realFileSystem.js.map +1 -1
  84. package/dist/languageServerBase.d.ts +2 -2
  85. package/dist/languageServerBase.js +14 -14
  86. package/dist/languageServerBase.js.map +1 -1
  87. package/dist/languageService/analyzerServiceExecutor.js +1 -1
  88. package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
  89. package/dist/languageService/callHierarchyProvider.js +3 -3
  90. package/dist/languageService/callHierarchyProvider.js.map +1 -1
  91. package/dist/languageService/completionProvider.js +8 -8
  92. package/dist/languageService/completionProvider.js.map +1 -1
  93. package/dist/languageService/completionProviderUtils.js +1 -1
  94. package/dist/languageService/definitionProvider.js +1 -1
  95. package/dist/languageService/documentSymbolCollector.js +1 -1
  96. package/dist/languageService/hoverProvider.js +1 -1
  97. package/dist/languageService/signatureHelpProvider.js +0 -14
  98. package/dist/languageService/signatureHelpProvider.js.map +1 -1
  99. package/dist/languageService/tooltipUtils.js +4 -4
  100. package/dist/languageService/tooltipUtils.js.map +1 -1
  101. package/dist/localization/localize.d.ts +12 -0
  102. package/dist/localization/localize.js +4 -0
  103. package/dist/localization/localize.js.map +1 -1
  104. package/dist/localization/package.nls.cs.json +1 -1
  105. package/dist/localization/package.nls.de.json +1 -1
  106. package/dist/localization/package.nls.en-us.json +4 -0
  107. package/dist/localization/package.nls.es.json +1 -1
  108. package/dist/localization/package.nls.fr.json +1 -1
  109. package/dist/localization/package.nls.it.json +1 -1
  110. package/dist/localization/package.nls.ja.json +1 -1
  111. package/dist/localization/package.nls.ko.json +1 -1
  112. package/dist/localization/package.nls.pl.json +1 -1
  113. package/dist/localization/package.nls.pt-br.json +1 -1
  114. package/dist/localization/package.nls.ru.json +1 -1
  115. package/dist/localization/package.nls.tr.json +1 -1
  116. package/dist/localization/package.nls.zh-cn.json +1 -1
  117. package/dist/localization/package.nls.zh-tw.json +1 -1
  118. package/dist/pyright.js +3 -6
  119. package/dist/pyright.js.map +1 -1
  120. package/dist/server.d.ts +1 -0
  121. package/dist/server.js +10 -1
  122. package/dist/server.js.map +1 -1
  123. package/dist/tests/fourslash/{completions.importInterimFile.fourslash.js → completions.importInterimFile.fourslash.disabled.js} +2 -2
  124. package/dist/tests/fourslash/completions.importInterimFile.fourslash.disabled.js.map +1 -0
  125. package/dist/tests/fourslash/fourslash.d.ts +1 -1
  126. package/dist/tests/fourslash/signature.complicated.fourslash.js +6 -6
  127. package/dist/tests/fourslash/signature.complicated.fourslash.js.map +1 -1
  128. package/dist/tests/harness/fourslash/testState.d.ts +1 -1
  129. package/dist/tests/harness/fourslash/testState.js +1 -1
  130. package/dist/tests/harness/fourslash/testState.js.map +1 -1
  131. package/dist/tests/harness/vfs/filesystem.js +1 -1
  132. package/dist/tests/harness/vfs/filesystem.js.map +1 -1
  133. package/dist/tests/logger.test.js +0 -1
  134. package/dist/tests/logger.test.js.map +1 -1
  135. package/dist/tests/pathUtils.test.js +30 -1
  136. package/dist/tests/pathUtils.test.js.map +1 -1
  137. package/dist/tests/testUtils.js +2 -1
  138. package/dist/tests/testUtils.js.map +1 -1
  139. package/dist/tests/typeEvaluator1.test.js +3 -3
  140. package/dist/tests/typeEvaluator2.test.js +1 -1
  141. package/dist/tests/typeEvaluator3.test.js +7 -1
  142. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  143. package/dist/tests/typeEvaluator4.test.js +6 -2
  144. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  145. package/dist/tests/typePrinter.test.js +12 -16
  146. package/dist/tests/typePrinter.test.js.map +1 -1
  147. package/dist/tests/zipfs.test.js +2 -0
  148. package/dist/tests/zipfs.test.js.map +1 -1
  149. package/package.json +1 -1
  150. package/dist/tests/fourslash/completions.importInterimFile.fourslash.js.map +0 -1
  151. /package/dist/tests/fourslash/{completions.importInterimFile.fourslash.d.ts → completions.importInterimFile.fourslash.disabled.d.ts} +0 -0
@@ -178,6 +178,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
178
178
  let deferredClassCompletions = [];
179
179
  let cancellationToken;
180
180
  let isBasicTypesInitialized = false;
181
+ let noneClassType;
181
182
  let noneType;
182
183
  let objectType;
183
184
  let typeClassType;
@@ -374,6 +375,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
374
375
  // type of surrounding statements to be evaluated.
375
376
  function getType(node) {
376
377
  var _a, _b;
378
+ initializedBasicTypes(node);
377
379
  let type = (_a = evaluateTypeForSubnode(node, () => {
378
380
  evaluateTypesForExpressionInContext(node);
379
381
  })) === null || _a === void 0 ? void 0 : _a.type;
@@ -447,6 +449,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
447
449
  return undefined;
448
450
  }
449
451
  function initializedBasicTypes(node) {
452
+ var _a;
450
453
  if (!isBasicTypesInitialized) {
451
454
  // Some of these types have cyclical dependencies on each other,
452
455
  // so don't re-enter this block once we start executing it.
@@ -457,7 +460,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
457
460
  // Initialize and cache "Collection" to break a cyclical dependency
458
461
  // that occurs when resolving tuple below.
459
462
  getTypingType(node, 'Collection');
460
- noneType = getTypeshedType(node, 'NoneType') || types_1.AnyType.create();
463
+ noneClassType = (_a = getTypeshedType(node, 'NoneType')) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
464
+ noneType = (0, types_1.isInstantiableClass)(noneClassType)
465
+ ? types_1.ClassType.cloneAsInstance(noneClassType)
466
+ : types_1.UnknownType.create();
461
467
  tupleClassType = getBuiltInType(node, 'tuple');
462
468
  boolClassType = getBuiltInType(node, 'bool');
463
469
  intClassType = getBuiltInType(node, 'int');
@@ -1079,20 +1085,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1079
1085
  case 0 /* Unbound */:
1080
1086
  case 1 /* Unknown */:
1081
1087
  case 2 /* Any */:
1082
- case 4 /* Never */:
1083
- case 3 /* None */: {
1088
+ case 3 /* Never */: {
1084
1089
  return true;
1085
1090
  }
1086
- case 9 /* Union */: {
1091
+ case 8 /* Union */: {
1087
1092
  return (0, types_1.findSubtype)(type, (subtype) => canBeFalsy(subtype, recursionCount)) !== undefined;
1088
1093
  }
1089
- case 5 /* Function */:
1090
- case 6 /* OverloadedFunction */:
1091
- case 8 /* Module */:
1092
- case 10 /* TypeVar */: {
1094
+ case 4 /* Function */:
1095
+ case 5 /* OverloadedFunction */:
1096
+ case 7 /* Module */:
1097
+ case 9 /* TypeVar */: {
1093
1098
  return false;
1094
1099
  }
1095
- case 7 /* Class */: {
1100
+ case 6 /* Class */: {
1096
1101
  if (types_1.TypeBase.isInstantiable(type)) {
1097
1102
  return false;
1098
1103
  }
@@ -1133,7 +1138,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1133
1138
  }
1134
1139
  return true;
1135
1140
  }
1136
- return false;
1141
+ // If the class is not final, it's possible that it could be overridden
1142
+ // such that it is falsy. To be fully correct, we'd need to do the
1143
+ // following:
1144
+ // return !ClassType.isFinal(type);
1145
+ // However, pragmatically if the class is not an `object`, it's typically
1146
+ // OK to assume that it will not be overridden in this manner.
1147
+ return types_1.ClassType.isBuiltIn(type, 'object');
1137
1148
  }
1138
1149
  }
1139
1150
  }
@@ -1145,25 +1156,27 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1145
1156
  recursionCount++;
1146
1157
  switch (type.category) {
1147
1158
  case 1 /* Unknown */:
1148
- case 5 /* Function */:
1149
- case 6 /* OverloadedFunction */:
1150
- case 8 /* Module */:
1151
- case 10 /* TypeVar */:
1152
- case 4 /* Never */:
1159
+ case 4 /* Function */:
1160
+ case 5 /* OverloadedFunction */:
1161
+ case 7 /* Module */:
1162
+ case 9 /* TypeVar */:
1163
+ case 3 /* Never */:
1153
1164
  case 2 /* Any */: {
1154
1165
  return true;
1155
1166
  }
1156
- case 9 /* Union */: {
1167
+ case 8 /* Union */: {
1157
1168
  return (0, types_1.findSubtype)(type, (subtype) => canBeTruthy(subtype, recursionCount)) !== undefined;
1158
1169
  }
1159
- case 0 /* Unbound */:
1160
- case 3 /* None */: {
1170
+ case 0 /* Unbound */: {
1161
1171
  return false;
1162
1172
  }
1163
- case 7 /* Class */: {
1173
+ case 6 /* Class */: {
1164
1174
  if (types_1.TypeBase.isInstantiable(type)) {
1165
1175
  return true;
1166
1176
  }
1177
+ if ((0, typeUtils_1.isNoneInstance)(type)) {
1178
+ return false;
1179
+ }
1167
1180
  // Check for Tuple[()] (an empty tuple).
1168
1181
  if ((0, typeUtils_1.isTupleClass)(type)) {
1169
1182
  if (type.tupleTypeArguments && type.tupleTypeArguments.length === 0) {
@@ -1255,6 +1268,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1255
1268
  if (types_1.ClassType.isBuiltIn(concreteSubtype, 'bool')) {
1256
1269
  return types_1.ClassType.cloneWithLiteral(concreteSubtype, /* value */ true);
1257
1270
  }
1271
+ // If the object is a "None" instance, we can eliminate it.
1272
+ if ((0, typeUtils_1.isNoneInstance)(concreteSubtype)) {
1273
+ return undefined;
1274
+ }
1275
+ // If this is an instance of a class that cannot be subclassed,
1276
+ // we cannot say definitively that it's not falsy because a subclass
1277
+ // could override `__bool__`. For this reason, the code should not
1278
+ // remove any classes that are not final.
1279
+ // if (!ClassType.isFinal(concreteSubtype)) {
1280
+ // return subtype;
1281
+ // }
1282
+ // However, we're going to pragmatically assume that any classes
1283
+ // other than `object` will not be overridden in this manner.
1284
+ if (types_1.ClassType.isBuiltIn(concreteSubtype, 'object')) {
1285
+ return subtype;
1286
+ }
1258
1287
  }
1259
1288
  // If it's possible for the type to be truthy, include it.
1260
1289
  if (canBeTruthy(subtype)) {
@@ -1263,113 +1292,109 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1263
1292
  return undefined;
1264
1293
  });
1265
1294
  }
1266
- // Gets a member type from an object and if it's a function binds
1267
- // it to the object. If bindToClass is undefined, the binding is done
1295
+ // Gets a member type from an object or class. If it's a function, binds
1296
+ // it to the object or class. If selfType is undefined, the binding is done
1268
1297
  // using the objectType parameter. Callers can specify these separately
1269
1298
  // to handle the case where we're fetching the object member from a
1270
1299
  // metaclass but binding to the class.
1271
- function getTypeOfObjectMember(errorNode, objectType, memberName, usage = { method: 'get' }, diag = undefined, memberAccessFlags = 0 /* None */, bindToType) {
1272
- let memberInfo = getTypeOfClassMemberName(errorNode, types_1.ClassType.cloneAsInstantiable(objectType),
1273
- /* isAccessedThroughObject */ true, memberName, usage, diag, memberAccessFlags | 16 /* DisallowClassVarWrites */, bindToType);
1274
- if (!memberInfo) {
1275
- const metaclass = objectType.details.effectiveMetaclass;
1276
- if (metaclass &&
1277
- (0, types_1.isInstantiableClass)(metaclass) &&
1278
- !types_1.ClassType.isBuiltIn(metaclass, 'type') &&
1279
- !types_1.ClassType.isSameGenericClass(metaclass, objectType)) {
1280
- memberInfo = getTypeOfClassMemberName(errorNode, metaclass,
1281
- /* isAccessedThroughObject */ false, memberName, usage,
1282
- /* diag */ undefined, memberAccessFlags |
1283
- 2 /* AccessInstanceMembersOnly */ |
1284
- 128 /* SkipAttributeAccessOverride */, types_1.ClassType.cloneAsInstantiable(objectType));
1285
- }
1286
- }
1287
- if (memberInfo && !memberInfo.isSetTypeError) {
1288
- return {
1289
- type: memberInfo.type,
1290
- classType: memberInfo.classType,
1291
- isIncomplete: !!memberInfo.isTypeIncomplete,
1292
- isAsymmetricAccessor: memberInfo.isAsymmetricAccessor,
1293
- memberAccessDeprecationInfo: memberInfo.memberAccessDeprecationInfo,
1294
- };
1295
- }
1296
- return undefined;
1297
- }
1298
- // Gets a member type from a class and if it's a function binds
1299
- // it to the class.
1300
- function getTypeOfClassMember(errorNode, classType, memberName, usage = { method: 'get' }, diag = undefined, memberAccessFlags = 0 /* None */, bindToType) {
1301
- let memberInfo;
1302
- const classDiag = diag ? new diagnostic_1.DiagnosticAddendum() : undefined;
1303
- const metaclassDiag = diag ? new diagnostic_1.DiagnosticAddendum() : undefined;
1304
- let considerMetaclassOnly = (memberAccessFlags & 64 /* ConsiderMetaclassOnly */) !== 0;
1305
- if (types_1.ClassType.isPartiallyEvaluated(classType)) {
1306
- addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.classDefinitionCycle().format({ name: classType.details.name }), errorNode);
1300
+ function getTypeOfObjectMember(errorNode, objectType, memberName, usage = { method: 'get' }, diag = undefined, flags = 0 /* Default */, selfType) {
1301
+ if (types_1.ClassType.isPartiallyEvaluated(objectType)) {
1302
+ addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.classDefinitionCycle().format({ name: objectType.details.name }), errorNode);
1307
1303
  return { type: types_1.UnknownType.create() };
1308
1304
  }
1309
- const metaclass = classType.details.effectiveMetaclass;
1305
+ // Determine the class that was used to instantiate the objectType.
1306
+ // If the objectType is a class itself, then the class used to instantiate
1307
+ // it is the metaclass.
1308
+ const objectTypeIsInstantiable = types_1.TypeBase.isInstantiable(objectType);
1309
+ const metaclass = objectType.details.effectiveMetaclass;
1310
+ let memberInfo;
1311
+ // If the object type is an instantiable (i.e. it derives from "type") and
1312
+ // we've been asked not to consider instance members, don't look in the class.
1313
+ // Consider only the metaclass class variables in this case.
1314
+ let skipObjectTypeLookup = objectTypeIsInstantiable && (flags & 16 /* SkipInstanceMembers */) !== 0;
1310
1315
  // Look up the attribute in the metaclass first. If the member is a descriptor
1311
- // (an object with a __get__ method) and the access is a 'get', the Python runtime
1312
- // uses this metaclass descriptor to satisfy the lookup. Skip this costly lookup
1313
- // in the common case where the metaclass is 'type' since we know that `type` doesn't
1314
- // have any attributes that are descriptors.
1316
+ // (an object with a __get__ and __set__ method) and the access is a 'get',
1317
+ // the Python runtime uses this descriptor to satisfy the lookup. Skip this
1318
+ // costly lookup in the common case where the metaclass is 'type' since we know
1319
+ // that `type` doesn't have any attributes that are descriptors.
1315
1320
  if (usage.method === 'get' &&
1321
+ objectTypeIsInstantiable &&
1316
1322
  metaclass &&
1317
1323
  (0, types_1.isInstantiableClass)(metaclass) &&
1318
1324
  !types_1.ClassType.isBuiltIn(metaclass, 'type') &&
1319
- !types_1.ClassType.isSameGenericClass(metaclass, classType)) {
1320
- const metaclassMemberInfo = getTypeOfClassMemberName(errorNode, metaclass,
1321
- /* isAccessedThroughObject */ false, memberName, usage, metaclassDiag, memberAccessFlags | 128 /* SkipAttributeAccessOverride */, classType);
1322
- if (metaclassMemberInfo && (0, typeUtils_1.isDescriptorInstance)(metaclassMemberInfo.type)) {
1323
- considerMetaclassOnly = true;
1325
+ !types_1.ClassType.isSameGenericClass(metaclass, objectType)) {
1326
+ const descMemberInfo = getTypeOfClassMemberName(errorNode, metaclass, memberName, usage,
1327
+ /* diag */ undefined, flags | 512 /* SkipAttributeAccessOverride */, objectType);
1328
+ if (descMemberInfo) {
1329
+ const isProperty = (0, types_1.isClassInstance)(descMemberInfo.type) && types_1.ClassType.isPropertyClass(descMemberInfo.type);
1330
+ if ((0, typeUtils_1.isDescriptorInstance)(descMemberInfo.type, /* requireSetter */ true) || isProperty) {
1331
+ skipObjectTypeLookup = true;
1332
+ }
1324
1333
  }
1325
1334
  }
1326
- // Look up the attribute in the class object.
1327
- if (!memberInfo && !considerMetaclassOnly) {
1328
- memberInfo = getTypeOfClassMemberName(errorNode, classType,
1329
- /* isAccessedThroughObject */ false, memberName, usage, classDiag, memberAccessFlags | 1 /* AccessClassMembersOnly */, bindToType);
1330
- }
1331
- const isMemberPresentOnClass = (memberInfo === null || memberInfo === void 0 ? void 0 : memberInfo.classType) !== undefined;
1332
- // If it wasn't found on the class, see if it's part of the metaclass.
1333
- if (!memberInfo) {
1334
- const metaclass = classType.details.effectiveMetaclass;
1335
- if (metaclass && (0, types_1.isInstantiableClass)(metaclass) && !types_1.ClassType.isSameGenericClass(metaclass, classType)) {
1336
- memberInfo = getTypeOfClassMemberName(errorNode, metaclass,
1337
- /* isAccessedThroughObject */ true, memberName, usage, metaclassDiag, memberAccessFlags, classType);
1335
+ let subDiag;
1336
+ if (!skipObjectTypeLookup) {
1337
+ let effectiveFlags = flags;
1338
+ if (objectTypeIsInstantiable) {
1339
+ effectiveFlags |= 16 /* SkipInstanceMembers */ | 512 /* SkipAttributeAccessOverride */;
1340
+ effectiveFlags &= ~32 /* SkipClassMembers */;
1338
1341
  }
1339
- }
1340
- if (memberInfo && !memberInfo.isSetTypeError) {
1342
+ else {
1343
+ effectiveFlags |= 128 /* DisallowClassVarWrites */;
1344
+ }
1345
+ subDiag = diag ? new diagnostic_1.DiagnosticAddendum() : undefined;
1346
+ // See if the member is present in the object itself.
1347
+ memberInfo = getTypeOfClassMemberName(errorNode, objectType, memberName, usage, subDiag, effectiveFlags, selfType);
1348
+ }
1349
+ // If it wasn't found on the object, see if it's part of the metaclass.
1350
+ if (!memberInfo && metaclass && (0, types_1.isInstantiableClass)(metaclass)) {
1351
+ let effectiveFlags = flags;
1352
+ // Class members cannot be accessed on a class's metaclass through
1353
+ // an instance of a class. Limit access to metaclass instance members
1354
+ // in this case.
1355
+ if (!objectTypeIsInstantiable) {
1356
+ effectiveFlags |= 32 /* SkipClassMembers */ | 512 /* SkipAttributeAccessOverride */;
1357
+ effectiveFlags &= ~16 /* SkipInstanceMembers */;
1358
+ }
1359
+ const metaclassDiag = diag ? new diagnostic_1.DiagnosticAddendum() : undefined;
1360
+ memberInfo = getTypeOfClassMemberName(errorNode, types_1.ClassType.cloneAsInstance(metaclass), memberName, usage, metaclassDiag, effectiveFlags, objectTypeIsInstantiable ? objectType : types_1.ClassType.cloneAsInstantiable(objectType));
1361
+ // If there was a descriptor error (as opposed to an error where the members
1362
+ // was simply not found), use this diagnostic message.
1363
+ if (memberInfo === null || memberInfo === void 0 ? void 0 : memberInfo.isDescriptorError) {
1364
+ subDiag = metaclassDiag;
1365
+ }
1366
+ }
1367
+ if (memberInfo && !memberInfo.isDescriptorError) {
1341
1368
  return {
1342
1369
  type: memberInfo.type,
1370
+ classType: memberInfo.classType,
1343
1371
  isIncomplete: !!memberInfo.isTypeIncomplete,
1344
1372
  isAsymmetricAccessor: memberInfo.isAsymmetricAccessor,
1345
1373
  memberAccessDeprecationInfo: memberInfo.memberAccessDeprecationInfo,
1346
1374
  };
1347
1375
  }
1348
- // Determine whether to use the class or metaclass diagnostic addendum.
1349
- const subDiag = isMemberPresentOnClass ? classDiag : metaclassDiag;
1350
1376
  if (diag && subDiag) {
1351
1377
  diag.addAddendum(subDiag);
1352
1378
  }
1353
1379
  return undefined;
1354
1380
  }
1355
- function getBoundMethod(classType, memberName, recursionCount = 0, treatConstructorAsClassMember = false) {
1356
- const memberInfo = (0, typeUtils_1.lookUpClassMember)(classType, memberName, 8 /* SkipInstanceVariables */);
1357
- if (memberInfo) {
1358
- const unboundMethodType = getTypeOfMember(memberInfo);
1359
- if ((0, types_1.isFunction)(unboundMethodType) || (0, types_1.isOverloadedFunction)(unboundMethodType)) {
1360
- const boundMethod = bindFunctionToClassOrObject(types_1.ClassType.cloneAsInstance(classType), unboundMethodType,
1361
- /* memberClass */ undefined, treatConstructorAsClassMember,
1362
- /* firstParamType */ undefined,
1363
- /* diag */ undefined, recursionCount);
1364
- if (boundMethod) {
1365
- return boundMethod;
1366
- }
1367
- }
1368
- else if ((0, types_1.isAnyOrUnknown)(unboundMethodType)) {
1369
- const unknownFunction = types_1.FunctionType.createSynthesizedInstance('', 32768 /* SkipArgsKwargsCompatibilityCheck */);
1370
- types_1.FunctionType.addDefaultParameters(unknownFunction);
1371
- return unknownFunction;
1372
- }
1381
+ function getBoundMethod(classType, memberName, recursionCount = 0) {
1382
+ const memberInfo = (0, typeUtils_1.lookUpClassMember)(classType, memberName, 16 /* SkipInstanceMembers */);
1383
+ if (!memberInfo) {
1384
+ return undefined;
1385
+ }
1386
+ const unboundMethodType = getTypeOfMember(memberInfo);
1387
+ if ((0, types_1.isFunction)(unboundMethodType) || (0, types_1.isOverloadedFunction)(unboundMethodType)) {
1388
+ return bindFunctionToClassOrObject(types_1.ClassType.cloneAsInstance(classType), unboundMethodType,
1389
+ /* memberClass */ undefined,
1390
+ /* treatConstructorAsClassMember */ true,
1391
+ /* selfType */ undefined,
1392
+ /* diag */ undefined, recursionCount);
1393
+ }
1394
+ if ((0, types_1.isAnyOrUnknown)(unboundMethodType)) {
1395
+ const unknownFunction = types_1.FunctionType.createSynthesizedInstance('', 32768 /* SkipArgsKwargsCompatibilityCheck */);
1396
+ types_1.FunctionType.addDefaultParameters(unknownFunction);
1397
+ return unknownFunction;
1373
1398
  }
1374
1399
  return undefined;
1375
1400
  }
@@ -1379,7 +1404,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1379
1404
  function getCallSignatureInfo(callNode, activeIndex, activeOrFake) {
1380
1405
  const exprNode = callNode.leftExpression;
1381
1406
  const callType = getType(exprNode);
1382
- if (callType === undefined) {
1407
+ if (!callType) {
1383
1408
  return undefined;
1384
1409
  }
1385
1410
  const argList = [];
@@ -1424,7 +1449,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1424
1449
  /* skipUnknownArgCheck */ true);
1425
1450
  });
1426
1451
  signatures.push({
1427
- type,
1452
+ type: expandTypedKwargs(type),
1428
1453
  activeParam: callResult === null || callResult === void 0 ? void 0 : callResult.activeParam,
1429
1454
  });
1430
1455
  }
@@ -1440,12 +1465,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1440
1465
  }
1441
1466
  (0, typeUtils_1.doForEachSubtype)(callType, (subtype) => {
1442
1467
  switch (subtype.category) {
1443
- case 5 /* Function */:
1444
- case 6 /* OverloadedFunction */: {
1468
+ case 4 /* Function */:
1469
+ case 5 /* OverloadedFunction */: {
1445
1470
  addFunctionToSignature(subtype);
1446
1471
  break;
1447
1472
  }
1448
- case 7 /* Class */: {
1473
+ case 6 /* Class */: {
1449
1474
  if (types_1.TypeBase.isInstantiable(subtype)) {
1450
1475
  let methodType;
1451
1476
  // Try to get the `__init__` method first because it typically has more
@@ -1460,9 +1485,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1460
1485
  // the `object` class or accepts only default parameters(* args, ** kwargs),
1461
1486
  // see if we can find a better signature from the `__new__` method.
1462
1487
  if (!methodType || isObjectInit || isDefaultParams) {
1463
- const constructorType = getBoundMethod(subtype, '__new__',
1464
- /* recursionCount */ undefined,
1465
- /* treatConstructorAsClassMember */ true);
1488
+ const constructorType = getBoundMethod(subtype, '__new__');
1466
1489
  if (constructorType) {
1467
1490
  // Is this the __new__ method provided by the object class?
1468
1491
  const isObjectNew = (0, types_1.isFunction)(constructorType) &&
@@ -1494,6 +1517,48 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1494
1517
  signatures,
1495
1518
  };
1496
1519
  }
1520
+ // If the function includes a `**kwargs: Unpack[TypedDict]` parameter, the
1521
+ // parameter is expanded to include individual keyword args.
1522
+ function expandTypedKwargs(functionType) {
1523
+ var _a;
1524
+ const kwargsIndex = functionType.details.parameters.findIndex((param) => param.category === 2 /* KwargsDict */);
1525
+ if (kwargsIndex < 0) {
1526
+ return functionType;
1527
+ }
1528
+ (0, debug_1.assert)(kwargsIndex === functionType.details.parameters.length - 1);
1529
+ const kwargsType = types_1.FunctionType.getEffectiveParameterType(functionType, kwargsIndex);
1530
+ if (!(0, types_1.isClassInstance)(kwargsType) || !types_1.ClassType.isTypedDictClass(kwargsType) || !kwargsType.isUnpacked) {
1531
+ return functionType;
1532
+ }
1533
+ const tdEntries = (_a = kwargsType.typedDictNarrowedEntries) !== null && _a !== void 0 ? _a : kwargsType.details.typedDictEntries;
1534
+ if (!tdEntries) {
1535
+ return functionType;
1536
+ }
1537
+ const newFunction = types_1.FunctionType.clone(functionType);
1538
+ newFunction.details.parameters.splice(kwargsIndex);
1539
+ if (newFunction.specializedTypes) {
1540
+ newFunction.specializedTypes.parameterTypes.splice(kwargsIndex);
1541
+ }
1542
+ const kwSeparatorIndex = functionType.details.parameters.findIndex((param) => param.category === 1 /* ArgsList */);
1543
+ // Add a keyword separator if necessary.
1544
+ if (kwSeparatorIndex < 0) {
1545
+ types_1.FunctionType.addParameter(newFunction, {
1546
+ category: 1 /* ArgsList */,
1547
+ type: types_1.AnyType.create(),
1548
+ });
1549
+ }
1550
+ tdEntries.forEach((tdEntry, name) => {
1551
+ types_1.FunctionType.addParameter(newFunction, {
1552
+ category: 0 /* Simple */,
1553
+ name,
1554
+ hasDeclaredType: true,
1555
+ type: tdEntry.valueType,
1556
+ hasDefault: !tdEntry.isRequired,
1557
+ defaultType: tdEntry.valueType,
1558
+ });
1559
+ });
1560
+ return newFunction;
1561
+ }
1497
1562
  // Determines whether the specified expression is an explicit TypeAlias declaration.
1498
1563
  function isDeclaredTypeAlias(expression) {
1499
1564
  if (expression.nodeType === 54 /* TypeAnnotation */) {
@@ -1530,8 +1595,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1530
1595
  if (enclosingClass && enclosingClass.nodeType === 10 /* Class */) {
1531
1596
  const classTypeInfo = getTypeOfClass(enclosingClass);
1532
1597
  if (classTypeInfo) {
1533
- const classMemberInfo = (0, typeUtils_1.lookUpClassMember)(classTypeInfo.classType, expression.value, 8 /* SkipInstanceVariables */ |
1534
- 32 /* DeclaredTypesOnly */);
1598
+ const classMemberInfo = (0, typeUtils_1.lookUpClassMember)(classTypeInfo.classType, expression.value, 16 /* SkipInstanceMembers */ | 64 /* DeclaredTypesOnly */);
1535
1599
  if (classMemberInfo) {
1536
1600
  symbol = classMemberInfo.symbol;
1537
1601
  }
@@ -1548,7 +1612,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1548
1612
  const baseType = makeTopLevelTypeVarsConcrete(getTypeOfExpression(expression.leftExpression, 16777218 /* MemberAccessBaseDefaults */).type);
1549
1613
  let classMemberInfo;
1550
1614
  if ((0, types_1.isClassInstance)(baseType)) {
1551
- classMemberInfo = (0, typeUtils_1.lookUpObjectMember)(baseType, expression.memberName.value, 32 /* DeclaredTypesOnly */);
1615
+ classMemberInfo = (0, typeUtils_1.lookUpObjectMember)(baseType, expression.memberName.value, 64 /* DeclaredTypesOnly */);
1552
1616
  classOrObjectBase = baseType;
1553
1617
  memberAccessClass = classMemberInfo === null || classMemberInfo === void 0 ? void 0 : classMemberInfo.classType;
1554
1618
  // If this is an instance member (e.g. a dataclass field), don't
@@ -1559,7 +1623,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1559
1623
  useDescriptorSetterType = true;
1560
1624
  }
1561
1625
  else if ((0, types_1.isInstantiableClass)(baseType)) {
1562
- classMemberInfo = (0, typeUtils_1.lookUpClassMember)(baseType, expression.memberName.value, 8 /* SkipInstanceVariables */ | 32 /* DeclaredTypesOnly */);
1626
+ classMemberInfo = (0, typeUtils_1.lookUpClassMember)(baseType, expression.memberName.value, 16 /* SkipInstanceMembers */ | 64 /* DeclaredTypesOnly */);
1563
1627
  classOrObjectBase = baseType;
1564
1628
  memberAccessClass = classMemberInfo === null || classMemberInfo === void 0 ? void 0 : classMemberInfo.classType;
1565
1629
  }
@@ -1668,17 +1732,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1668
1732
  }
1669
1733
  // Validates that the type is an iterator and returns the iterated type
1670
1734
  // (i.e. the type returned from the '__next__' or '__anext__' method).
1671
- function getTypeOfIterator(typeResult, isAsync, errorNode) {
1735
+ function getTypeOfIterator(typeResult, isAsync, errorNode, emitNotIterableError = true) {
1672
1736
  const iterMethodName = isAsync ? '__aiter__' : '__iter__';
1673
1737
  const nextMethodName = isAsync ? '__anext__' : '__next__';
1674
1738
  let isValidIterator = true;
1675
1739
  let type = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(typeResult.type);
1676
1740
  type = makeTopLevelTypeVarsConcrete(type);
1677
1741
  if ((0, typeUtils_1.isOptionalType)(type)) {
1678
- if (errorNode && !typeResult.isIncomplete) {
1742
+ if (!typeResult.isIncomplete && emitNotIterableError) {
1679
1743
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportOptionalIterable, diagnosticRules_1.DiagnosticRule.reportOptionalIterable, localize_1.Localizer.Diagnostic.noneNotIterable(), errorNode);
1680
1744
  }
1681
- type = (0, types_1.removeNoneFromUnion)(type);
1745
+ type = (0, typeUtils_1.removeNoneFromUnion)(type);
1682
1746
  }
1683
1747
  const iterableType = (0, typeUtils_1.mapSubtypes)(type, (subtype) => {
1684
1748
  subtype = makeTopLevelTypeVarsConcrete(subtype);
@@ -1687,33 +1751,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1687
1751
  }
1688
1752
  const diag = new diagnostic_1.DiagnosticAddendum();
1689
1753
  if ((0, types_1.isClass)(subtype)) {
1690
- let iterReturnType;
1691
- if (types_1.TypeBase.isInstance(subtype)) {
1692
- // Handle an empty tuple specially.
1693
- if ((0, typeUtils_1.isTupleClass)(subtype) &&
1694
- subtype.tupleTypeArguments &&
1695
- subtype.tupleTypeArguments.length === 0) {
1696
- return types_1.NeverType.createNever();
1697
- }
1698
- iterReturnType = getSpecializedReturnType(subtype, iterMethodName, [], errorNode);
1699
- }
1700
- else if (types_1.TypeBase.isInstantiable(subtype) &&
1701
- subtype.details.effectiveMetaclass &&
1702
- (0, types_1.isInstantiableClass)(subtype.details.effectiveMetaclass)) {
1703
- iterReturnType = getSpecializedReturnType(types_1.ClassType.cloneAsInstance(subtype.details.effectiveMetaclass), iterMethodName, [], errorNode, subtype);
1704
- }
1754
+ // Handle an empty tuple specially.
1755
+ if (types_1.TypeBase.isInstance(subtype) &&
1756
+ (0, typeUtils_1.isTupleClass)(subtype) &&
1757
+ subtype.tupleTypeArguments &&
1758
+ subtype.tupleTypeArguments.length === 0) {
1759
+ return types_1.NeverType.createNever();
1760
+ }
1761
+ const iterReturnType = getTypeOfMagicMethodCall(subtype, iterMethodName, [], errorNode);
1705
1762
  if (!iterReturnType) {
1706
1763
  // There was no __iter__. See if we can fall back to
1707
1764
  // the __getitem__ method instead.
1708
1765
  if (!isAsync && (0, types_1.isClassInstance)(subtype)) {
1709
- const getItemReturnType = getSpecializedReturnType(subtype, '__getitem__', [
1766
+ const getItemReturnType = getTypeOfMagicMethodCall(subtype, '__getitem__', [
1710
1767
  {
1711
- argumentCategory: 0 /* Simple */,
1712
- typeResult: {
1713
- type: intClassType && (0, types_1.isInstantiableClass)(intClassType)
1714
- ? types_1.ClassType.cloneAsInstance(intClassType)
1715
- : types_1.UnknownType.create(),
1716
- },
1768
+ type: intClassType && (0, types_1.isInstantiableClass)(intClassType)
1769
+ ? types_1.ClassType.cloneAsInstance(intClassType)
1770
+ : types_1.UnknownType.create(),
1717
1771
  },
1718
1772
  ], errorNode);
1719
1773
  if (getItemReturnType) {
@@ -1730,7 +1784,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1730
1784
  return subtype;
1731
1785
  }
1732
1786
  if ((0, types_1.isClassInstance)(subtype)) {
1733
- let nextReturnType = getSpecializedReturnType(subtype, nextMethodName, [], errorNode);
1787
+ let nextReturnType = getTypeOfMagicMethodCall(subtype, nextMethodName, [], errorNode);
1734
1788
  if (!nextReturnType) {
1735
1789
  iterReturnTypeDiag.addMessage(localize_1.Localizer.Diagnostic.methodNotDefinedOnType().format({
1736
1790
  name: nextMethodName,
@@ -1765,7 +1819,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1765
1819
  diag.addAddendum(iterReturnTypeDiag);
1766
1820
  }
1767
1821
  }
1768
- if (errorNode && !typeResult.isIncomplete) {
1822
+ if (!typeResult.isIncomplete && emitNotIterableError) {
1769
1823
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeNotIterable().format({ type: printType(subtype) }) + diag.getString(), errorNode);
1770
1824
  }
1771
1825
  isValidIterator = false;
@@ -1774,35 +1828,27 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1774
1828
  return isValidIterator ? { type: iterableType, isIncomplete: typeResult.isIncomplete } : undefined;
1775
1829
  }
1776
1830
  // Validates that the type is an iterable and returns the iterable type argument.
1777
- function getTypeOfIterable(typeResult, isAsync, errorNode) {
1831
+ function getTypeOfIterable(typeResult, isAsync, errorNode, emitNotIterableError = true) {
1778
1832
  const iterMethodName = isAsync ? '__aiter__' : '__iter__';
1779
1833
  let isValidIterable = true;
1780
1834
  let type = makeTopLevelTypeVarsConcrete(typeResult.type);
1781
1835
  if ((0, typeUtils_1.isOptionalType)(type)) {
1782
- if (errorNode && !typeResult.isIncomplete) {
1836
+ if (!typeResult.isIncomplete && emitNotIterableError) {
1783
1837
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportOptionalIterable, diagnosticRules_1.DiagnosticRule.reportOptionalIterable, localize_1.Localizer.Diagnostic.noneNotIterable(), errorNode);
1784
1838
  }
1785
- type = (0, types_1.removeNoneFromUnion)(type);
1839
+ type = (0, typeUtils_1.removeNoneFromUnion)(type);
1786
1840
  }
1787
1841
  const iterableType = (0, typeUtils_1.mapSubtypes)(type, (subtype) => {
1788
1842
  if ((0, types_1.isAnyOrUnknown)(subtype)) {
1789
1843
  return subtype;
1790
1844
  }
1791
1845
  if ((0, types_1.isClass)(subtype)) {
1792
- let iterReturnType;
1793
- if (types_1.TypeBase.isInstance(subtype)) {
1794
- iterReturnType = getSpecializedReturnType(subtype, iterMethodName, [], errorNode);
1795
- }
1796
- else if (types_1.TypeBase.isInstantiable(subtype) &&
1797
- subtype.details.effectiveMetaclass &&
1798
- (0, types_1.isInstantiableClass)(subtype.details.effectiveMetaclass)) {
1799
- iterReturnType = getSpecializedReturnType(types_1.ClassType.cloneAsInstance(subtype.details.effectiveMetaclass), iterMethodName, [], errorNode, subtype);
1800
- }
1846
+ const iterReturnType = getTypeOfMagicMethodCall(subtype, iterMethodName, [], errorNode);
1801
1847
  if (iterReturnType) {
1802
1848
  return makeTopLevelTypeVarsConcrete(iterReturnType);
1803
1849
  }
1804
1850
  }
1805
- if (errorNode) {
1851
+ if (emitNotIterableError) {
1806
1852
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeNotIterable().format({ type: printType(subtype) }), errorNode);
1807
1853
  }
1808
1854
  isValidIterable = false;
@@ -1828,7 +1874,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1828
1874
  // Handle the case where the type is synthesized (used for
1829
1875
  // dataclasses).
1830
1876
  if (synthesizedType) {
1831
- isObjectHashable = !(0, types_1.isNoneInstance)(synthesizedType);
1877
+ isObjectHashable = !(0, typeUtils_1.isNoneInstance)(synthesizedType);
1832
1878
  }
1833
1879
  else {
1834
1880
  // Assume that if '__hash__' is declared as a variable, it is
@@ -1851,13 +1897,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1851
1897
  return isTypeHashable;
1852
1898
  }
1853
1899
  function getTypedDictClassType() {
1854
- return typedDictPrivateClassType;
1900
+ return typedDictPrivateClassType && (0, types_1.isInstantiableClass)(typedDictPrivateClassType)
1901
+ ? typedDictPrivateClassType
1902
+ : undefined;
1855
1903
  }
1856
1904
  function getTupleClassType() {
1857
- return tupleClassType;
1905
+ return tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType) ? tupleClassType : undefined;
1858
1906
  }
1859
1907
  function getObjectType() {
1860
- return objectType;
1908
+ return objectType !== null && objectType !== void 0 ? objectType : types_1.UnknownType.create();
1909
+ }
1910
+ function getNoneType() {
1911
+ return noneType !== null && noneType !== void 0 ? noneType : types_1.UnknownType.create();
1861
1912
  }
1862
1913
  function getTypingType(node, symbolName) {
1863
1914
  var _a;
@@ -2192,7 +2243,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2192
2243
  }
2193
2244
  const classTypeInfo = getTypeOfClass(classDef);
2194
2245
  if (classTypeInfo && (0, types_1.isInstantiableClass)(classTypeInfo.classType)) {
2195
- let memberInfo = (0, typeUtils_1.lookUpClassMember)(classTypeInfo.classType, memberName, isInstanceMember ? 0 /* Default */ : 8 /* SkipInstanceVariables */);
2246
+ let memberInfo = (0, typeUtils_1.lookUpClassMember)(classTypeInfo.classType, memberName, isInstanceMember ? 0 /* Default */ : 16 /* SkipInstanceMembers */);
2196
2247
  const memberFields = classTypeInfo.classType.details.fields;
2197
2248
  if (memberInfo) {
2198
2249
  // Are we accessing an existing member on this class, or is
@@ -2210,7 +2261,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2210
2261
  // Determine whether the assignment corresponds to a descriptor
2211
2262
  // that was assigned as a class variable. If so, then slots will not
2212
2263
  // apply in this case.
2213
- const classMemberDetails = (0, typeUtils_1.lookUpClassMember)(memberClass, memberName, 8 /* SkipInstanceVariables */);
2264
+ const classMemberDetails = (0, typeUtils_1.lookUpClassMember)(memberClass, memberName, 16 /* SkipInstanceMembers */);
2214
2265
  let isPotentiallyDescriptor = false;
2215
2266
  if (classMemberDetails) {
2216
2267
  const classMemberSymbolType = getEffectiveTypeOfSymbol(classMemberDetails.symbol);
@@ -2257,7 +2308,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2257
2308
  }
2258
2309
  }
2259
2310
  // Look up the member info again, now that we've potentially updated it.
2260
- memberInfo = (0, typeUtils_1.lookUpClassMember)(classTypeInfo.classType, memberName, 32 /* DeclaredTypesOnly */);
2311
+ memberInfo = (0, typeUtils_1.lookUpClassMember)(classTypeInfo.classType, memberName, 64 /* DeclaredTypesOnly */);
2261
2312
  if (!memberInfo && srcExprNode && !isTypeIncomplete) {
2262
2313
  reportPossibleUnknownAssignment(fileInfo.diagnosticRuleSet.reportUnknownMemberType, diagnosticRules_1.DiagnosticRule.reportUnknownMemberType, node.memberName, srcType, node,
2263
2314
  /* ignoreEmptyContainers */ true);
@@ -2388,6 +2439,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2388
2439
  // TypeVar, only the conditions that match the filter will be included.
2389
2440
  function makeTopLevelTypeVarsConcrete(type, makeParamSpecsConcrete = false, conditionFilter) {
2390
2441
  return (0, typeUtils_1.mapSubtypes)(type, (subtype) => {
2442
+ var _a, _b;
2391
2443
  if ((0, types_1.isParamSpec)(subtype)) {
2392
2444
  if (subtype.paramSpecAccess === 'args') {
2393
2445
  if (tupleClassType &&
@@ -2443,22 +2495,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2443
2495
  }
2444
2496
  }
2445
2497
  if ((0, types_1.isTypeVar)(subtype) && !subtype.details.recursiveTypeAliasName) {
2446
- if (subtype.details.boundType) {
2447
- const boundType = types_1.TypeBase.isInstantiable(subtype)
2448
- ? (0, typeUtils_1.convertToInstantiable)(subtype.details.boundType)
2449
- : subtype.details.boundType;
2450
- // Handle Self and type[Self] specially.
2451
- if (subtype.details.isSynthesizedSelf && (0, types_1.isClass)(boundType)) {
2452
- return types_1.ClassType.cloneIncludeSubclasses(boundType);
2453
- }
2454
- return (0, typeUtils_1.addConditionToType)(boundType, [
2455
- {
2456
- typeVarName: types_1.TypeVarType.getNameWithScope(subtype),
2457
- constraintIndex: 0,
2458
- isConstrainedTypeVar: false,
2459
- },
2460
- ]);
2461
- }
2462
2498
  // If this is a recursive type alias placeholder
2463
2499
  // that hasn't yet been resolved, return it as is.
2464
2500
  if (subtype.details.recursiveTypeAliasName) {
@@ -2494,32 +2530,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2494
2530
  if (subtype.details.isExemptFromBoundCheck) {
2495
2531
  return types_1.AnyType.create();
2496
2532
  }
2497
- // Convert to an "object" or "type" instance depending on whether
2498
- // it's instantiable.
2499
- if (types_1.TypeBase.isInstantiable(subtype)) {
2500
- if (typeClassType && (0, types_1.isInstantiableClass)(typeClassType)) {
2501
- return subtype.details.isSynthesized
2502
- ? typeClassType
2503
- : (0, typeUtils_1.addConditionToType)(types_1.ClassType.cloneAsInstance(typeClassType), [
2504
- {
2505
- typeVarName: types_1.TypeVarType.getNameWithScope(subtype),
2506
- constraintIndex: 0,
2507
- isConstrainedTypeVar: false,
2508
- },
2509
- ]);
2510
- }
2511
- }
2512
- else if (objectType) {
2513
- return subtype.details.isSynthesized
2514
- ? objectType
2515
- : (0, typeUtils_1.addConditionToType)(objectType, [
2516
- {
2517
- typeVarName: types_1.TypeVarType.getNameWithScope(subtype),
2518
- constraintIndex: 0,
2519
- isConstrainedTypeVar: false,
2520
- },
2521
- ]);
2533
+ // Fall back to a bound of "object" if no bound is provided.
2534
+ let boundType = (_b = (_a = subtype.details.boundType) !== null && _a !== void 0 ? _a : objectType) !== null && _b !== void 0 ? _b : types_1.UnknownType.create();
2535
+ boundType = types_1.TypeBase.isInstantiable(subtype) ? (0, typeUtils_1.convertToInstantiable)(boundType) : boundType;
2536
+ // Handle Self and type[Self] specially.
2537
+ if (subtype.details.isSynthesizedSelf && (0, types_1.isClass)(boundType)) {
2538
+ return types_1.ClassType.cloneIncludeSubclasses(boundType);
2522
2539
  }
2540
+ return (0, typeUtils_1.addConditionToType)(boundType, [
2541
+ {
2542
+ typeVarName: types_1.TypeVarType.getNameWithScope(subtype),
2543
+ constraintIndex: 0,
2544
+ isConstrainedTypeVar: false,
2545
+ },
2546
+ ]);
2523
2547
  return types_1.AnyType.create();
2524
2548
  }
2525
2549
  return subtype;
@@ -2531,7 +2555,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2531
2555
  // its bound type and a constrained TypeVar is expanded to its individual
2532
2556
  // constrained types). If conditionFilter is specified, conditions that
2533
2557
  // do not match will be ignored.
2534
- function mapSubtypesExpandTypeVars(type, conditionFilter, callback, recursionCount = 0) {
2558
+ function mapSubtypesExpandTypeVars(type, conditionFilter, callback, sortSubtypes = false, recursionCount = 0) {
2535
2559
  const newSubtypes = [];
2536
2560
  let typeChanged = false;
2537
2561
  function expandSubtype(unexpandedType, isLastSubtype) {
@@ -2559,10 +2583,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2559
2583
  newSubtypes.push(transformedType);
2560
2584
  }
2561
2585
  return undefined;
2562
- });
2586
+ }, sortSubtypes);
2563
2587
  }
2564
2588
  if ((0, types_1.isUnion)(type)) {
2565
- type.subtypes.forEach((subtype, index) => {
2589
+ const subtypes = sortSubtypes ? (0, typeUtils_1.sortTypes)(type.subtypes) : type.subtypes;
2590
+ subtypes.forEach((subtype, index) => {
2566
2591
  expandSubtype(subtype, index === type.subtypes.length - 1);
2567
2592
  });
2568
2593
  }
@@ -2574,7 +2599,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2574
2599
  }
2575
2600
  const newType = (0, types_1.combineTypes)(newSubtypes);
2576
2601
  // Do our best to retain type aliases.
2577
- if (newType.category === 9 /* Union */) {
2602
+ if (newType.category === 8 /* Union */) {
2578
2603
  types_1.UnionType.addTypeAliasSource(newType, type);
2579
2604
  }
2580
2605
  return newType;
@@ -2604,7 +2629,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2604
2629
  }
2605
2630
  const filteredTypeArg = mapSubtypesExpandTypeVars(typeArg, conditionFilter, (expandedSubtype) => {
2606
2631
  return expandedSubtype;
2607
- }, recursionCount);
2632
+ },
2633
+ /* sortSubtypes */ undefined, recursionCount);
2608
2634
  if (filteredTypeArg !== typeArg) {
2609
2635
  typeWasTransformed = true;
2610
2636
  }
@@ -2835,39 +2861,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2835
2861
  fileInfo.accessedSymbolSet.add(symbol.id);
2836
2862
  }
2837
2863
  }
2838
- function getSpecializedReturnType(objType, memberName, argList, errorNode, bindToClass) {
2839
- const classMember = (0, typeUtils_1.lookUpObjectMember)(objType, memberName, 8 /* SkipInstanceVariables */);
2840
- if (!classMember) {
2841
- return undefined;
2842
- }
2843
- const memberTypeResult = getTypeOfMemberInternal(classMember, objType);
2844
- if (!memberTypeResult) {
2845
- return undefined;
2846
- }
2847
- const memberType = memberTypeResult.type;
2848
- if ((0, types_1.isAnyOrUnknown)(memberType)) {
2849
- return memberType;
2850
- }
2851
- if ((0, types_1.isFunction)(memberType) || (0, types_1.isOverloadedFunction)(memberType)) {
2852
- const methodType = bindFunctionToClassOrObjectWithErrors(bindToClass || objType, memberType, classMember && (0, types_1.isInstantiableClass)(classMember.classType) ? classMember.classType : undefined, errorNode,
2853
- /* treatConstructorAsClassMember */ false,
2854
- /* firstParamType */ bindToClass);
2855
- if (methodType) {
2856
- if ((0, types_1.isOverloadedFunction)(methodType)) {
2857
- if (errorNode) {
2858
- const bestOverload = getBestOverloadForArguments(errorNode, { type: methodType, isIncomplete: memberTypeResult.isIncomplete }, argList);
2859
- if (bestOverload) {
2860
- return getFunctionEffectiveReturnType(bestOverload);
2861
- }
2862
- }
2863
- }
2864
- else {
2865
- return getFunctionEffectiveReturnType(methodType);
2866
- }
2867
- }
2868
- }
2869
- return undefined;
2870
- }
2871
2864
  function getTypeOfName(node, flags) {
2872
2865
  const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
2873
2866
  const name = node.value;
@@ -3393,6 +3386,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3393
3386
  return { type, isRescoped: false, foundInterveningClass: false };
3394
3387
  }
3395
3388
  function getTypeOfMemberAccess(node, flags) {
3389
+ var _a;
3396
3390
  // Compute flags specifically for evaluating the left expression.
3397
3391
  let leftExprFlags = 16777218 /* MemberAccessBaseDefaults */;
3398
3392
  leftExprFlags |=
@@ -3458,12 +3452,28 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3458
3452
  if (baseTypeResult.isIncomplete) {
3459
3453
  typeResult.isIncomplete = true;
3460
3454
  }
3455
+ // See if we need to log an "unknown member access" diagnostic.
3456
+ let skipPartialUnknownCheck = typeResult.isIncomplete;
3457
+ // Don't report an error if the type is a partially-specialized
3458
+ // class being passed as an argument. This comes up frequently in
3459
+ // cases where a type is passed as an argument (e.g. "defaultdict(list)").
3460
+ // It can also come up in cases like "isinstance(x, (list, dict))".
3461
+ if ((0, types_1.isInstantiableClass)(typeResult.type)) {
3462
+ const argNode = ParseTreeUtils.getParentNodeOfType(node, 1 /* Argument */);
3463
+ if (argNode && ((_a = argNode === null || argNode === void 0 ? void 0 : argNode.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 9 /* Call */) {
3464
+ skipPartialUnknownCheck = true;
3465
+ }
3466
+ }
3467
+ if (!skipPartialUnknownCheck) {
3468
+ reportPossibleUnknownAssignment(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportUnknownMemberType, diagnosticRules_1.DiagnosticRule.reportUnknownMemberType, node.memberName, typeResult.type, node,
3469
+ /* ignoreEmptyContainers */ false);
3470
+ }
3461
3471
  // Cache the type information in the member name node.
3462
3472
  writeTypeCache(node.memberName, typeResult, flags);
3463
3473
  return typeResult;
3464
3474
  }
3465
3475
  function getTypeOfMemberAccessWithBaseType(node, baseTypeResult, usage, flags) {
3466
- var _a, _b, _c;
3476
+ var _a, _b;
3467
3477
  let baseType = baseTypeResult.type;
3468
3478
  const memberName = node.memberName.value;
3469
3479
  let diag = new diagnostic_1.DiagnosticAddendum();
@@ -3486,113 +3496,90 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3486
3496
  baseType = objectType;
3487
3497
  }
3488
3498
  }
3489
- function getTypeOfNoneBase(subtype) {
3490
- if (noneType && (0, types_1.isInstantiableClass)(noneType)) {
3491
- if (types_1.TypeBase.isInstance(subtype)) {
3492
- return getTypeOfObjectMember(node.memberName, types_1.ClassType.cloneAsInstance(noneType), memberName, usage, diag);
3493
- }
3494
- else {
3495
- return getTypeOfClassMember(node.memberName, noneType, memberName, usage, diag);
3496
- }
3497
- }
3498
- return undefined;
3499
- }
3500
3499
  if ((0, types_1.isParamSpec)(baseType) && baseType.paramSpecAccess) {
3501
3500
  baseType = makeTopLevelTypeVarsConcrete(baseType);
3502
3501
  }
3503
3502
  switch (baseType.category) {
3504
3503
  case 2 /* Any */:
3505
3504
  case 1 /* Unknown */:
3506
- case 4 /* Never */: {
3505
+ case 3 /* Never */: {
3507
3506
  type = baseType;
3508
3507
  break;
3509
3508
  }
3510
- case 10 /* TypeVar */: {
3509
+ case 0 /* Unbound */: {
3510
+ break;
3511
+ }
3512
+ case 9 /* TypeVar */: {
3511
3513
  if (baseType.details.isParamSpec) {
3512
- if (memberName === 'args') {
3513
- const paramNode = ParseTreeUtils.getEnclosingParameter(node);
3514
- if (!paramNode || paramNode.category !== 1 /* ArgsList */) {
3515
- addError(localize_1.Localizer.Diagnostic.paramSpecArgsUsage(), node);
3516
- return { type: types_1.UnknownType.create(isIncomplete), isIncomplete };
3517
- }
3518
- return { type: types_1.TypeVarType.cloneForParamSpecAccess(baseType, 'args'), isIncomplete };
3519
- }
3520
- if (memberName === 'kwargs') {
3514
+ // Handle special cases for "P.args" and "P.kwargs".
3515
+ if (memberName === 'args' || memberName === 'kwargs') {
3516
+ const isArgs = memberName === 'args';
3521
3517
  const paramNode = ParseTreeUtils.getEnclosingParameter(node);
3522
- if (!paramNode || paramNode.category !== 2 /* KwargsDict */) {
3523
- addError(localize_1.Localizer.Diagnostic.paramSpecKwargsUsage(), node);
3524
- return { type: types_1.UnknownType.create(isIncomplete), isIncomplete };
3518
+ const expectedCategory = isArgs ? 1 /* ArgsList */ : 2 /* KwargsDict */;
3519
+ if (!paramNode || paramNode.category !== expectedCategory) {
3520
+ const errorMessage = isArgs
3521
+ ? localize_1.Localizer.Diagnostic.paramSpecArgsUsage()
3522
+ : localize_1.Localizer.Diagnostic.paramSpecKwargsUsage();
3523
+ addError(errorMessage, node);
3524
+ type = types_1.UnknownType.create(isIncomplete);
3525
+ break;
3525
3526
  }
3526
- return { type: types_1.TypeVarType.cloneForParamSpecAccess(baseType, 'kwargs'), isIncomplete };
3527
+ type = types_1.TypeVarType.cloneForParamSpecAccess(baseType, memberName);
3528
+ break;
3527
3529
  }
3528
3530
  if (!isIncomplete) {
3529
3531
  addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.paramSpecUnknownMember().format({ name: memberName }), node);
3530
3532
  }
3531
- return { type: types_1.UnknownType.create(isIncomplete), isIncomplete };
3533
+ type = types_1.UnknownType.create(isIncomplete);
3534
+ break;
3532
3535
  }
3536
+ // It's illegal to reference a member from a type variable.
3533
3537
  if ((flags & 256 /* ExpectingTypeAnnotation */) !== 0) {
3534
3538
  if (!isIncomplete) {
3535
- addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeVarNoMember().format({
3539
+ addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeVarNoMember().format({
3536
3540
  type: printType(baseType),
3537
3541
  name: memberName,
3538
3542
  }), node.leftExpression);
3539
3543
  }
3540
- return { type: types_1.UnknownType.create(isIncomplete), isIncomplete };
3544
+ type = types_1.UnknownType.create(isIncomplete);
3545
+ break;
3541
3546
  }
3542
3547
  if (baseType.details.recursiveTypeAliasName) {
3543
- return { type: types_1.UnknownType.create(/* isIncomplete */ true), isIncomplete: true };
3548
+ type = types_1.UnknownType.create(/* isIncomplete */ true);
3549
+ isIncomplete = true;
3550
+ break;
3544
3551
  }
3545
- if (!baseType.details.isVariadic) {
3546
- return getTypeOfMemberAccessWithBaseType(node, {
3547
- type: makeTopLevelTypeVarsConcrete(baseType),
3548
- bindToType: baseType,
3549
- isIncomplete,
3550
- }, usage, 0 /* None */);
3552
+ if (baseType.details.isVariadic) {
3553
+ break;
3551
3554
  }
3552
- break;
3555
+ return getTypeOfMemberAccessWithBaseType(node, {
3556
+ type: makeTopLevelTypeVarsConcrete(baseType),
3557
+ bindToSelfType: types_1.TypeBase.isInstantiable(baseType) ? (0, typeUtils_1.convertToInstance)(baseType) : baseType,
3558
+ isIncomplete,
3559
+ }, usage, 0 /* None */);
3553
3560
  }
3554
- case 7 /* Class */: {
3555
- if (types_1.TypeBase.isInstantiable(baseType)) {
3556
- const typeResult = getTypeOfClassMember(node.memberName, baseType, memberName, usage, diag, 0 /* None */, baseTypeResult.bindToType);
3557
- type = typeResult === null || typeResult === void 0 ? void 0 : typeResult.type;
3558
- if (typeResult === null || typeResult === void 0 ? void 0 : typeResult.isIncomplete) {
3559
- isIncomplete = true;
3560
- }
3561
- if (typeResult === null || typeResult === void 0 ? void 0 : typeResult.isAsymmetricAccessor) {
3562
- isAsymmetricAccessor = true;
3563
- }
3564
- if (typeResult === null || typeResult === void 0 ? void 0 : typeResult.memberAccessDeprecationInfo) {
3565
- memberAccessDeprecationInfo = typeResult.memberAccessDeprecationInfo;
3566
- }
3561
+ case 6 /* Class */: {
3562
+ const typeResult = (_a = (0, enums_1.getTypeOfEnumMember)(evaluatorInterface, node, baseType, memberName, isIncomplete)) !== null && _a !== void 0 ? _a : getTypeOfObjectMember(node.memberName, baseType, memberName, usage, diag,
3563
+ /* memberAccessFlags */ undefined, baseTypeResult.bindToSelfType);
3564
+ if (typeResult) {
3565
+ type = (0, typeUtils_1.addConditionToType)(typeResult.type, (0, typeUtils_1.getTypeCondition)(baseType));
3567
3566
  }
3568
- else {
3569
- // Handle the special case of 'name' and 'value' members within an enum.
3570
- const enumMemberResult = (0, enums_1.getTypeOfEnumMember)(evaluatorInterface, node, baseType, memberName, isIncomplete);
3571
- if (enumMemberResult) {
3572
- return enumMemberResult;
3573
- }
3574
- const typeResult = getTypeOfObjectMember(node.memberName, baseType, memberName, usage, diag,
3575
- /* memberAccessFlags */ undefined, baseTypeResult.bindToType);
3576
- if (typeResult) {
3577
- type = (0, typeUtils_1.addConditionToType)(typeResult.type, (0, typeUtils_1.getTypeCondition)(baseType));
3578
- }
3579
- if (typeResult === null || typeResult === void 0 ? void 0 : typeResult.isIncomplete) {
3580
- isIncomplete = true;
3581
- }
3582
- if (typeResult === null || typeResult === void 0 ? void 0 : typeResult.isAsymmetricAccessor) {
3583
- isAsymmetricAccessor = true;
3584
- }
3585
- if (typeResult === null || typeResult === void 0 ? void 0 : typeResult.memberAccessDeprecationInfo) {
3586
- memberAccessDeprecationInfo = typeResult.memberAccessDeprecationInfo;
3587
- }
3567
+ if (typeResult === null || typeResult === void 0 ? void 0 : typeResult.isIncomplete) {
3568
+ isIncomplete = true;
3569
+ }
3570
+ if (typeResult === null || typeResult === void 0 ? void 0 : typeResult.isAsymmetricAccessor) {
3571
+ isAsymmetricAccessor = true;
3572
+ }
3573
+ if (typeResult === null || typeResult === void 0 ? void 0 : typeResult.memberAccessDeprecationInfo) {
3574
+ memberAccessDeprecationInfo = typeResult.memberAccessDeprecationInfo;
3588
3575
  }
3589
3576
  break;
3590
3577
  }
3591
- case 8 /* Module */: {
3578
+ case 7 /* Module */: {
3592
3579
  const symbol = types_1.ModuleType.getField(baseType, memberName);
3593
3580
  if (symbol && !symbol.isExternallyHidden()) {
3594
3581
  if (usage.method === 'get') {
3595
- setSymbolAccessed(AnalyzerNodeInfo.getFileInfo(node), symbol, node.memberName);
3582
+ setSymbolAccessed(fileInfo, symbol, node.memberName);
3596
3583
  }
3597
3584
  type = getEffectiveTypeOfSymbolForUsage(symbol,
3598
3585
  /* usageNode */ undefined,
@@ -3608,12 +3595,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3608
3595
  type = types_1.UnknownType.create(/* isIncomplete */ true);
3609
3596
  }
3610
3597
  if (symbol.isPrivateMember()) {
3611
- addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportPrivateUsage, diagnosticRules_1.DiagnosticRule.reportPrivateUsage, localize_1.Localizer.Diagnostic.privateUsedOutsideOfModule().format({
3598
+ addDiagnostic(fileInfo.diagnosticRuleSet.reportPrivateUsage, diagnosticRules_1.DiagnosticRule.reportPrivateUsage, localize_1.Localizer.Diagnostic.privateUsedOutsideOfModule().format({
3612
3599
  name: memberName,
3613
3600
  }), node.memberName);
3614
3601
  }
3615
3602
  if (symbol.isPrivatePyTypedImport()) {
3616
- addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportPrivateImportUsage, diagnosticRules_1.DiagnosticRule.reportPrivateImportUsage, localize_1.Localizer.Diagnostic.privateImportFromPyTypedModule().format({
3603
+ addDiagnostic(fileInfo.diagnosticRuleSet.reportPrivateImportUsage, diagnosticRules_1.DiagnosticRule.reportPrivateImportUsage, localize_1.Localizer.Diagnostic.privateImportFromPyTypedModule().format({
3617
3604
  name: memberName,
3618
3605
  module: baseType.moduleName,
3619
3606
  }), node.memberName);
@@ -3656,10 +3643,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3656
3643
  }
3657
3644
  break;
3658
3645
  }
3659
- case 9 /* Union */: {
3646
+ case 8 /* Union */: {
3660
3647
  type = (0, typeUtils_1.mapSubtypes)(baseType, (subtype) => {
3661
- if ((0, types_1.isNoneInstance)(subtype)) {
3662
- const typeResult = getTypeOfNoneBase(subtype);
3648
+ if ((0, types_1.isUnbound)(subtype)) {
3649
+ // Don't do anything if it's unbound. The error will already
3650
+ // be reported elsewhere.
3651
+ return undefined;
3652
+ }
3653
+ if ((0, typeUtils_1.isNoneInstance)(subtype) && noneType && (0, types_1.isClassInstance)(noneType)) {
3654
+ const typeResult = getTypeOfObjectMember(node.memberName, noneType, memberName, usage, diag);
3663
3655
  if (typeResult) {
3664
3656
  type = (0, typeUtils_1.addConditionToType)(typeResult.type, (0, typeUtils_1.getTypeCondition)(baseType));
3665
3657
  if (typeResult.isIncomplete) {
@@ -3667,42 +3659,28 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3667
3659
  }
3668
3660
  return type;
3669
3661
  }
3670
- else {
3671
- if (!isIncomplete) {
3672
- addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportOptionalMemberAccess, diagnosticRules_1.DiagnosticRule.reportOptionalMemberAccess, localize_1.Localizer.Diagnostic.noneUnknownMember().format({ name: memberName }), node.memberName);
3673
- }
3674
- return undefined;
3662
+ if (!isIncomplete) {
3663
+ addDiagnostic(fileInfo.diagnosticRuleSet.reportOptionalMemberAccess, diagnosticRules_1.DiagnosticRule.reportOptionalMemberAccess, localize_1.Localizer.Diagnostic.noneUnknownMember().format({ name: memberName }), node.memberName);
3675
3664
  }
3676
- }
3677
- else if ((0, types_1.isUnbound)(subtype)) {
3678
- // Don't do anything if it's unbound. The error will already
3679
- // be reported elsewhere.
3680
3665
  return undefined;
3681
3666
  }
3682
- else {
3683
- const typeResult = getTypeOfMemberAccessWithBaseType(node, {
3684
- type: subtype,
3685
- isIncomplete: baseTypeResult.isIncomplete,
3686
- }, usage, 0 /* None */);
3687
- if (typeResult.isIncomplete) {
3688
- isIncomplete = true;
3689
- }
3690
- if (typeResult === null || typeResult === void 0 ? void 0 : typeResult.memberAccessDeprecationInfo) {
3691
- memberAccessDeprecationInfo = typeResult.memberAccessDeprecationInfo;
3692
- }
3693
- return typeResult.type;
3667
+ const typeResult = getTypeOfMemberAccessWithBaseType(node, {
3668
+ type: subtype,
3669
+ isIncomplete: baseTypeResult.isIncomplete,
3670
+ }, usage, 0 /* None */);
3671
+ if (typeResult.isIncomplete) {
3672
+ isIncomplete = true;
3673
+ }
3674
+ if (typeResult === null || typeResult === void 0 ? void 0 : typeResult.memberAccessDeprecationInfo) {
3675
+ memberAccessDeprecationInfo = typeResult.memberAccessDeprecationInfo;
3694
3676
  }
3677
+ return typeResult.type;
3695
3678
  });
3696
3679
  break;
3697
3680
  }
3698
- case 5 /* Function */:
3699
- case 6 /* OverloadedFunction */: {
3700
- if (memberName === '__defaults__') {
3701
- // The "__defaults__" member is not currently defined in the "function"
3702
- // class, so we'll special-case it here.
3703
- type = types_1.AnyType.create();
3704
- }
3705
- else if (memberName === '__self__') {
3681
+ case 4 /* Function */:
3682
+ case 5 /* OverloadedFunction */: {
3683
+ if (memberName === '__self__') {
3706
3684
  // The "__self__" member is not currently defined in the "function"
3707
3685
  // class, so we'll special-case it here.
3708
3686
  const functionType = (0, types_1.isFunction)(baseType) ? baseType : baseType.overloads[0];
@@ -3712,29 +3690,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3712
3690
  }
3713
3691
  }
3714
3692
  else {
3715
- if (!functionObj) {
3716
- type = types_1.AnyType.create();
3717
- }
3718
- else {
3719
- type = getTypeOfMemberAccessWithBaseType(node, { type: functionObj }, usage, flags).type;
3720
- }
3721
- }
3722
- break;
3723
- }
3724
- case 3 /* None */: {
3725
- const typeResult = getTypeOfNoneBase(baseType);
3726
- if (typeResult) {
3727
- type = (0, typeUtils_1.addConditionToType)(typeResult.type, (0, typeUtils_1.getTypeCondition)(baseType));
3728
- if (typeResult.isIncomplete) {
3729
- isIncomplete = true;
3730
- }
3693
+ type = getTypeOfMemberAccessWithBaseType(node, { type: functionObj !== null && functionObj !== void 0 ? functionObj : types_1.AnyType.create() }, usage, flags).type;
3731
3694
  }
3732
3695
  break;
3733
3696
  }
3734
3697
  default:
3735
- diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeUnsupported().format({ type: printType(baseType) }));
3736
- break;
3698
+ (0, debug_1.assertNever)(baseType);
3737
3699
  }
3700
+ // If type is undefined, emit a general error message indicating that the
3701
+ // member could not be accessed.
3738
3702
  if (!type) {
3739
3703
  const isFunctionRule = (0, types_1.isFunction)(baseType) ||
3740
3704
  (0, types_1.isOverloadedFunction)(baseType) ||
@@ -3756,7 +3720,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3756
3720
  const [ruleSet, rule] = isFunctionRule
3757
3721
  ? [fileInfo.diagnosticRuleSet.reportFunctionMemberAccess, diagnosticRules_1.DiagnosticRule.reportFunctionMemberAccess]
3758
3722
  : [fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues];
3759
- addDiagnostic(ruleSet, rule, diagMessage.format({ name: memberName, type: printType(baseType) }) + diag.getString(), node.memberName, (_a = diag.getEffectiveTextRange()) !== null && _a !== void 0 ? _a : node.memberName);
3723
+ addDiagnostic(ruleSet, rule, diagMessage.format({ name: memberName, type: printType(baseType) }) + diag.getString(), node.memberName, (_b = diag.getEffectiveTextRange()) !== null && _b !== void 0 ? _b : node.memberName);
3760
3724
  }
3761
3725
  // If this is member access on a function, use "Any" so if the
3762
3726
  // reportFunctionMemberAccess rule is disabled, we don't trigger
@@ -3766,159 +3730,133 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3766
3730
  if ((flags & 256 /* ExpectingTypeAnnotation */) === 0) {
3767
3731
  reportUseOfTypeCheckOnly(type, node.memberName);
3768
3732
  }
3769
- // Should we specialize the class?
3770
- if ((flags & 2 /* DoNotSpecialize */) === 0) {
3771
- if ((0, types_1.isInstantiableClass)(type) && !type.typeArguments) {
3772
- type = (_b = createSpecializedClassType(type, /* typeArgs */ undefined, flags, node)) === null || _b === void 0 ? void 0 : _b.type;
3773
- }
3774
- }
3775
- if (usage.method === 'get') {
3776
- let skipPartialUnknownCheck = isIncomplete;
3777
- // Don't report an error if the type is a partially-specialized
3778
- // class being passed as an argument. This comes up frequently in
3779
- // cases where a type is passed as an argument (e.g. "defaultdict(list)").
3780
- // It can also come up in cases like "isinstance(x, (list, dict))".
3781
- if ((0, types_1.isInstantiableClass)(type)) {
3782
- const argNode = ParseTreeUtils.getParentNodeOfType(node, 1 /* Argument */);
3783
- if (argNode && ((_c = argNode === null || argNode === void 0 ? void 0 : argNode.parent) === null || _c === void 0 ? void 0 : _c.nodeType) === 9 /* Call */) {
3784
- skipPartialUnknownCheck = true;
3785
- }
3786
- }
3787
- if (!skipPartialUnknownCheck) {
3788
- reportPossibleUnknownAssignment(fileInfo.diagnosticRuleSet.reportUnknownMemberType, diagnosticRules_1.DiagnosticRule.reportUnknownMemberType, node.memberName, type, node,
3789
- /* ignoreEmptyContainers */ false);
3790
- }
3791
- }
3792
3733
  return { type, isIncomplete, isAsymmetricAccessor, isRequired, isNotRequired, memberAccessDeprecationInfo };
3793
3734
  }
3794
- function getTypeOfClassMemberName(errorNode, classType, isAccessedThroughObject, memberName, usage, diag, flags, bindToType) {
3795
- var _a, _b;
3796
- let classLookupFlags = 0 /* Default */;
3797
- if (flags & 1 /* AccessClassMembersOnly */) {
3798
- classLookupFlags |= 8 /* SkipInstanceVariables */;
3799
- }
3800
- if (flags & 2 /* AccessInstanceMembersOnly */) {
3801
- classLookupFlags |= 16 /* SkipClassVariables */;
3802
- }
3803
- if (flags & 4 /* SkipBaseClasses */) {
3804
- classLookupFlags |= 2 /* SkipBaseClasses */;
3805
- }
3806
- if (flags & 8 /* SkipObjectBaseClass */) {
3807
- classLookupFlags |= 4 /* SkipObjectBaseClass */;
3808
- }
3809
- if (flags & 512 /* SkipTypeBaseClass */) {
3810
- classLookupFlags |= 64 /* SkipTypeBaseClass */;
3811
- }
3812
- if (flags & 256 /* SkipOriginalClass */) {
3813
- classLookupFlags |= 1 /* SkipOriginalClass */;
3814
- }
3735
+ function getTypeOfClassMemberName(errorNode, classType, memberName, usage, diag, flags, selfType) {
3736
+ var _a, _b, _c, _d;
3737
+ const isAccessedThroughObject = types_1.TypeBase.isInstance(classType);
3815
3738
  // Always look for a member with a declared type first.
3816
- let memberInfo = (0, typeUtils_1.lookUpClassMember)(classType, memberName, classLookupFlags | 32 /* DeclaredTypesOnly */);
3739
+ let memberInfo = (0, typeUtils_1.lookUpClassMember)(classType, memberName, flags | 64 /* DeclaredTypesOnly */);
3817
3740
  // If we couldn't find a symbol with a declared type, use
3818
3741
  // a symbol with an inferred type.
3819
3742
  if (!memberInfo) {
3820
- memberInfo = (0, typeUtils_1.lookUpClassMember)(classType, memberName, classLookupFlags);
3743
+ memberInfo = (0, typeUtils_1.lookUpClassMember)(classType, memberName, flags);
3821
3744
  }
3822
- if (memberInfo) {
3823
- let type;
3824
- let isTypeIncomplete = false;
3825
- if (memberInfo.symbol.isInitVar()) {
3826
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.memberIsInitVar().format({ name: memberName }));
3827
- return undefined;
3745
+ if (!memberInfo) {
3746
+ // No attribute of that name was found. If this is a member access
3747
+ // through an object, see if there's an attribute access override
3748
+ // method ("__getattr__", etc.).
3749
+ if ((flags & 512 /* SkipAttributeAccessOverride */) === 0) {
3750
+ const generalAttrType = applyAttributeAccessOverride(classType, errorNode, usage, memberName, selfType);
3751
+ if (generalAttrType) {
3752
+ return {
3753
+ symbol: undefined,
3754
+ type: generalAttrType.type,
3755
+ isTypeIncomplete: false,
3756
+ isDescriptorError: false,
3757
+ isClassMember: false,
3758
+ isClassVar: false,
3759
+ isAsymmetricAccessor: generalAttrType.isAsymmetricAccessor,
3760
+ };
3761
+ }
3828
3762
  }
3829
- if (usage.method !== 'get') {
3830
- // If the usage indicates a 'set' or 'delete' and the access is within the
3831
- // class definition itself, use only the declared type to avoid circular
3832
- // type evaluation.
3833
- const containingClass = ParseTreeUtils.getEnclosingClass(errorNode);
3834
- if (containingClass) {
3835
- const containingClassType = (_a = getTypeOfClass(containingClass)) === null || _a === void 0 ? void 0 : _a.classType;
3836
- if (containingClassType &&
3837
- (0, types_1.isInstantiableClass)(containingClassType) &&
3838
- types_1.ClassType.isSameGenericClass(containingClassType, classType)) {
3839
- type = (_b = getDeclaredTypeOfSymbol(memberInfo.symbol)) === null || _b === void 0 ? void 0 : _b.type;
3840
- if (type && (0, types_1.isInstantiableClass)(memberInfo.classType)) {
3841
- type = (0, typeUtils_1.partiallySpecializeType)(type, memberInfo.classType);
3842
- }
3843
- // If we're setting a class variable via a write through an object,
3844
- // this is normally considered a type violation. But it is allowed
3845
- // if the class variable is a descriptor object. In this case, we will
3846
- // clear the flag that causes an error to be generated.
3847
- if (usage.method === 'set' && memberInfo.symbol.isClassVar() && isAccessedThroughObject) {
3848
- const selfClass = bindToType || memberName === '__new__' ? undefined : classType;
3849
- const typeResult = getTypeOfMemberInternal(memberInfo, selfClass);
3850
- if (typeResult) {
3851
- if ((0, typeUtils_1.isDescriptorInstance)(typeResult.type, /* requireSetter */ true)) {
3852
- type = typeResult.type;
3853
- flags &= 16 /* DisallowClassVarWrites */;
3854
- }
3763
+ // Report that the member could not be accessed.
3764
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.memberUnknown().format({ name: memberName }));
3765
+ return undefined;
3766
+ }
3767
+ let type;
3768
+ let isTypeIncomplete = false;
3769
+ if (memberInfo.symbol.isInitVar()) {
3770
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.memberIsInitVar().format({ name: memberName }));
3771
+ return undefined;
3772
+ }
3773
+ if (usage.method !== 'get') {
3774
+ // If the usage indicates a 'set' or 'delete' and the access is within the
3775
+ // class definition itself, use only the declared type to avoid circular
3776
+ // type evaluation.
3777
+ const containingClass = ParseTreeUtils.getEnclosingClass(errorNode);
3778
+ if (containingClass) {
3779
+ const containingClassType = (_a = getTypeOfClass(containingClass)) === null || _a === void 0 ? void 0 : _a.classType;
3780
+ if (containingClassType &&
3781
+ (0, types_1.isInstantiableClass)(containingClassType) &&
3782
+ types_1.ClassType.isSameGenericClass(containingClassType, classType)) {
3783
+ type = (_b = getDeclaredTypeOfSymbol(memberInfo.symbol)) === null || _b === void 0 ? void 0 : _b.type;
3784
+ if (type && (0, types_1.isInstantiableClass)(memberInfo.classType)) {
3785
+ type = (0, typeUtils_1.partiallySpecializeType)(type, memberInfo.classType);
3786
+ }
3787
+ // If we're setting a class variable via a write through an object,
3788
+ // this is normally considered a type violation. But it is allowed
3789
+ // if the class variable is a descriptor object. In this case, we will
3790
+ // clear the flag that causes an error to be generated.
3791
+ if (usage.method === 'set' && memberInfo.symbol.isClassVar() && isAccessedThroughObject) {
3792
+ const selfClass = (selfType !== null && selfType !== void 0 ? selfType : memberName === '__new__') ? undefined : classType;
3793
+ const typeResult = getTypeOfMemberInternal(memberInfo, selfClass);
3794
+ if (typeResult) {
3795
+ if ((0, typeUtils_1.isDescriptorInstance)(typeResult.type, /* requireSetter */ true)) {
3796
+ type = typeResult.type;
3797
+ flags &= 128 /* DisallowClassVarWrites */;
3855
3798
  }
3856
3799
  }
3857
- if (!type) {
3858
- type = types_1.UnknownType.create();
3859
- }
3860
3800
  }
3861
- }
3862
- }
3863
- if (!type) {
3864
- let selfClass = classType;
3865
- // Determine whether to replace Self variables with a specific
3866
- // class. Avoid doing this if there's a "bindToType" specified
3867
- // because that case is used for super() calls where we want
3868
- // to leave the Self type generic (not specialized). We'll also
3869
- // skip this for __new__ methods because they are not bound
3870
- // to the class but rather assume the type of the cls argument.
3871
- if (bindToType) {
3872
- if ((0, types_1.isTypeVar)(bindToType) && bindToType.details.isSynthesizedSelf) {
3873
- selfClass = bindToType;
3874
- }
3875
- else {
3876
- selfClass = undefined;
3801
+ if (!type) {
3802
+ type = types_1.UnknownType.create();
3877
3803
  }
3878
3804
  }
3879
- else if (memberName === '__new__') {
3880
- selfClass = undefined;
3881
- }
3882
- const typeResult = getTypeOfMemberInternal(memberInfo, selfClass);
3883
- if (typeResult) {
3884
- type = typeResult.type;
3885
- if (typeResult.isIncomplete) {
3886
- isTypeIncomplete = true;
3887
- }
3805
+ }
3806
+ }
3807
+ if (!type) {
3808
+ let selfClass = classType;
3809
+ // Determine whether to replace Self variables with a specific
3810
+ // class. Avoid doing this if there's a "selfType" specified
3811
+ // because that case is used for super() calls where we want
3812
+ // to leave the Self type generic (not specialized). We'll also
3813
+ // skip this for __new__ methods because they are not bound
3814
+ // to the class but rather assume the type of the cls argument.
3815
+ if (selfType) {
3816
+ if ((0, types_1.isTypeVar)(selfType) && selfType.details.isSynthesizedSelf) {
3817
+ selfClass = selfType;
3888
3818
  }
3889
3819
  else {
3890
- type = types_1.UnknownType.create();
3820
+ selfClass = undefined;
3891
3821
  }
3892
3822
  }
3893
- // Don't include variables within typed dict classes.
3894
- if ((0, types_1.isClass)(memberInfo.classType) && types_1.ClassType.isTypedDictClass(memberInfo.classType)) {
3895
- const typedDecls = memberInfo.symbol.getTypedDeclarations();
3896
- if (typedDecls.length > 0 && typedDecls[0].type === 1 /* Variable */) {
3897
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.memberUnknown().format({ name: memberName }));
3898
- return undefined;
3899
- }
3823
+ else if (memberName === '__new__') {
3824
+ selfClass = undefined;
3900
3825
  }
3901
- if (usage.method === 'get') {
3902
- // Mark the member accessed if it's not coming from a parent class.
3903
- if ((0, types_1.isInstantiableClass)(memberInfo.classType) &&
3904
- types_1.ClassType.isSameGenericClass(memberInfo.classType, classType)) {
3905
- setSymbolAccessed(AnalyzerNodeInfo.getFileInfo(errorNode), memberInfo.symbol, errorNode);
3906
- }
3907
- // Special-case `__init_subclass` and `__class_getitem__` because
3908
- // these are always treated as class methods even if they're not
3909
- // decorated as such.
3910
- if (memberName === '__init_subclass__' || memberName === '__class_getitem__') {
3911
- if ((0, types_1.isFunction)(type) && !types_1.FunctionType.isClassMethod(type)) {
3912
- type = types_1.FunctionType.cloneWithNewFlags(type, type.details.flags | 2 /* ClassMethod */);
3913
- }
3914
- }
3826
+ const typeResult = getTypeOfMemberInternal(memberInfo, selfClass);
3827
+ type = (_c = typeResult === null || typeResult === void 0 ? void 0 : typeResult.type) !== null && _c !== void 0 ? _c : types_1.UnknownType.create();
3828
+ if (typeResult === null || typeResult === void 0 ? void 0 : typeResult.isIncomplete) {
3829
+ isTypeIncomplete = true;
3915
3830
  }
3916
- const descriptorResult = applyDescriptorAccessMethod(type, memberInfo, classType, bindToType, isAccessedThroughObject, flags, errorNode, memberName, usage, diag);
3917
- if (!descriptorResult) {
3831
+ }
3832
+ // Don't include variables within typed dict classes.
3833
+ if ((0, types_1.isClass)(memberInfo.classType) && types_1.ClassType.isTypedDictClass(memberInfo.classType)) {
3834
+ const typedDecls = memberInfo.symbol.getTypedDeclarations();
3835
+ if (typedDecls.length > 0 && typedDecls[0].type === 1 /* Variable */) {
3836
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.memberUnknown().format({ name: memberName }));
3918
3837
  return undefined;
3919
3838
  }
3920
- type = descriptorResult.type;
3921
- let isSetTypeError = false;
3839
+ }
3840
+ if (usage.method === 'get') {
3841
+ // Mark the member accessed if it's not coming from a parent class.
3842
+ if ((0, types_1.isInstantiableClass)(memberInfo.classType) &&
3843
+ types_1.ClassType.isSameGenericClass(memberInfo.classType, classType)) {
3844
+ setSymbolAccessed(AnalyzerNodeInfo.getFileInfo(errorNode), memberInfo.symbol, errorNode);
3845
+ }
3846
+ // Special-case `__init_subclass` and `__class_getitem__` because
3847
+ // these are always treated as class methods even if they're not
3848
+ // decorated as such.
3849
+ if (memberName === '__init_subclass__' || memberName === '__class_getitem__') {
3850
+ if ((0, types_1.isFunction)(type) && !types_1.FunctionType.isClassMethod(type)) {
3851
+ type = types_1.FunctionType.cloneWithNewFlags(type, type.details.flags | 2 /* ClassMethod */);
3852
+ }
3853
+ }
3854
+ }
3855
+ const descResult = applyDescriptorAccessMethod(type, memberInfo, classType, selfType, flags, errorNode, memberName, usage, diag);
3856
+ let isDescriptorError = true;
3857
+ if (descResult) {
3858
+ isDescriptorError = false;
3859
+ type = descResult.type;
3922
3860
  if (usage.method === 'set' && usage.setType) {
3923
3861
  // Verify that the assigned type is compatible.
3924
3862
  if (!assignType(type, usage.setType.type, diag === null || diag === void 0 ? void 0 : diag.createAddendum())) {
@@ -3929,7 +3867,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3929
3867
  classType: printObjectTypeForClass(classType),
3930
3868
  }));
3931
3869
  }
3932
- isSetTypeError = true;
3870
+ isDescriptorError = true;
3933
3871
  }
3934
3872
  if ((0, types_1.isInstantiableClass)(memberInfo.classType) &&
3935
3873
  types_1.ClassType.isFrozenDataClass(memberInfo.classType) &&
@@ -3937,47 +3875,28 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3937
3875
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.dataClassFrozen().format({
3938
3876
  name: printType(types_1.ClassType.cloneAsInstance(memberInfo.classType)),
3939
3877
  }));
3940
- isSetTypeError = true;
3878
+ isDescriptorError = true;
3941
3879
  }
3942
3880
  }
3943
- return {
3944
- symbol: memberInfo.symbol,
3945
- type,
3946
- isTypeIncomplete,
3947
- isSetTypeError,
3948
- isClassMember: !memberInfo.isInstanceMember,
3949
- isClassVar: memberInfo.isClassVar,
3950
- classType: memberInfo.classType,
3951
- isAsymmetricAccessor: descriptorResult.isAsymmetricAccessor,
3952
- memberAccessDeprecationInfo: descriptorResult === null || descriptorResult === void 0 ? void 0 : descriptorResult.memberAccessDeprecationInfo,
3953
- };
3954
3881
  }
3955
- // No attribute of that name was found. If this is a member access
3956
- // through an object, see if there's an attribute access override
3957
- // method ("__getattr__", etc.).
3958
- if ((flags & (1 /* AccessClassMembersOnly */ | 128 /* SkipAttributeAccessOverride */)) ===
3959
- 0) {
3960
- const generalAttrType = applyAttributeAccessOverride(classType, errorNode, usage, memberName);
3961
- if (generalAttrType) {
3962
- return {
3963
- symbol: undefined,
3964
- type: generalAttrType.type,
3965
- isTypeIncomplete: false,
3966
- isSetTypeError: false,
3967
- isClassMember: false,
3968
- isClassVar: false,
3969
- isAsymmetricAccessor: generalAttrType.isAsymmetricAccessor,
3970
- };
3971
- }
3972
- }
3973
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.memberUnknown().format({ name: memberName }));
3974
- return undefined;
3882
+ return {
3883
+ symbol: memberInfo.symbol,
3884
+ type,
3885
+ isTypeIncomplete,
3886
+ isDescriptorError,
3887
+ isClassMember: !memberInfo.isInstanceMember,
3888
+ isClassVar: memberInfo.isClassVar,
3889
+ classType: memberInfo.classType,
3890
+ isAsymmetricAccessor: (_d = descResult === null || descResult === void 0 ? void 0 : descResult.isAsymmetricAccessor) !== null && _d !== void 0 ? _d : false,
3891
+ memberAccessDeprecationInfo: descResult === null || descResult === void 0 ? void 0 : descResult.memberAccessDeprecationInfo,
3892
+ };
3975
3893
  }
3976
3894
  // Applies descriptor access methods "__get__", "__set__", or "__delete__"
3977
3895
  // if they apply. Also binds methods to the class/object through which it
3978
3896
  // is accessed.
3979
- function applyDescriptorAccessMethod(type, memberInfo, baseTypeClass, bindToType, isAccessedThroughObject, flags, errorNode, memberName, usage, diag) {
3980
- const treatConstructorAsClassMember = (flags & 32 /* TreatConstructorAsClassMethod */) !== 0;
3897
+ function applyDescriptorAccessMethod(type, memberInfo, classType, selfType, flags, errorNode, memberName, usage, diag) {
3898
+ const treatConstructorAsClassMember = (flags & 256 /* TreatConstructorAsClassMethod */) !== 0;
3899
+ const isAccessedThroughObject = types_1.TypeBase.isInstance(classType);
3981
3900
  let isTypeValid = true;
3982
3901
  let isAsymmetricAccessor = false;
3983
3902
  let memberAccessDeprecationInfo;
@@ -4019,7 +3938,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4019
3938
  else {
4020
3939
  accessMethodName = '__delete__';
4021
3940
  }
4022
- const accessMethod = (0, typeUtils_1.lookUpClassMember)(lookupClass, accessMethodName, 8 /* SkipInstanceVariables */);
3941
+ const accessMethod = (0, typeUtils_1.lookUpClassMember)(lookupClass, accessMethodName, 16 /* SkipInstanceMembers */);
4023
3942
  // Handle properties specially.
4024
3943
  if (types_1.ClassType.isPropertyClass(lookupClass)) {
4025
3944
  if (usage.method === 'set') {
@@ -4049,10 +3968,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4049
3968
  argumentCategory: 0 /* Simple */,
4050
3969
  typeResult: {
4051
3970
  type: types_1.ClassType.isClassProperty(lookupClass)
4052
- ? baseTypeClass
3971
+ ? classType
4053
3972
  : isAccessedThroughObject
4054
- ? bindToType !== null && bindToType !== void 0 ? bindToType : types_1.ClassType.cloneAsInstance(baseTypeClass)
4055
- : types_1.NoneType.createInstance(),
3973
+ ? selfType !== null && selfType !== void 0 ? selfType : types_1.ClassType.cloneAsInstance(classType)
3974
+ : getNoneType(),
4056
3975
  },
4057
3976
  },
4058
3977
  ];
@@ -4061,7 +3980,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4061
3980
  argList.push({
4062
3981
  argumentCategory: 0 /* Simple */,
4063
3982
  typeResult: {
4064
- type: baseTypeClass,
3983
+ type: isAccessedThroughObject
3984
+ ? types_1.ClassType.cloneAsInstantiable(classType)
3985
+ : classType,
4065
3986
  },
4066
3987
  });
4067
3988
  }
@@ -4090,8 +4011,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4090
4011
  // flag this as an error because a property within a protocol is meant to be
4091
4012
  // interpreted as a read-only attribute rather than a protocol, so accessing
4092
4013
  // it directly from the class has an ambiguous meaning.
4093
- if ((flags & 1 /* AccessClassMembersOnly */) !== 0 &&
4094
- types_1.ClassType.isProtocolClass(baseTypeClass)) {
4014
+ if ((flags & 16 /* SkipInstanceMembers */) !== 0 &&
4015
+ types_1.ClassType.isProtocolClass(classType)) {
4095
4016
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.propertyAccessFromProtocolClass());
4096
4017
  isTypeValid = false;
4097
4018
  }
@@ -4110,12 +4031,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4110
4031
  // because of the way we model the __get__ logic in the property class.
4111
4032
  if (types_1.ClassType.isPropertyClass(concreteSubtype) && !isAccessedThroughMetaclass) {
4112
4033
  if (memberInfo && (0, types_1.isInstantiableClass)(memberInfo.classType)) {
4113
- bindToClass = memberInfo.classType;
4114
- }
4115
- }
4116
- else {
4117
- if ((0, types_1.isInstantiableClass)(accessMethod.classType)) {
4118
- bindToClass = accessMethod.classType;
4034
+ bindToClass = types_1.ClassType.cloneAsInstance(memberInfo.classType);
4119
4035
  }
4120
4036
  }
4121
4037
  let boundMethodType = bindFunctionToClassOrObjectWithErrors(lookupClass, methodType, bindToClass, errorNode,
@@ -4127,7 +4043,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4127
4043
  ((0, types_1.isFunction)(boundMethodType) || (0, types_1.isOverloadedFunction)(boundMethodType))) {
4128
4044
  const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(boundMethodType));
4129
4045
  if (bindToClass) {
4130
- const specializedBoundType = (0, typeUtils_1.partiallySpecializeType)(boundMethodType, bindToClass, baseTypeClass);
4046
+ const specializedBoundType = (0, typeUtils_1.partiallySpecializeType)(boundMethodType, bindToClass, classType);
4131
4047
  if (specializedBoundType) {
4132
4048
  if ((0, types_1.isFunction)(specializedBoundType) ||
4133
4049
  (0, types_1.isOverloadedFunction)(specializedBoundType)) {
@@ -4166,6 +4082,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4166
4082
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.Diagnostic.noOverload().format({ name: accessMethodName }));
4167
4083
  }
4168
4084
  }
4085
+ else {
4086
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.descriptorAccessCallFailed().format({
4087
+ name: accessMethodName,
4088
+ className: printType((0, typeUtils_1.convertToInstance)(accessMethod.classType)),
4089
+ }));
4090
+ }
4169
4091
  isTypeValid = false;
4170
4092
  return types_1.AnyType.create();
4171
4093
  }
@@ -4174,6 +4096,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4174
4096
  ? (_a = callResult.returnType) !== null && _a !== void 0 ? _a : types_1.UnknownType.create()
4175
4097
  : types_1.AnyType.create();
4176
4098
  }
4099
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.descriptorAccessBindingFailed().format({
4100
+ name: accessMethodName,
4101
+ className: printType((0, typeUtils_1.convertToInstance)(accessMethod.classType)),
4102
+ }));
4103
+ isTypeValid = false;
4177
4104
  return undefined;
4178
4105
  });
4179
4106
  // Determine if we're calling __set__ on an asymmetric descriptor or property.
@@ -4214,29 +4141,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4214
4141
  // If this function is an instance member (e.g. a lambda that was
4215
4142
  // assigned to an instance variable), don't perform any binding.
4216
4143
  if (!isAccessedThroughObject || (memberInfo && !memberInfo.isInstanceMember)) {
4217
- let effectiveBindToType = bindToType;
4218
- if (bindToType && !(0, typeUtils_1.isInstantiableMetaclass)(baseTypeClass)) {
4219
- // If bindToType is an instantiable class or TypeVar but we're targeting
4220
- // an instance method (in a non-metaclass), we need to convert
4221
- // the bindToType to an instance.
4222
- const targetMethod = (0, types_1.isFunction)(concreteSubtype)
4223
- ? concreteSubtype
4224
- : concreteSubtype.overloads[0];
4225
- if (types_1.FunctionType.isInstanceMethod(targetMethod) && !types_1.TypeBase.isInstance(bindToType)) {
4226
- effectiveBindToType = (0, typeUtils_1.convertToInstance)(bindToType);
4227
- }
4228
- }
4229
- // If the bind-to type is a specific class, add the "includeSubclasses" flag
4230
- // to the type to indicate that it could be a subclass.
4231
- if (effectiveBindToType && (0, types_1.isClass)(effectiveBindToType)) {
4232
- effectiveBindToType = types_1.ClassType.cloneIncludeSubclasses(effectiveBindToType);
4233
- }
4234
- return bindFunctionToClassOrObjectWithErrors(isAccessedThroughObject ? types_1.ClassType.cloneAsInstance(baseTypeClass) : baseTypeClass, concreteSubtype, memberInfo && (0, types_1.isInstantiableClass)(memberInfo.classType) ? memberInfo.classType : undefined, errorNode, treatConstructorAsClassMember, effectiveBindToType);
4144
+ return bindFunctionToClassOrObjectWithErrors(classType, concreteSubtype, memberInfo && (0, types_1.isInstantiableClass)(memberInfo.classType) ? memberInfo.classType : undefined, errorNode, treatConstructorAsClassMember, selfType && (0, types_1.isClass)(selfType) ? types_1.ClassType.cloneIncludeSubclasses(selfType) : selfType);
4235
4145
  }
4236
4146
  }
4237
4147
  if (usage.method === 'set') {
4238
4148
  if (memberInfo === null || memberInfo === void 0 ? void 0 : memberInfo.symbol.isClassVar()) {
4239
- if (flags & 16 /* DisallowClassVarWrites */) {
4149
+ if (flags & 128 /* DisallowClassVarWrites */) {
4240
4150
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.memberSetClassVar().format({ name: memberName }));
4241
4151
  isTypeValid = false;
4242
4152
  return undefined;
@@ -4366,14 +4276,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4366
4276
  return isAsymmetric;
4367
4277
  }
4368
4278
  // Applies the __getattr__, __setattr__ or __delattr__ method if present.
4369
- function applyAttributeAccessOverride(classType, errorNode, usage, memberName) {
4279
+ function applyAttributeAccessOverride(classType, errorNode, usage, memberName, selfType) {
4370
4280
  var _a, _b, _c, _d, _e;
4371
4281
  const getAttributeAccessMember = (name) => {
4372
4282
  var _a;
4373
- // See if the class has a "__getattribute__" or "__getattr__" method.
4374
- // If so, arbitrary members are supported.
4375
- return (_a = getTypeOfClassMember(errorNode, classType, name, { method: 'get' },
4376
- /* diag */ undefined, 8 /* SkipObjectBaseClass */ | 128 /* SkipAttributeAccessOverride */)) === null || _a === void 0 ? void 0 : _a.type;
4283
+ return (_a = getTypeOfObjectMember(errorNode, classType, name, { method: 'get' },
4284
+ /* diag */ undefined, 16 /* SkipInstanceMembers */ |
4285
+ 4 /* SkipObjectBaseClass */ |
4286
+ 512 /* SkipAttributeAccessOverride */, selfType)) === null || _a === void 0 ? void 0 : _a.type;
4377
4287
  };
4378
4288
  let accessMemberType;
4379
4289
  if (usage.method === 'get') {
@@ -4386,51 +4296,47 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4386
4296
  (0, debug_1.assert)(usage.method === 'del');
4387
4297
  accessMemberType = getAttributeAccessMember('__delattr__');
4388
4298
  }
4389
- if (accessMemberType) {
4390
- let nameLiteralType = types_1.AnyType.create();
4391
- if (strClassType && (0, types_1.isInstantiableClass)(strClassType)) {
4392
- nameLiteralType = types_1.ClassType.cloneWithLiteral(types_1.ClassType.cloneAsInstance(strClassType), memberName);
4393
- }
4394
- const argList = [
4395
- {
4396
- // Provide "self" argument.
4397
- argumentCategory: 0 /* Simple */,
4398
- typeResult: { type: types_1.ClassType.cloneAsInstance(classType) },
4399
- },
4400
- {
4401
- // Provide "name" argument.
4402
- argumentCategory: 0 /* Simple */,
4403
- typeResult: { type: nameLiteralType },
4299
+ if (!accessMemberType) {
4300
+ return undefined;
4301
+ }
4302
+ let nameLiteralType = types_1.AnyType.create();
4303
+ if (strClassType && (0, types_1.isInstantiableClass)(strClassType)) {
4304
+ nameLiteralType = types_1.ClassType.cloneWithLiteral(types_1.ClassType.cloneAsInstance(strClassType), memberName);
4305
+ }
4306
+ const argList = [
4307
+ {
4308
+ // Provide "name" argument.
4309
+ argumentCategory: 0 /* Simple */,
4310
+ typeResult: { type: nameLiteralType },
4311
+ },
4312
+ ];
4313
+ if (usage.method === 'set') {
4314
+ argList.push({
4315
+ // Provide "value" argument.
4316
+ argumentCategory: 0 /* Simple */,
4317
+ typeResult: {
4318
+ type: (_c = (_b = usage.setType) === null || _b === void 0 ? void 0 : _b.type) !== null && _c !== void 0 ? _c : types_1.UnknownType.create(),
4319
+ isIncomplete: !!((_d = usage.setType) === null || _d === void 0 ? void 0 : _d.isIncomplete),
4404
4320
  },
4405
- ];
4406
- if (usage.method === 'set') {
4407
- argList.push({
4408
- // Provide "value" argument.
4409
- argumentCategory: 0 /* Simple */,
4410
- typeResult: {
4411
- type: (_c = (_b = usage.setType) === null || _b === void 0 ? void 0 : _b.type) !== null && _c !== void 0 ? _c : types_1.UnknownType.create(),
4412
- isIncomplete: !!((_d = usage.setType) === null || _d === void 0 ? void 0 : _d.isIncomplete),
4413
- },
4414
- });
4415
- }
4416
- if ((0, types_1.isFunction)(accessMemberType) || (0, types_1.isOverloadedFunction)(accessMemberType)) {
4417
- const boundMethodType = bindFunctionToClassOrObjectWithErrors(classType, accessMemberType, classType, errorNode);
4418
- if (boundMethodType && ((0, types_1.isFunction)(boundMethodType) || (0, types_1.isOverloadedFunction)(boundMethodType))) {
4419
- const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(boundMethodType));
4420
- const callResult = validateCallArguments(errorNode, argList, { type: boundMethodType }, typeVarContext,
4421
- /* skipUnknownArgCheck */ true);
4422
- let isAsymmetricAccessor = false;
4423
- if (usage.method === 'set') {
4424
- isAsymmetricAccessor = isClassWithAsymmetricAttributeAccessor(classType);
4425
- }
4426
- return {
4427
- type: (_e = callResult.returnType) !== null && _e !== void 0 ? _e : types_1.UnknownType.create(),
4428
- isAsymmetricAccessor,
4429
- };
4430
- }
4431
- }
4321
+ });
4432
4322
  }
4433
- return undefined;
4323
+ if (!(0, types_1.isFunction)(accessMemberType) && !(0, types_1.isOverloadedFunction)(accessMemberType)) {
4324
+ // TODO - need to handle and report this error.
4325
+ return undefined;
4326
+ }
4327
+ const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(accessMemberType));
4328
+ const callResult = validateCallArguments(errorNode, argList, { type: accessMemberType }, typeVarContext,
4329
+ /* skipUnknownArgCheck */ true);
4330
+ // TODO - need to handle and report errors when validating call to
4331
+ // attribute access method.
4332
+ let isAsymmetricAccessor = false;
4333
+ if (usage.method === 'set') {
4334
+ isAsymmetricAccessor = isClassWithAsymmetricAttributeAccessor(classType);
4335
+ }
4336
+ return {
4337
+ type: (_e = callResult.returnType) !== null && _e !== void 0 ? _e : types_1.UnknownType.create(),
4338
+ isAsymmetricAccessor,
4339
+ };
4434
4340
  }
4435
4341
  function getTypeOfIndex(node, flags = 0 /* None */) {
4436
4342
  const baseTypeResult = getTypeOfExpression(node.baseExpression, flags | 2 /* IndexBaseDefaults */);
@@ -4786,9 +4692,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4786
4692
  (0, types_1.isInstantiableClass)(concreteSubtype.details.effectiveMetaclass) &&
4787
4693
  !types_1.ClassType.isBuiltIn(concreteSubtype.details.effectiveMetaclass, ['type', '_InitVarMeta']) &&
4788
4694
  (flags & 128 /* ExpectingInstantiableType */) === 0) {
4789
- const itemMethodType = getTypeOfClassMember(node, concreteSubtype, getIndexAccessMagicMethodName(usage),
4695
+ const itemMethodType = getTypeOfObjectMember(node, concreteSubtype, getIndexAccessMagicMethodName(usage),
4790
4696
  /* usage */ undefined,
4791
- /* diag */ undefined, 128 /* SkipAttributeAccessOverride */ | 64 /* ConsiderMetaclassOnly */);
4697
+ /* diag */ undefined, 512 /* SkipAttributeAccessOverride */);
4792
4698
  if ((flags & 256 /* ExpectingTypeAnnotation */) !== 0) {
4793
4699
  // If the class doesn't derive from Generic, a type argument should not be allowed.
4794
4700
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeArgsExpectingNone().format({
@@ -4876,6 +4782,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4876
4782
  }
4877
4783
  return result.type;
4878
4784
  }
4785
+ if ((0, typeUtils_1.isNoneInstance)(concreteSubtype)) {
4786
+ if (!isIncomplete) {
4787
+ addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportOptionalSubscript, diagnosticRules_1.DiagnosticRule.reportOptionalSubscript, localize_1.Localizer.Diagnostic.noneNotSubscriptable(), node.baseExpression);
4788
+ }
4789
+ return types_1.UnknownType.create();
4790
+ }
4879
4791
  if ((0, types_1.isClassInstance)(concreteSubtype)) {
4880
4792
  const typeResult = getTypeOfIndexedObjectOrClass(node, concreteSubtype, usage);
4881
4793
  if (typeResult.isIncomplete) {
@@ -4886,10 +4798,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4886
4798
  if ((0, types_1.isNever)(concreteSubtype) || (0, types_1.isUnbound)(concreteSubtype)) {
4887
4799
  return types_1.NeverType.createNever();
4888
4800
  }
4889
- if ((0, types_1.isNoneInstance)(concreteSubtype) && !isIncomplete) {
4890
- addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportOptionalSubscript, diagnosticRules_1.DiagnosticRule.reportOptionalSubscript, localize_1.Localizer.Diagnostic.noneNotSubscriptable(), node.baseExpression);
4891
- return types_1.UnknownType.create();
4892
- }
4893
4801
  if (!isIncomplete) {
4894
4802
  const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
4895
4803
  addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeNotSubscriptable().format({ type: printType(concreteSubtype) }), node.baseExpression);
@@ -4952,7 +4860,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4952
4860
  });
4953
4861
  }
4954
4862
  (0, typeUtils_1.doForEachSubtype)(type, (subtype) => {
4955
- if (subtype.category === 5 /* Function */) {
4863
+ if (subtype.category === 4 /* Function */) {
4956
4864
  if (subtype.specializedTypes) {
4957
4865
  subtype.specializedTypes.parameterTypes.forEach((paramType) => {
4958
4866
  updateUsageVarianceForType(paramType, 4 /* Contravariant */);
@@ -4963,7 +4871,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4963
4871
  }
4964
4872
  }
4965
4873
  }
4966
- else if (subtype.category === 7 /* Class */) {
4874
+ else if (subtype.category === 6 /* Class */) {
4967
4875
  if (subtype.typeArguments) {
4968
4876
  // If the class includes type parameters that uses auto variance,
4969
4877
  // compute the calculated variance.
@@ -5012,7 +4920,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5012
4920
  }
5013
4921
  }
5014
4922
  function getTypeOfIndexedObjectOrClass(node, baseType, usage) {
5015
- var _a, _b, _c, _d, _e, _f;
4923
+ var _a, _b, _c, _d, _e;
5016
4924
  // Handle index operations for TypedDict classes specially.
5017
4925
  if ((0, types_1.isClassInstance)(baseType) && types_1.ClassType.isTypedDictClass(baseType)) {
5018
4926
  const typeFromTypedDict = (0, typedDicts_1.getTypeOfIndexedTypedDict)(evaluatorInterface, node, baseType, usage);
@@ -5021,13 +4929,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5021
4929
  }
5022
4930
  }
5023
4931
  const magicMethodName = getIndexAccessMagicMethodName(usage);
5024
- const itemMethodType = (0, types_1.isClassInstance)(baseType)
5025
- ? (_a = getTypeOfObjectMember(node, baseType, magicMethodName,
5026
- /* usage */ undefined,
5027
- /* diag */ undefined, 128 /* SkipAttributeAccessOverride */)) === null || _a === void 0 ? void 0 : _a.type
5028
- : (_b = getTypeOfClassMember(node, baseType, magicMethodName,
5029
- /* usage */ undefined,
5030
- /* diag */ undefined, 128 /* SkipAttributeAccessOverride */ | 64 /* ConsiderMetaclassOnly */)) === null || _b === void 0 ? void 0 : _b.type;
4932
+ const itemMethodType = (_a = getTypeOfObjectMember(node, baseType, magicMethodName,
4933
+ /* usage */ undefined,
4934
+ /* diag */ undefined, 512 /* SkipAttributeAccessOverride */)) === null || _a === void 0 ? void 0 : _a.type;
5031
4935
  if (!itemMethodType) {
5032
4936
  const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
5033
4937
  addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.methodNotDefinedOnType().format({
@@ -5156,7 +5060,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5156
5060
  },
5157
5061
  ];
5158
5062
  if (usage.method === 'set') {
5159
- let setType = (_d = (_c = usage.setType) === null || _c === void 0 ? void 0 : _c.type) !== null && _d !== void 0 ? _d : types_1.AnyType.create();
5063
+ let setType = (_c = (_b = usage.setType) === null || _b === void 0 ? void 0 : _b.type) !== null && _c !== void 0 ? _c : types_1.AnyType.create();
5160
5064
  // Expand constrained type variables.
5161
5065
  if ((0, types_1.isTypeVar)(setType) && setType.details.constraints.length > 0) {
5162
5066
  const conditionFilter = (0, types_1.isClassInstance)(baseType) ? baseType.condition : undefined;
@@ -5167,7 +5071,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5167
5071
  argumentCategory: 0 /* Simple */,
5168
5072
  typeResult: {
5169
5073
  type: setType,
5170
- isIncomplete: !!((_e = usage.setType) === null || _e === void 0 ? void 0 : _e.isIncomplete),
5074
+ isIncomplete: !!((_d = usage.setType) === null || _d === void 0 ? void 0 : _d.isIncomplete),
5171
5075
  },
5172
5076
  });
5173
5077
  }
@@ -5217,7 +5121,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5217
5121
  }
5218
5122
  callResult = validateCallArguments(node, argList, { type: itemMethodType });
5219
5123
  return {
5220
- type: (_f = callResult.returnType) !== null && _f !== void 0 ? _f : types_1.UnknownType.create(),
5124
+ type: (_e = callResult.returnType) !== null && _e !== void 0 ? _e : types_1.UnknownType.create(),
5221
5125
  isIncomplete: !!callResult.isTypeIncomplete,
5222
5126
  };
5223
5127
  }
@@ -5807,7 +5711,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5807
5711
  else {
5808
5712
  addInformation(localize_1.Localizer.Diagnostic.revealLocalsNone(), node);
5809
5713
  }
5810
- return types_1.NoneType.createInstance();
5714
+ return getNoneType();
5811
5715
  }
5812
5716
  function getTypeOfSuperCall(node) {
5813
5717
  var _a;
@@ -5832,6 +5736,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5832
5736
  else {
5833
5737
  if (enclosingClassType) {
5834
5738
  targetClassType = enclosingClassType !== null && enclosingClassType !== void 0 ? enclosingClassType : types_1.UnknownType.create();
5739
+ // Zero-argument forms of super are not allowed within static methods.
5740
+ // This results in a runtime exception.
5741
+ if (enclosingFunction) {
5742
+ const functionInfo = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, enclosingFunction,
5743
+ /* isInClass */ true);
5744
+ if (((functionInfo === null || functionInfo === void 0 ? void 0 : functionInfo.flags) & 4 /* StaticMethod */) !== 0) {
5745
+ addError(localize_1.Localizer.Diagnostic.superCallZeroArgFormStaticMethod(), node.leftExpression);
5746
+ targetClassType = types_1.UnknownType.create();
5747
+ }
5748
+ }
5835
5749
  }
5836
5750
  else {
5837
5751
  addError(localize_1.Localizer.Diagnostic.superCallZeroArgForm(), node.leftExpression);
@@ -5927,8 +5841,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5927
5841
  type: resultIsInstance
5928
5842
  ? types_1.ClassType.cloneAsInstance(lookupResults.classType)
5929
5843
  : lookupResults.classType,
5930
- bindToType: bindToType
5931
- ? types_1.TypeBase.cloneForCondition((0, typeUtils_1.synthesizeTypeVarForSelfCls)(bindToType, !resultIsInstance), bindToType.condition)
5844
+ bindToSelfType: bindToType
5845
+ ? types_1.TypeBase.cloneForCondition((0, typeUtils_1.synthesizeTypeVarForSelfCls)(bindToType, /* isClsParam */ false), bindToType.condition)
5932
5846
  : undefined,
5933
5847
  };
5934
5848
  }
@@ -6418,7 +6332,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6418
6332
  }, {
6419
6333
  allowDiagnostics: true,
6420
6334
  });
6421
- });
6335
+ },
6336
+ /* sortSubtypes */ true);
6422
6337
  // If we ended up with a "Never" type because all code paths returned
6423
6338
  // undefined due to argument errors, transform the result into an Unknown
6424
6339
  // to avoid subsequent false positives.
@@ -6435,7 +6350,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6435
6350
  }
6436
6351
  function validateCallArgumentsForSubtype(errorNode, argList, expandedCallType, unexpandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount) {
6437
6352
  switch (expandedCallType.category) {
6438
- case 4 /* Never */:
6353
+ case 3 /* Never */:
6439
6354
  case 1 /* Unknown */:
6440
6355
  case 2 /* Any */: {
6441
6356
  // Touch all of the args so they're marked accessed. Don't bother
@@ -6450,37 +6365,30 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6450
6365
  }
6451
6366
  return { returnType: expandedCallType };
6452
6367
  }
6453
- case 5 /* Function */: {
6368
+ case 4 /* Function */: {
6454
6369
  return validateCallForFunction(errorNode, argList, expandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext);
6455
6370
  }
6456
- case 6 /* OverloadedFunction */: {
6371
+ case 5 /* OverloadedFunction */: {
6457
6372
  return validateCallForOverloadedFunction(errorNode, argList, expandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext);
6458
6373
  }
6459
- case 7 /* Class */: {
6374
+ case 6 /* Class */: {
6375
+ if ((0, typeUtils_1.isNoneInstance)(expandedCallType)) {
6376
+ addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportOptionalCall, diagnosticRules_1.DiagnosticRule.reportOptionalCall, localize_1.Localizer.Diagnostic.noneNotCallable(), errorNode);
6377
+ return { argumentErrors: true };
6378
+ }
6460
6379
  if (types_1.TypeBase.isInstantiable(expandedCallType)) {
6461
6380
  return validateCallForInstantiableClass(errorNode, argList, expandedCallType, unexpandedCallType, skipUnknownArgCheck, inferenceContext);
6462
6381
  }
6463
6382
  return validateCallForClassInstance(errorNode, argList, expandedCallType, unexpandedCallType, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount);
6464
6383
  }
6465
- case 3 /* None */: {
6466
- if (types_1.TypeBase.isInstantiable(expandedCallType)) {
6467
- if (noneType && (0, types_1.isInstantiableClass)(noneType)) {
6468
- const callResult = validateCallForInstantiableClass(errorNode, argList, noneType, noneType, skipUnknownArgCheck, inferenceContext);
6469
- return { ...callResult, returnType: types_1.NoneType.createInstance() };
6470
- }
6471
- return { returnType: types_1.NoneType.createInstance() };
6472
- }
6473
- addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportOptionalCall, diagnosticRules_1.DiagnosticRule.reportOptionalCall, localize_1.Localizer.Diagnostic.noneNotCallable(), errorNode);
6474
- return { argumentErrors: true };
6475
- }
6476
6384
  // TypeVars should have been expanded in most cases,
6477
6385
  // but we still need to handle the case of Type[T] where
6478
6386
  // T is a constrained type that contains a union. We also
6479
6387
  // need to handle recursive type aliases.
6480
- case 10 /* TypeVar */: {
6388
+ case 9 /* TypeVar */: {
6481
6389
  return validateCallArguments(errorNode, argList, { type: (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(expandedCallType), isIncomplete: isCallTypeIncomplete }, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount);
6482
6390
  }
6483
- case 8 /* Module */: {
6391
+ case 7 /* Module */: {
6484
6392
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.moduleNotCallable(), errorNode);
6485
6393
  return { argumentErrors: true };
6486
6394
  }
@@ -6611,7 +6519,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6611
6519
  const returnType = (0, typeUtils_1.mapSubtypes)(argType, (subtype) => {
6612
6520
  if ((0, types_1.isClassInstance)(subtype) ||
6613
6521
  ((0, types_1.isTypeVar)(subtype) && types_1.TypeBase.isInstance(subtype)) ||
6614
- (0, types_1.isNoneInstance)(subtype)) {
6522
+ (0, typeUtils_1.isNoneInstance)(subtype)) {
6615
6523
  return (0, typeUtils_1.convertToInstantiable)(stripLiteralValue(subtype));
6616
6524
  }
6617
6525
  else if ((0, types_1.isFunction)(subtype) && types_1.TypeBase.isInstance(subtype)) {
@@ -6759,7 +6667,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6759
6667
  var _a, _b;
6760
6668
  const memberType = (_a = getTypeOfObjectMember(errorNode, expandedCallType, '__call__',
6761
6669
  /* usage */ undefined,
6762
- /* diag */ undefined, 128 /* SkipAttributeAccessOverride */ | 1 /* AccessClassMembersOnly */)) === null || _a === void 0 ? void 0 : _a.type;
6670
+ /* diag */ undefined, 512 /* SkipAttributeAccessOverride */ | 16 /* SkipInstanceMembers */)) === null || _a === void 0 ? void 0 : _a.type;
6763
6671
  if (!memberType) {
6764
6672
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.objectNotCallable().format({
6765
6673
  type: printType(expandedCallType),
@@ -7021,8 +6929,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7021
6929
  // with a ParamSpec and a Concatenate operator. PEP 612 indicates that
7022
6930
  // all positional parameters specified in the Concatenate must be
7023
6931
  // filled explicitly.
7024
- if (typeResult.type.details.paramSpec && paramIndex < positionParamLimitIndex) {
7025
- if ((0, types_1.isTypeVar)(argTypeResult.type) && argTypeResult.type.paramSpecAccess === 'args') {
6932
+ if (paramIndex < positionParamLimitIndex) {
6933
+ if ((0, types_1.isTypeVar)(argTypeResult.type) &&
6934
+ argTypeResult.type.paramSpecAccess === 'args' &&
6935
+ paramDetails.params[paramIndex].param.category !== 1 /* ArgsList */) {
7026
6936
  if (!isDiagnosticSuppressedForNode(errorNode)) {
7027
6937
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, positionParamLimitIndex === 1
7028
6938
  ? localize_1.Localizer.Diagnostic.argPositionalExpectedOne()
@@ -8140,6 +8050,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8140
8050
  return { argumentErrors: paramSpecArgResult.argumentErrors, typeVarContexts };
8141
8051
  }
8142
8052
  function validateFunctionArgumentsForParamSpecSignature(errorNode, argList, paramSpec, typeVarContext, signatureTracker) {
8053
+ var _a;
8143
8054
  let paramSpecType = typeVarContext.getParamSpecType(paramSpec);
8144
8055
  if (!paramSpecType) {
8145
8056
  paramSpecType = (0, typeUtils_1.convertTypeToParamSpecValue)(paramSpec);
@@ -8162,8 +8073,37 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8162
8073
  if (functionType.details.paramSpec &&
8163
8074
  functionType.details.parameters.length === 0 &&
8164
8075
  (0, types_1.isTypeSame)(functionType.details.paramSpec, paramSpec)) {
8165
- // TODO - need to perform additional validation here.
8166
- return { argumentErrors: false, typeVarContexts: [srcTypeVarContext] };
8076
+ // If there are any arguments other than *args: P.args or **kwargs: P.kwargs,
8077
+ // report an error.
8078
+ let sawArgs = false;
8079
+ let sawKwargs = false;
8080
+ let argumentErrors = false;
8081
+ let argErrorNode;
8082
+ for (const arg of argList) {
8083
+ const argType = (_a = getTypeOfArgument(arg)) === null || _a === void 0 ? void 0 : _a.type;
8084
+ const isArgTypeCompatible = argType && ((0, types_1.isTypeSame)(argType, paramSpec) || (0, types_1.isAnyOrUnknown)(argType));
8085
+ if (arg.argumentCategory === 1 /* UnpackedList */ && !sawArgs && isArgTypeCompatible) {
8086
+ sawArgs = true;
8087
+ }
8088
+ else if (arg.argumentCategory === 2 /* UnpackedDictionary */ &&
8089
+ !sawKwargs &&
8090
+ isArgTypeCompatible) {
8091
+ sawKwargs = true;
8092
+ }
8093
+ else {
8094
+ argErrorNode = argErrorNode !== null && argErrorNode !== void 0 ? argErrorNode : arg.valueExpression;
8095
+ argumentErrors = true;
8096
+ }
8097
+ }
8098
+ if (!sawArgs || !sawKwargs) {
8099
+ argumentErrors = true;
8100
+ }
8101
+ if (argumentErrors) {
8102
+ addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.paramSpecArgsMissing().format({
8103
+ type: printType(functionType.details.paramSpec),
8104
+ }), argErrorNode !== null && argErrorNode !== void 0 ? argErrorNode : errorNode);
8105
+ }
8106
+ return { argumentErrors, typeVarContexts: [srcTypeVarContext] };
8167
8107
  }
8168
8108
  const result = validateFunctionArgumentTypes(errorNode, matchResults, srcTypeVarContext, signatureTracker);
8169
8109
  return { argumentErrors: !!result.argumentErrors, typeVarContexts: [srcTypeVarContext] };
@@ -8327,7 +8267,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8327
8267
  }
8328
8268
  }
8329
8269
  if ((0, types_1.isClassInstance)(argType)) {
8330
- const callMember = (0, typeUtils_1.lookUpObjectMember)(argType, '__call__', 8 /* SkipInstanceVariables */);
8270
+ const callMember = (0, typeUtils_1.lookUpObjectMember)(argType, '__call__', 16 /* SkipInstanceMembers */);
8331
8271
  if (callMember) {
8332
8272
  const memberType = getTypeOfMember(callMember);
8333
8273
  if ((0, types_1.isOverloadedFunction)(memberType)) {
@@ -8891,7 +8831,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8891
8831
  type: types_1.ClassType.cloneAsInstance(baseClass),
8892
8832
  hasDeclaredType: true,
8893
8833
  });
8894
- initType.details.declaredReturnType = types_1.NoneType.createInstance();
8834
+ initType.details.declaredReturnType = getNoneType();
8895
8835
  classType.details.fields.set('__init__', symbol_1.Symbol.createWithType(4 /* ClassMember */, initType));
8896
8836
  // Synthesize a trivial __new__ method.
8897
8837
  const newType = types_1.FunctionType.createSynthesizedInstance('__new__', 1 /* ConstructorMethod */);
@@ -8938,10 +8878,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8938
8878
  function getTypeOfConstant(node, flags) {
8939
8879
  let type;
8940
8880
  if (node.constType === 26 /* None */) {
8941
- type =
8942
- (flags & 128 /* ExpectingInstantiableType */) !== 0
8943
- ? types_1.NoneType.createType()
8944
- : types_1.NoneType.createInstance();
8881
+ type = (flags & 128 /* ExpectingInstantiableType */) !== 0 ? noneClassType : noneType;
8945
8882
  }
8946
8883
  else if (node.constType === 33 /* True */ ||
8947
8884
  node.constType === 15 /* False */ ||
@@ -8958,30 +8895,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8958
8895
  }
8959
8896
  }
8960
8897
  }
8961
- if (!type) {
8962
- return undefined;
8963
- }
8964
- return { type };
8898
+ return { type: type !== null && type !== void 0 ? type : types_1.UnknownType.create() };
8965
8899
  }
8966
- function getTypeOfMagicMethodReturn(objType, args, magicMethodName, errorNode, inferenceContext) {
8900
+ function getTypeOfMagicMethodCall(objType, methodName, argList, errorNode, inferenceContext) {
8967
8901
  let magicMethodSupported = true;
8968
8902
  // Create a helper lambda for object subtypes.
8969
8903
  const handleSubtype = (subtype) => {
8970
- var _a, _b;
8904
+ var _a;
8971
8905
  let magicMethodType;
8972
8906
  const concreteSubtype = makeTopLevelTypeVarsConcrete(subtype);
8973
- if ((0, types_1.isClassInstance)(concreteSubtype)) {
8974
- magicMethodType = (_a = getTypeOfObjectMember(errorNode, concreteSubtype, magicMethodName,
8907
+ if ((0, types_1.isClass)(concreteSubtype)) {
8908
+ magicMethodType = (_a = getTypeOfObjectMember(errorNode, concreteSubtype, methodName,
8975
8909
  /* usage */ undefined,
8976
- /* diag */ undefined, 128 /* SkipAttributeAccessOverride */ | 1 /* AccessClassMembersOnly */)) === null || _a === void 0 ? void 0 : _a.type;
8977
- }
8978
- else if ((0, types_1.isInstantiableClass)(concreteSubtype)) {
8979
- magicMethodType = (_b = getTypeOfClassMember(errorNode, concreteSubtype, magicMethodName,
8980
- /* usage */ undefined,
8981
- /* diag */ undefined, 128 /* SkipAttributeAccessOverride */ | 64 /* ConsiderMetaclassOnly */)) === null || _b === void 0 ? void 0 : _b.type;
8910
+ /* diag */ undefined, 16 /* SkipInstanceMembers */ | 512 /* SkipAttributeAccessOverride */)) === null || _a === void 0 ? void 0 : _a.type;
8982
8911
  }
8983
8912
  if (magicMethodType) {
8984
- const functionArgs = args.map((arg) => {
8913
+ const functionArgs = argList.map((arg) => {
8985
8914
  return {
8986
8915
  argumentCategory: 0 /* Simple */,
8987
8916
  typeResult: arg,
@@ -9017,13 +8946,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9017
8946
  if ((0, types_1.isClassInstance)(subtype) || (0, types_1.isInstantiableClass)(subtype) || (0, types_1.isTypeVar)(subtype)) {
9018
8947
  return handleSubtype(subtype);
9019
8948
  }
9020
- if ((0, types_1.isNoneInstance)(subtype)) {
8949
+ if ((0, typeUtils_1.isNoneInstance)(subtype)) {
9021
8950
  if (objectType && (0, types_1.isClassInstance)(objectType)) {
9022
8951
  // Use 'object' for 'None'.
9023
8952
  return handleSubtype(objectType);
9024
8953
  }
9025
8954
  }
9026
- if ((0, types_1.isNoneTypeClass)(subtype)) {
8955
+ if ((0, typeUtils_1.isNoneTypeClass)(subtype)) {
9027
8956
  if (typeClassType && (0, types_1.isInstantiableClass)(typeClassType)) {
9028
8957
  // Use 'type' for 'type[None]'.
9029
8958
  return handleSubtype(types_1.ClassType.cloneAsInstance(typeClassType));
@@ -9675,11 +9604,26 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9675
9604
  // Pre-cache the incomplete function type in case the evaluation of the
9676
9605
  // lambda depends on itself.
9677
9606
  writeTypeCache(node, { type: functionType, isIncomplete: true }, 0 /* None */);
9607
+ // We assume for simplicity that the parameter signature of the lambda is
9608
+ // the same as the expected type. If this isn't the case, we'll use
9609
+ // object for any lambda parameters that don't match. We could make this
9610
+ // more sophisticated in the future, but it becomes very complex to handle
9611
+ // all of the permutations.
9612
+ let sawParamMismatch = false;
9678
9613
  node.parameters.forEach((param, index) => {
9679
9614
  let paramType;
9680
- if (expectedParamDetails) {
9615
+ if (expectedParamDetails && !sawParamMismatch) {
9681
9616
  if (index < expectedParamDetails.params.length) {
9682
- paramType = expectedParamDetails.params[index].type;
9617
+ const expectedParam = expectedParamDetails.params[index];
9618
+ // If the parameter category matches and both of the parameters are
9619
+ // either separators (/ or *) or not separators, copy the type
9620
+ // from the expected parameter.
9621
+ if (expectedParam.param.category === param.category && !param.name === !expectedParam.param.name) {
9622
+ paramType = expectedParam.type;
9623
+ }
9624
+ else {
9625
+ sawParamMismatch = true;
9626
+ }
9683
9627
  }
9684
9628
  else if (param.defaultValue) {
9685
9629
  // If the lambda param has a default value but there is no associated
@@ -9789,8 +9733,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9789
9733
  }
9790
9734
  let expectedElementType;
9791
9735
  if (inferenceContext) {
9792
- expectedElementType = (_a = getTypeOfIterator({ type: inferenceContext.expectedType }, isAsync,
9793
- /* errorNode */ undefined)) === null || _a === void 0 ? void 0 : _a.type;
9736
+ expectedElementType = (_a = getTypeOfIterator({ type: inferenceContext.expectedType }, isAsync, node,
9737
+ /* emitNotIterableError */ false)) === null || _a === void 0 ? void 0 : _a.type;
9794
9738
  }
9795
9739
  const elementTypeResult = getElementTypeFromListComprehension(node, expectedElementType);
9796
9740
  if (elementTypeResult.isIncomplete) {
@@ -9810,9 +9754,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9810
9754
  }
9811
9755
  const builtInIteratorType = getTypingType(node, isAsync ? 'AsyncGenerator' : 'Generator');
9812
9756
  if (builtInIteratorType && (0, types_1.isInstantiableClass)(builtInIteratorType)) {
9813
- type = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForSpecialization(builtInIteratorType, isAsync
9814
- ? [elementType, types_1.NoneType.createInstance()]
9815
- : [elementType, types_1.NoneType.createInstance(), types_1.NoneType.createInstance()],
9757
+ type = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForSpecialization(builtInIteratorType, isAsync ? [elementType, getNoneType()] : [elementType, getNoneType(), getNoneType()],
9816
9758
  /* isTypeArgumentExplicit */ true));
9817
9759
  }
9818
9760
  return { type, isIncomplete, typeErrors };
@@ -10141,7 +10083,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10141
10083
  addExpectedClassDiagnostic(typeArg0Type, typeArgs[0].node);
10142
10084
  typeArg0Type = types_1.UnknownType.create();
10143
10085
  }
10144
- const optionalType = (0, types_1.combineTypes)([typeArg0Type, types_1.NoneType.createType()]);
10086
+ const optionalType = (0, types_1.combineTypes)([typeArg0Type, noneClassType !== null && noneClassType !== void 0 ? noneClassType : types_1.UnknownType.create()]);
10145
10087
  if ((0, types_1.isUnion)(optionalType)) {
10146
10088
  types_1.TypeBase.setSpecialForm(optionalType);
10147
10089
  }
@@ -10204,7 +10146,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10204
10146
  type = cloneBuiltinClassWithLiteral(node, 'bool', false);
10205
10147
  }
10206
10148
  else if (itemExpr.constType === 26 /* None */) {
10207
- type = types_1.NoneType.createType();
10149
+ type = noneClassType !== null && noneClassType !== void 0 ? noneClassType : types_1.UnknownType.create();
10208
10150
  }
10209
10151
  }
10210
10152
  else if (itemExpr.nodeType === 55 /* UnaryOperation */ &&
@@ -10228,7 +10170,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10228
10170
  let isLiteralType = true;
10229
10171
  (0, typeUtils_1.doForEachSubtype)(exprType.type, (subtype) => {
10230
10172
  if (!(0, types_1.isInstantiableClass)(subtype) || subtype.literalValue === undefined) {
10231
- if (!(0, types_1.isNoneTypeClass)(subtype)) {
10173
+ if (!(0, typeUtils_1.isNoneTypeClass)(subtype)) {
10232
10174
  isLiteralType = false;
10233
10175
  }
10234
10176
  }
@@ -10639,7 +10581,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10639
10581
  // is allowed if it's an unpacked variadic type var or tuple. None is also allowed
10640
10582
  // since it is used to define NoReturn in typeshed stubs).
10641
10583
  if (types.length === 1) {
10642
- if (!(0, types_1.isVariadicTypeVar)(types[0]) && !(0, types_1.isUnpacked)(types[0]) && !(0, types_1.isNoneInstance)(types[0])) {
10584
+ if (!(0, types_1.isVariadicTypeVar)(types[0]) && !(0, types_1.isUnpacked)(types[0]) && !(0, typeUtils_1.isNoneInstance)(types[0])) {
10643
10585
  addError(localize_1.Localizer.Diagnostic.unionTypeArgCount(), errorNode);
10644
10586
  }
10645
10587
  }
@@ -10988,8 +10930,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10988
10930
  if (typeAliasNameNode) {
10989
10931
  // If this was a speculative type alias, it becomes a real type alias
10990
10932
  // only if the evaluated type is an instantiable type.
10991
- if (!isSpeculativeTypeAlias ||
10992
- (types_1.TypeBase.isInstantiable(rightHandType) && !(0, types_1.isUnknown)(rightHandType))) {
10933
+ if (!isSpeculativeTypeAlias || isLegalImplicitTypeAliasType(rightHandType)) {
10993
10934
  // If this is a type alias, record its name based on the assignment target.
10994
10935
  rightHandType = transformTypeForTypeAlias(rightHandType, typeAliasNameNode, node.rightExpression,
10995
10936
  /* isPep695Syntax */ false);
@@ -11115,6 +11056,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11115
11056
  return `__type_of_${paramName}`;
11116
11057
  }
11117
11058
  function getTypeOfClass(node) {
11059
+ initializedBasicTypes(node);
11118
11060
  // Is this type already cached?
11119
11061
  const cachedClassType = readTypeCache(node.name, 0 /* None */);
11120
11062
  if (cachedClassType) {
@@ -11135,7 +11077,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11135
11077
  if ((scope === null || scope === void 0 ? void 0 : scope.type) === 4 /* Builtin */ ||
11136
11078
  fileInfo.isTypingStubFile ||
11137
11079
  fileInfo.isTypingExtensionsStubFile ||
11138
- fileInfo.isBuiltInStubFile) {
11080
+ fileInfo.isBuiltInStubFile ||
11081
+ fileInfo.isTypeshedStubFile) {
11139
11082
  classFlags |= 1 /* BuiltInClass */;
11140
11083
  if (fileInfo.isTypingExtensionsStubFile) {
11141
11084
  classFlags |= 65536 /* TypingExtensionClass */;
@@ -11443,7 +11386,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11443
11386
  classType.details.fields.set('__hash__', symbol_1.Symbol.createWithType(4 /* ClassMember */ |
11444
11387
  128 /* ClassVar */ |
11445
11388
  64 /* IgnoredForProtocolMatch */ |
11446
- 4096 /* IgnoredForOverrideChecks */, types_1.NoneType.createInstance()));
11389
+ 4096 /* IgnoredForOverrideChecks */, getNoneType()));
11447
11390
  }
11448
11391
  // Determine whether the class's instance variables are constrained
11449
11392
  // to those defined by __slots__. We need to do this prior to dataclass
@@ -11889,22 +11832,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11889
11832
  }
11890
11833
  });
11891
11834
  const errorNode = argList.length > 0 ? argList[0].node.name : node.name;
11892
- const initSubclassMethodInfo = getTypeOfClassMemberName(errorNode, classType,
11893
- /* isAccessedThroughObject */ false, '__init_subclass__', { method: 'get' },
11894
- /* diag */ undefined, 1 /* AccessClassMembersOnly */ |
11895
- 8 /* SkipObjectBaseClass */ |
11896
- 256 /* SkipOriginalClass */, classType);
11835
+ const initSubclassMethodInfo = getTypeOfObjectMember(errorNode, classType, '__init_subclass__', { method: 'get' },
11836
+ /* diag */ undefined, 32 /* SkipClassMembers */ |
11837
+ 4 /* SkipObjectBaseClass */ |
11838
+ 1 /* SkipOriginalClass */ |
11839
+ 512 /* SkipAttributeAccessOverride */);
11897
11840
  if (initSubclassMethodInfo) {
11898
11841
  const initSubclassMethodType = initSubclassMethodInfo.type;
11899
11842
  if (initSubclassMethodType) {
11900
11843
  validateCallArguments(errorNode, argList, { type: initSubclassMethodType },
11901
11844
  /* typeVarContext */ undefined,
11902
- /* skipUnknownArgCheck */ false, (0, typeUtils_1.makeInferenceContext)(types_1.NoneType.createInstance()));
11845
+ /* skipUnknownArgCheck */ false, (0, typeUtils_1.makeInferenceContext)(getNoneType()));
11903
11846
  }
11904
11847
  }
11905
11848
  else if (classType.details.effectiveMetaclass && (0, types_1.isClass)(classType.details.effectiveMetaclass)) {
11906
11849
  // See if the metaclass has a `__new__` method that accepts keyword parameters.
11907
- const newMethodMember = (0, typeUtils_1.lookUpClassMember)(classType.details.effectiveMetaclass, '__new__', 64 /* SkipTypeBaseClass */);
11850
+ const newMethodMember = (0, typeUtils_1.lookUpClassMember)(classType.details.effectiveMetaclass, '__new__', 8 /* SkipTypeBaseClass */);
11908
11851
  if (newMethodMember) {
11909
11852
  const newMethodType = getTypeOfMember(newMethodMember);
11910
11853
  if ((0, types_1.isFunction)(newMethodType)) {
@@ -11967,6 +11910,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11967
11910
  });
11968
11911
  }
11969
11912
  function getTypeOfFunction(node) {
11913
+ initializedBasicTypes(node);
11970
11914
  // Is this predecorated function type cached?
11971
11915
  let functionType = readTypeCache(node.name, 0 /* None */);
11972
11916
  if (functionType) {
@@ -12329,7 +12273,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12329
12273
  // Special-case the __init__ method, which is commonly left without
12330
12274
  // an annotated return type, but we can assume it returns None.
12331
12275
  if (node.name.value === '__init__') {
12332
- functionType.details.declaredReturnType = types_1.NoneType.createInstance();
12276
+ functionType.details.declaredReturnType = getNoneType();
12333
12277
  }
12334
12278
  else {
12335
12279
  functionType.details.declaredReturnType = types_1.UnknownType.create();
@@ -12422,7 +12366,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12422
12366
  param.defaultValue.constType === 26 /* None */ &&
12423
12367
  !(0, typeUtils_1.isOptionalType)(type) &&
12424
12368
  !AnalyzerNodeInfo.getFileInfo(param).diagnosticRuleSet.strictParameterNoneValue) {
12425
- return (0, types_1.combineTypes)([type, types_1.NoneType.createInstance()]);
12369
+ return (0, types_1.combineTypes)([type, getNoneType()]);
12426
12370
  }
12427
12371
  return type;
12428
12372
  }
@@ -12482,7 +12426,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12482
12426
  // whose name starts with an underscore)? If so, we will assume that the
12483
12427
  // value is a singleton sentinel. The actual supported type is going to be
12484
12428
  // a union of this type and Unknown.
12485
- if ((0, types_1.isNoneInstance)(defaultValueType) ||
12429
+ if ((0, typeUtils_1.isNoneInstance)(defaultValueType) ||
12486
12430
  ((0, types_1.isClassInstance)(defaultValueType) && (0, symbolNameUtils_1.isPrivateOrProtectedName)(defaultValueType.details.name))) {
12487
12431
  inferredParamType = (0, types_1.combineTypes)([defaultValueType, types_1.UnknownType.create()]);
12488
12432
  }
@@ -12680,13 +12624,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12680
12624
  inferredReturnTypes.push(returnType);
12681
12625
  }
12682
12626
  else {
12683
- inferredReturnTypes.push(types_1.NoneType.createInstance());
12627
+ inferredReturnTypes.push(getNoneType());
12684
12628
  }
12685
12629
  }
12686
12630
  });
12687
12631
  }
12688
12632
  if (!functionNeverReturns && implicitlyReturnsNone) {
12689
- inferredReturnTypes.push(types_1.NoneType.createInstance());
12633
+ inferredReturnTypes.push(getNoneType());
12690
12634
  }
12691
12635
  inferredReturnType = (0, types_1.combineTypes)(inferredReturnTypes);
12692
12636
  // Remove any unbound values since those would generate an exception
@@ -12728,14 +12672,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12728
12672
  inferredYieldTypes.push(yieldType !== null && yieldType !== void 0 ? yieldType : types_1.UnknownType.create());
12729
12673
  }
12730
12674
  else {
12731
- inferredYieldTypes.push(types_1.NoneType.createInstance());
12675
+ inferredYieldTypes.push(getNoneType());
12732
12676
  }
12733
12677
  }
12734
12678
  }
12735
12679
  });
12736
12680
  }
12737
12681
  if (inferredYieldTypes.length === 0) {
12738
- inferredYieldTypes.push(types_1.NoneType.createInstance());
12682
+ inferredYieldTypes.push(getNoneType());
12739
12683
  }
12740
12684
  const inferredYieldType = (0, types_1.combineTypes)(inferredYieldTypes);
12741
12685
  // Inferred yield types need to be wrapped in a Generator or
@@ -12749,7 +12693,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12749
12693
  // This eliminates any "partially unknown" errors in strict mode
12750
12694
  // in the common case.
12751
12695
  const sendType = isYieldResultUsed ? types_1.UnknownType.create() : types_1.AnyType.create();
12752
- typeArgs.push(inferredYieldType, sendType, (0, types_1.isNever)(inferredReturnType) ? types_1.NoneType.createInstance() : inferredReturnType);
12696
+ typeArgs.push(inferredYieldType, sendType, (0, types_1.isNever)(inferredReturnType) ? getNoneType() : inferredReturnType);
12753
12697
  if (useAwaitableGenerator) {
12754
12698
  typeArgs.push(types_1.AnyType.create());
12755
12699
  }
@@ -12866,7 +12810,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12866
12810
  if ((0, typeUtils_1.isOptionalType)(exprType)) {
12867
12811
  const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
12868
12812
  addDiagnostic(fileInfo.diagnosticRuleSet.reportOptionalContextManager, diagnosticRules_1.DiagnosticRule.reportOptionalContextManager, localize_1.Localizer.Diagnostic.noneNotUsableWith(), node.expression);
12869
- exprType = (0, types_1.removeNoneFromUnion)(exprType);
12813
+ exprType = (0, typeUtils_1.removeNoneFromUnion)(exprType);
12870
12814
  }
12871
12815
  // Verify that the target has an __enter__ or __aenter__ method defined.
12872
12816
  const enterMethodName = isAsync ? '__aenter__' : '__enter__';
@@ -12877,7 +12821,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12877
12821
  }
12878
12822
  const additionalHelp = new diagnostic_1.DiagnosticAddendum();
12879
12823
  if ((0, types_1.isClass)(subtype)) {
12880
- let enterType = getTypeOfMagicMethodReturn(subtype, [], enterMethodName, node.expression,
12824
+ let enterType = getTypeOfMagicMethodCall(subtype, enterMethodName, [], node.expression,
12881
12825
  /* inferenceContext */ undefined);
12882
12826
  if (enterType) {
12883
12827
  // For "async while", an implicit "await" is performed.
@@ -12887,7 +12831,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12887
12831
  return enterType;
12888
12832
  }
12889
12833
  if (!isAsync) {
12890
- if (getTypeOfMagicMethodReturn(subtype, [], '__aenter__', node.expression,
12834
+ if (getTypeOfMagicMethodCall(subtype, '__aenter__', [], node.expression,
12891
12835
  /* inferenceContext */ undefined)) {
12892
12836
  additionalHelp.addMessage(localize_1.Localizer.DiagnosticAddendum.asyncHelp());
12893
12837
  }
@@ -12907,7 +12851,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12907
12851
  }
12908
12852
  if ((0, types_1.isClass)(subtype)) {
12909
12853
  const anyArg = { type: types_1.AnyType.create() };
12910
- const exitType = getTypeOfMagicMethodReturn(subtype, [anyArg, anyArg, anyArg], exitMethodName, node.expression,
12854
+ const exitType = getTypeOfMagicMethodCall(subtype, exitMethodName, [anyArg, anyArg, anyArg], node.expression,
12911
12855
  /* inferenceContext */ undefined);
12912
12856
  if (exitType) {
12913
12857
  return;
@@ -14345,7 +14289,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14345
14289
  if ((0, types_1.isInstantiableClass)(subtype)) {
14346
14290
  // Try to find a member that has a declared type. If so, that
14347
14291
  // overrides any inferred types.
14348
- let member = (0, typeUtils_1.lookUpClassMember)(subtype, memberName, 32 /* DeclaredTypesOnly */);
14292
+ let member = (0, typeUtils_1.lookUpClassMember)(subtype, memberName, 64 /* DeclaredTypesOnly */);
14349
14293
  if (!member) {
14350
14294
  member = (0, typeUtils_1.lookUpClassMember)(subtype, memberName);
14351
14295
  }
@@ -14362,7 +14306,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14362
14306
  else if ((0, types_1.isClassInstance)(subtype)) {
14363
14307
  // Try to find a member that has a declared type. If so, that
14364
14308
  // overrides any inferred types.
14365
- let member = (0, typeUtils_1.lookUpObjectMember)(subtype, memberName, 32 /* DeclaredTypesOnly */);
14309
+ let member = (0, typeUtils_1.lookUpObjectMember)(subtype, memberName, 64 /* DeclaredTypesOnly */);
14366
14310
  if (!member) {
14367
14311
  member = (0, typeUtils_1.lookUpObjectMember)(subtype, memberName);
14368
14312
  }
@@ -14428,7 +14372,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14428
14372
  }
14429
14373
  else if ((0, types_1.isInstantiableClass)(baseType)) {
14430
14374
  const initMethodType = (_b = getTypeOfObjectMember(argNode.parent.leftExpression, types_1.ClassType.cloneAsInstance(baseType), '__init__', { method: 'get' },
14431
- /* diag */ undefined, 8 /* SkipObjectBaseClass */)) === null || _b === void 0 ? void 0 : _b.type;
14375
+ /* diag */ undefined, 4 /* SkipObjectBaseClass */)) === null || _b === void 0 ? void 0 : _b.type;
14432
14376
  if (initMethodType && (0, types_1.isFunction)(initMethodType)) {
14433
14377
  const paramDecl = getDeclarationFromFunctionNamedParameter(initMethodType, paramName);
14434
14378
  if (paramDecl) {
@@ -14492,7 +14436,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14492
14436
  return { type: strType };
14493
14437
  }
14494
14438
  if (declaration.intrinsicType === 'str | None') {
14495
- return { type: (0, types_1.combineTypes)([strType, types_1.NoneType.createInstance()]) };
14439
+ return { type: (0, types_1.combineTypes)([strType, getNoneType()]) };
14496
14440
  }
14497
14441
  if (declaration.intrinsicType === 'int') {
14498
14442
  return { type: intType };
@@ -14840,9 +14784,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14840
14784
  // If this was a speculative type alias, it becomes a real type alias only
14841
14785
  // in the event that its inferred type is instantiable or explicitly Any
14842
14786
  // (but not an ellipsis).
14843
- if (types_1.TypeBase.isInstantiable(inferredType) &&
14844
- !(0, types_1.isUnknown)(inferredType) &&
14845
- !(0, typeUtils_1.isEllipsisType)(inferredType)) {
14787
+ if (isLegalImplicitTypeAliasType(inferredType)) {
14846
14788
  inferredType = transformTypeForTypeAlias(inferredType, resolvedDecl.typeAliasName, resolvedDecl.node,
14847
14789
  /* isPep695Syntax */ false);
14848
14790
  isUnambiguousType = true;
@@ -15311,7 +15253,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15311
15253
  // Don't bother inferring the return type of __init__ because it's
15312
15254
  // always None.
15313
15255
  if (types_1.FunctionType.isInstanceMethod(type) && type.details.name === '__init__') {
15314
- returnType = types_1.NoneType.createInstance();
15256
+ returnType = getNoneType();
15315
15257
  }
15316
15258
  else if (type.details.declaration) {
15317
15259
  const functionNode = type.details.declaration.node;
@@ -16274,23 +16216,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16274
16216
  if ((0, types_1.isUnion)(destType)) {
16275
16217
  return assignToUnionType(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, originalFlags, recursionCount);
16276
16218
  }
16277
- if ((0, types_1.isNoneInstance)(destType)) {
16278
- if ((0, types_1.isNoneInstance)(srcType)) {
16219
+ if ((0, typeUtils_1.isNoneInstance)(destType)) {
16220
+ if ((0, typeUtils_1.isNoneInstance)(srcType)) {
16279
16221
  return true;
16280
16222
  }
16281
16223
  if ((0, types_1.isClassInstance)(srcType) && types_1.ClassType.isBuiltIn(srcType, 'NoneType')) {
16282
16224
  return true;
16283
16225
  }
16284
16226
  }
16285
- if ((0, types_1.isNoneTypeClass)(destType)) {
16286
- if ((0, types_1.isNoneTypeClass)(srcType)) {
16227
+ if ((0, typeUtils_1.isNoneTypeClass)(destType)) {
16228
+ if ((0, typeUtils_1.isNoneTypeClass)(srcType)) {
16287
16229
  return true;
16288
16230
  }
16289
16231
  if ((0, types_1.isInstantiableClass)(srcType) && types_1.ClassType.isBuiltIn(srcType, 'NoneType')) {
16290
16232
  return true;
16291
16233
  }
16292
16234
  }
16293
- // Is the src a specialized "Type" object?
16235
+ // Is the src a specialized "type" object?
16294
16236
  if ((0, types_1.isClassInstance)(expandedSrcType) && types_1.ClassType.isBuiltIn(expandedSrcType, 'type')) {
16295
16237
  const srcTypeArgs = expandedSrcType.typeArguments;
16296
16238
  let typeTypeArg;
@@ -16342,6 +16284,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16342
16284
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
16343
16285
  return false;
16344
16286
  }
16287
+ else if ((0, types_1.isClassInstance)(expandedSrcType) && (0, typeUtils_1.isMetaclassInstance)(expandedSrcType)) {
16288
+ // If the source is a metaclass instance, verify that it's compatible with
16289
+ // the metaclass of the instantiable dest type.
16290
+ const destMetaclass = destType.details.effectiveMetaclass;
16291
+ if (destMetaclass && (0, types_1.isInstantiableClass)(destMetaclass)) {
16292
+ if (assignClass(types_1.ClassType.cloneAsInstance(destMetaclass), expandedSrcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount,
16293
+ /* reportErrorsUsingObjType */ false)) {
16294
+ return true;
16295
+ }
16296
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
16297
+ return false;
16298
+ }
16299
+ }
16345
16300
  }
16346
16301
  if ((0, types_1.isClassInstance)(destType)) {
16347
16302
  // Is the dest a specialized "Type" object?
@@ -16560,13 +16515,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16560
16515
  }
16561
16516
  }
16562
16517
  // Are we trying to assign None to a protocol?
16563
- if ((0, types_1.isNoneInstance)(srcType) && (0, types_1.isClassInstance)(destType) && types_1.ClassType.isProtocolClass(destType)) {
16564
- if (noneType && (0, types_1.isInstantiableClass)(noneType)) {
16565
- return (0, protocols_1.assignClassToProtocol)(evaluatorInterface, types_1.ClassType.cloneAsInstantiable(destType), noneType, diag, destTypeVarContext, srcTypeVarContext, flags,
16518
+ if ((0, typeUtils_1.isNoneInstance)(srcType) && (0, types_1.isClassInstance)(destType) && types_1.ClassType.isProtocolClass(destType)) {
16519
+ if (noneClassType && (0, types_1.isInstantiableClass)(noneClassType)) {
16520
+ return (0, protocols_1.assignClassToProtocol)(evaluatorInterface, types_1.ClassType.cloneAsInstantiable(destType), noneClassType, diag, destTypeVarContext, srcTypeVarContext, flags,
16566
16521
  /* treatSourceAsInstantiable */ false, recursionCount);
16567
16522
  }
16568
16523
  }
16569
- if ((0, types_1.isNoneInstance)(destType)) {
16524
+ if ((0, typeUtils_1.isNoneInstance)(destType)) {
16570
16525
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.assignToNone());
16571
16526
  return false;
16572
16527
  }
@@ -16823,7 +16778,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16823
16778
  // match we find because we may need to match TypeVars in other
16824
16779
  // subtypes. We special-case "None" so we can handle Optional[T]
16825
16780
  // without matching the None to the type var.
16826
- if ((0, types_1.isNoneInstance)(srcType) && (0, typeUtils_1.isOptionalType)(destType)) {
16781
+ if ((0, typeUtils_1.isNoneInstance)(srcType) && (0, typeUtils_1.isOptionalType)(destType)) {
16827
16782
  foundMatch = true;
16828
16783
  }
16829
16784
  else {
@@ -17106,15 +17061,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17106
17061
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
17107
17062
  let canAssign = true;
17108
17063
  const checkReturnType = (flags & 32 /* SkipFunctionReturnTypeCheck */) === 0;
17064
+ const reverseMatching = (flags & 2 /* ReverseTypeVarMatching */) !== 0;
17109
17065
  flags &= ~32 /* SkipFunctionReturnTypeCheck */;
17110
17066
  destType = (0, typeUtils_1.removeParamSpecVariadicsFromFunction)(destType);
17111
17067
  srcType = (0, typeUtils_1.removeParamSpecVariadicsFromFunction)(srcType);
17112
17068
  const destParamDetails = (0, parameterUtils_1.getParameterListDetails)(destType);
17113
17069
  const srcParamDetails = (0, parameterUtils_1.getParameterListDetails)(srcType);
17114
- adjustSourceParamDetailsForDestVariadic(srcParamDetails, destParamDetails);
17115
- const targetIncludesParamSpec = (flags & 2 /* ReverseTypeVarMatching */) !== 0
17116
- ? !!srcType.details.paramSpec
17117
- : !!destType.details.paramSpec;
17070
+ adjustSourceParamDetailsForDestVariadic(reverseMatching ? destParamDetails : srcParamDetails, reverseMatching ? srcParamDetails : destParamDetails);
17071
+ const targetIncludesParamSpec = reverseMatching ? !!srcType.details.paramSpec : !!destType.details.paramSpec;
17118
17072
  const destPositionalCount = (_b = (_a = destParamDetails.argsIndex) !== null && _a !== void 0 ? _a : destParamDetails.firstKeywordOnlyIndex) !== null && _b !== void 0 ? _b : destParamDetails.params.length;
17119
17073
  const srcPositionalCount = (_d = (_c = srcParamDetails.argsIndex) !== null && _c !== void 0 ? _c : srcParamDetails.firstKeywordOnlyIndex) !== null && _d !== void 0 ? _d : srcParamDetails.params.length;
17120
17074
  const positionalsToMatch = Math.min(destPositionalCount, srcPositionalCount);
@@ -17387,7 +17341,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17387
17341
  canAssign = false;
17388
17342
  }
17389
17343
  }
17390
- const effectiveSrcTypeVarContext = (flags & 2 /* ReverseTypeVarMatching */) === 0 ? srcTypeVarContext : destTypeVarContext;
17344
+ const effectiveSrcTypeVarContext = reverseMatching ? destTypeVarContext : srcTypeVarContext;
17391
17345
  // If the target function was generic and we solved some of the type variables
17392
17346
  // in that generic type, assign them back to the destination typeVar.
17393
17347
  const typeVarSignatureContext = effectiveSrcTypeVarContext.getPrimarySignature();
@@ -17397,8 +17351,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17397
17351
  });
17398
17352
  // Are we assigning to a function with a ParamSpec?
17399
17353
  if (targetIncludesParamSpec) {
17400
- const effectiveDestType = (flags & 2 /* ReverseTypeVarMatching */) === 0 ? destType : srcType;
17401
- const effectiveSrcType = (flags & 2 /* ReverseTypeVarMatching */) === 0 ? srcType : destType;
17354
+ const effectiveDestType = reverseMatching ? srcType : destType;
17355
+ const effectiveSrcType = reverseMatching ? destType : srcType;
17402
17356
  if (effectiveDestType.details.paramSpec) {
17403
17357
  const requiredMatchParamCount = effectiveDestType.details.parameters.filter((p) => {
17404
17358
  if (!p.name) {
@@ -17451,9 +17405,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17451
17405
  remainingParams.forEach((param) => {
17452
17406
  types_1.FunctionType.addParameter(remainingFunction, param);
17453
17407
  });
17454
- remainingFunction.details.paramSpec = srcParamSpec
17455
- ? (0, typeUtils_1.convertToInstance)(srcParamSpec)
17456
- : undefined;
17408
+ remainingFunction.details.paramSpec = srcParamSpec ? (0, typeUtils_1.convertToInstance)(srcParamSpec) : undefined;
17457
17409
  if (!assignType(destParamSpec, remainingFunction,
17458
17410
  /* diag */ undefined, destTypeVarContext, srcTypeVarContext, flags)) {
17459
17411
  // If we couldn't assign the function to the ParamSpec, see if we can
@@ -17712,9 +17664,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17712
17664
  previousMatchIndex = matchIndex;
17713
17665
  }
17714
17666
  if (previousMatchIndex < baseOverloads.length - 1) {
17715
- // We didn't find matches for all of the base overloads.
17716
- diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideOverloadNoMatch());
17717
- return false;
17667
+ const unmatchedOverloads = baseOverloads.slice(previousMatchIndex + 1);
17668
+ // See if all of the remaining overrides are nonapplicable.
17669
+ if (!baseClass ||
17670
+ unmatchedOverloads.some((overload) => {
17671
+ return isOverrideMethodApplicable(overload, baseClass);
17672
+ })) {
17673
+ // We didn't find matches for all of the base overloads.
17674
+ diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideOverloadNoMatch());
17675
+ return false;
17676
+ }
17718
17677
  }
17719
17678
  return true;
17720
17679
  }
@@ -18150,9 +18109,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
18150
18109
  });
18151
18110
  return methodList;
18152
18111
  }
18153
- function bindFunctionToClassOrObjectWithErrors(baseType, memberType, memberClass, errorNode, treatConstructorAsClassMember = false, firstParamType) {
18112
+ function bindFunctionToClassOrObjectWithErrors(baseType, memberType, memberClass, errorNode, treatConstructorAsClassMember = false, selfType) {
18154
18113
  const diag = errorNode ? new diagnostic_1.DiagnosticAddendum() : undefined;
18155
- const result = bindFunctionToClassOrObject(baseType, memberType, memberClass, treatConstructorAsClassMember, firstParamType, diag);
18114
+ const result = bindFunctionToClassOrObject(baseType, memberType, memberClass, treatConstructorAsClassMember, selfType, diag);
18156
18115
  if (!result && errorNode && diag) {
18157
18116
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, diag.getString(), errorNode);
18158
18117
  }
@@ -18160,75 +18119,43 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
18160
18119
  }
18161
18120
  // If the memberType is an instance or class method, creates a new
18162
18121
  // version of the function that has the "self" or "cls" parameter bound
18163
- // to it. If treatAsClassMethod is true, the function is treated like a
18164
- // class method even if it's not marked as such. That's needed to
18165
- // special-case the __new__ magic method when it's invoked as a
18166
- // constructor (as opposed to by name).
18167
- function bindFunctionToClassOrObject(baseType, memberType, memberClass, treatConstructorAsClassMember = false, firstParamType, diag, recursionCount = 0) {
18168
- if ((0, types_1.isFunction)(memberType)) {
18122
+ // to it. If treatConstructorAsClassMember is true, the function is
18123
+ // treated like a class method even if it's not marked as such. That's
18124
+ // needed to special-case the __new__ magic method when it's invoked as
18125
+ // a constructor (as opposed to by name).
18126
+ function bindFunctionToClassOrObject(baseType, memberType, memberClass, treatConstructorAsClassMember = false, selfType, diag, recursionCount = 0) {
18127
+ return (0, typeUtils_1.mapSignatures)(memberType, (functionType) => {
18169
18128
  // If the caller specified no base type, always strip the
18170
18129
  // first parameter. This is used in cases like constructors.
18171
18130
  if (!baseType) {
18172
- return types_1.FunctionType.clone(memberType, /* stripFirstParam */ true);
18131
+ return types_1.FunctionType.clone(functionType, /* stripFirstParam */ true);
18173
18132
  }
18174
- if (types_1.FunctionType.isInstanceMethod(memberType)) {
18133
+ if (types_1.FunctionType.isInstanceMethod(functionType)) {
18175
18134
  // If the baseType is a metaclass, don't specialize the function.
18176
18135
  if ((0, typeUtils_1.isInstantiableMetaclass)(baseType)) {
18177
- return memberType;
18136
+ return functionType;
18178
18137
  }
18179
- const baseObj = (0, types_1.isClassInstance)(baseType)
18180
- ? baseType
18181
- : types_1.ClassType.cloneAsInstance((0, typeUtils_1.specializeClassType)(baseType));
18182
- return partiallySpecializeFunctionForBoundClassOrObject(baseType, memberType, memberClass || types_1.ClassType.cloneAsInstantiable(baseObj), diag, recursionCount, firstParamType || baseObj,
18138
+ const baseObj = (0, types_1.isInstantiableClass)(baseType)
18139
+ ? types_1.ClassType.cloneAsInstance((0, typeUtils_1.specializeClassType)(baseType))
18140
+ : baseType;
18141
+ return partiallySpecializeFunctionForBoundClassOrObject(baseType, functionType, memberClass !== null && memberClass !== void 0 ? memberClass : types_1.ClassType.cloneAsInstantiable(baseObj), diag, recursionCount, selfType !== null && selfType !== void 0 ? selfType : baseObj,
18183
18142
  /* stripFirstParam */ (0, types_1.isClassInstance)(baseType));
18184
18143
  }
18185
- if (types_1.FunctionType.isClassMethod(memberType) ||
18186
- (treatConstructorAsClassMember && types_1.FunctionType.isConstructorMethod(memberType))) {
18144
+ if (types_1.FunctionType.isClassMethod(functionType) ||
18145
+ (treatConstructorAsClassMember && types_1.FunctionType.isConstructorMethod(functionType))) {
18187
18146
  const baseClass = (0, types_1.isInstantiableClass)(baseType) ? baseType : types_1.ClassType.cloneAsInstantiable(baseType);
18188
- // If the caller passed an object as the base type, we need to also
18189
- // convert the firstParamType to an instantiable.
18190
- const effectiveFirstParamType = firstParamType
18191
- ? (0, types_1.isInstantiableClass)(baseType)
18192
- ? firstParamType
18193
- : (0, typeUtils_1.convertToInstantiable)(firstParamType)
18194
- : baseClass;
18195
- return partiallySpecializeFunctionForBoundClassOrObject(types_1.TypeBase.isInstance(baseType) ? types_1.ClassType.cloneAsInstantiable(baseType) : baseType, memberType, memberClass || baseClass, diag, recursionCount, effectiveFirstParamType,
18147
+ const clsType = selfType ? (0, typeUtils_1.convertToInstantiable)(selfType) : undefined;
18148
+ return partiallySpecializeFunctionForBoundClassOrObject(baseClass, functionType, memberClass !== null && memberClass !== void 0 ? memberClass : baseClass, diag, recursionCount, clsType !== null && clsType !== void 0 ? clsType : baseClass,
18196
18149
  /* stripFirstParam */ true);
18197
18150
  }
18198
- if (types_1.FunctionType.isStaticMethod(memberType)) {
18151
+ if (types_1.FunctionType.isStaticMethod(functionType)) {
18199
18152
  const baseClass = (0, types_1.isInstantiableClass)(baseType) ? baseType : types_1.ClassType.cloneAsInstantiable(baseType);
18200
- return partiallySpecializeFunctionForBoundClassOrObject(types_1.TypeBase.isInstance(baseType) ? types_1.ClassType.cloneAsInstantiable(baseType) : baseType, memberType, memberClass || baseClass, diag, recursionCount,
18201
- /* effectiveFirstParamType */ undefined,
18153
+ return partiallySpecializeFunctionForBoundClassOrObject(baseClass, functionType, memberClass !== null && memberClass !== void 0 ? memberClass : baseClass, diag, recursionCount,
18154
+ /* firstParamType */ undefined,
18202
18155
  /* stripFirstParam */ false);
18203
18156
  }
18204
- }
18205
- else if ((0, types_1.isOverloadedFunction)(memberType)) {
18206
- const newOverloadType = types_1.OverloadedFunctionType.create([]);
18207
- // Don't bother binding the implementation.
18208
- types_1.OverloadedFunctionType.getOverloads(memberType).forEach((overload) => {
18209
- const boundMethod = bindFunctionToClassOrObject(baseType, overload, memberClass, treatConstructorAsClassMember, firstParamType,
18210
- /* diag */ undefined, recursionCount);
18211
- if (boundMethod) {
18212
- types_1.OverloadedFunctionType.addOverload(newOverloadType, boundMethod);
18213
- }
18214
- });
18215
- const newOverloads = types_1.OverloadedFunctionType.getOverloads(newOverloadType);
18216
- if (newOverloads.length === 0) {
18217
- // No overloads matched, so rebind with the diag
18218
- // to report the error(s) to the user.
18219
- if (diag) {
18220
- memberType.overloads.forEach((overload) => {
18221
- bindFunctionToClassOrObject(baseType, overload, memberClass, treatConstructorAsClassMember, firstParamType, diag, recursionCount);
18222
- });
18223
- }
18224
- return undefined;
18225
- }
18226
- if (newOverloads.length === 1) {
18227
- return newOverloads[0];
18228
- }
18229
- return newOverloadType;
18230
- }
18231
- return memberType;
18157
+ return functionType;
18158
+ });
18232
18159
  }
18233
18160
  // Specializes the specified function for the specified class,
18234
18161
  // optionally stripping the first first parameter (the "self" or "cls")
@@ -18333,6 +18260,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
18333
18260
  }
18334
18261
  return true;
18335
18262
  }
18263
+ function isLegalImplicitTypeAliasType(type) {
18264
+ // We explicitly exclude "Unknown" and "...".
18265
+ if ((0, types_1.isUnknown)(type) || (0, typeUtils_1.isEllipsisType)(type)) {
18266
+ return false;
18267
+ }
18268
+ // Look at the subtypes within the union. If any of them are not
18269
+ // instantiable (other than "None" which is special-cased), it is
18270
+ // not a legal type alias type.
18271
+ let isLegal = true;
18272
+ (0, typeUtils_1.doForEachSubtype)(type, (subtype) => {
18273
+ if (!types_1.TypeBase.isInstantiable(subtype) && !(0, typeUtils_1.isNoneInstance)(subtype)) {
18274
+ isLegal = false;
18275
+ }
18276
+ });
18277
+ return isLegal;
18278
+ }
18336
18279
  function printObjectTypeForClass(type) {
18337
18280
  return TypePrinter.printObjectTypeForClass(type, evaluatorOptions.printTypeFlags, getFunctionEffectiveReturnType);
18338
18281
  }
@@ -18502,9 +18445,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
18502
18445
  getBuiltInType,
18503
18446
  getTypeOfMember,
18504
18447
  getTypeOfObjectMember,
18505
- getTypeOfClassMemberName,
18506
18448
  getBoundMethod,
18507
- getTypeOfMagicMethodReturn,
18449
+ getTypeOfMagicMethodCall,
18508
18450
  bindFunctionToClassOrObject,
18509
18451
  getCallSignatureInfo,
18510
18452
  getAbstractMethods,
@@ -18518,6 +18460,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
18518
18460
  getTypedDictClassType,
18519
18461
  getTupleClassType,
18520
18462
  getObjectType,
18463
+ getNoneType,
18521
18464
  getBuiltInObject,
18522
18465
  getTypingType,
18523
18466
  assignTypeArguments,