@zzzen/pyright-internal 1.2.0-dev.20240421 → 1.2.0-dev.20240505

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 (157) hide show
  1. package/dist/analyzer/analyzerNodeInfo.d.ts +1 -4
  2. package/dist/analyzer/analyzerNodeInfo.js +1 -11
  3. package/dist/analyzer/analyzerNodeInfo.js.map +1 -1
  4. package/dist/analyzer/binder.d.ts +0 -2
  5. package/dist/analyzer/binder.js +42 -66
  6. package/dist/analyzer/binder.js.map +1 -1
  7. package/dist/analyzer/checker.js +98 -45
  8. package/dist/analyzer/checker.js.map +1 -1
  9. package/dist/analyzer/constructors.js +31 -13
  10. package/dist/analyzer/constructors.js.map +1 -1
  11. package/dist/analyzer/dataClasses.d.ts +1 -1
  12. package/dist/analyzer/dataClasses.js +23 -11
  13. package/dist/analyzer/dataClasses.js.map +1 -1
  14. package/dist/analyzer/deprecatedSymbols.js +2 -4
  15. package/dist/analyzer/deprecatedSymbols.js.map +1 -1
  16. package/dist/analyzer/namedTuples.js +0 -8
  17. package/dist/analyzer/namedTuples.js.map +1 -1
  18. package/dist/analyzer/operations.js +3 -2
  19. package/dist/analyzer/operations.js.map +1 -1
  20. package/dist/analyzer/packageTypeVerifier.js +10 -10
  21. package/dist/analyzer/parseTreeUtils.d.ts +6 -3
  22. package/dist/analyzer/parseTreeUtils.js +75 -46
  23. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  24. package/dist/analyzer/patternMatching.js +19 -13
  25. package/dist/analyzer/patternMatching.js.map +1 -1
  26. package/dist/analyzer/protocols.js +32 -13
  27. package/dist/analyzer/protocols.js.map +1 -1
  28. package/dist/analyzer/scope.d.ts +14 -7
  29. package/dist/analyzer/scope.js +28 -17
  30. package/dist/analyzer/scope.js.map +1 -1
  31. package/dist/analyzer/scopeUtils.js +3 -3
  32. package/dist/analyzer/scopeUtils.js.map +1 -1
  33. package/dist/analyzer/typeEvaluator.js +252 -207
  34. package/dist/analyzer/typeEvaluator.js.map +1 -1
  35. package/dist/analyzer/typeEvaluatorTypes.d.ts +5 -1
  36. package/dist/analyzer/typeGuards.js +35 -110
  37. package/dist/analyzer/typeGuards.js.map +1 -1
  38. package/dist/analyzer/typeUtils.js +6 -8
  39. package/dist/analyzer/typeUtils.js.map +1 -1
  40. package/dist/analyzer/typedDicts.js +4 -6
  41. package/dist/analyzer/typedDicts.js.map +1 -1
  42. package/dist/analyzer/types.js +13 -0
  43. package/dist/analyzer/types.js.map +1 -1
  44. package/dist/common/console.d.ts +12 -1
  45. package/dist/common/console.js +22 -3
  46. package/dist/common/console.js.map +1 -1
  47. package/dist/common/diagnostic.d.ts +4 -0
  48. package/dist/common/diagnostic.js +10 -4
  49. package/dist/common/diagnostic.js.map +1 -1
  50. package/dist/common/envVarUtils.d.ts +2 -2
  51. package/dist/common/envVarUtils.js +1 -2
  52. package/dist/common/envVarUtils.js.map +1 -1
  53. package/dist/common/languageServerInterface.d.ts +6 -3
  54. package/dist/common/languageServerInterface.js +11 -0
  55. package/dist/common/languageServerInterface.js.map +1 -1
  56. package/dist/common/uri/uri.d.ts +2 -0
  57. package/dist/common/uri/uri.js +3 -1
  58. package/dist/common/uri/uri.js.map +1 -1
  59. package/dist/languageServerBase.d.ts +3 -2
  60. package/dist/languageServerBase.js +13 -35
  61. package/dist/languageServerBase.js.map +1 -1
  62. package/dist/languageService/callHierarchyProvider.js +5 -2
  63. package/dist/languageService/callHierarchyProvider.js.map +1 -1
  64. package/dist/languageService/completionProvider.js +12 -8
  65. package/dist/languageService/completionProvider.js.map +1 -1
  66. package/dist/languageService/documentSymbolCollector.js +1 -1
  67. package/dist/languageService/dynamicFeature.d.ts +18 -0
  68. package/dist/languageService/dynamicFeature.js +54 -0
  69. package/dist/languageService/dynamicFeature.js.map +1 -0
  70. package/dist/languageService/fileWatcherDynamicFeature.d.ts +12 -0
  71. package/dist/languageService/fileWatcherDynamicFeature.js +49 -0
  72. package/dist/languageService/fileWatcherDynamicFeature.js.map +1 -0
  73. package/dist/languageService/referencesProvider.js +3 -2
  74. package/dist/languageService/referencesProvider.js.map +1 -1
  75. package/dist/localization/package.nls.cs.json +28 -26
  76. package/dist/localization/package.nls.de.json +28 -26
  77. package/dist/localization/package.nls.en-us.json +1 -1
  78. package/dist/localization/package.nls.es.json +27 -25
  79. package/dist/localization/package.nls.fr.json +28 -26
  80. package/dist/localization/package.nls.it.json +28 -26
  81. package/dist/localization/package.nls.ja.json +28 -26
  82. package/dist/localization/package.nls.ko.json +28 -26
  83. package/dist/localization/package.nls.pl.json +27 -25
  84. package/dist/localization/package.nls.pt-br.json +28 -26
  85. package/dist/localization/package.nls.qps-ploc.json +25 -23
  86. package/dist/localization/package.nls.ru.json +28 -26
  87. package/dist/localization/package.nls.tr.json +28 -26
  88. package/dist/localization/package.nls.zh-cn.json +28 -26
  89. package/dist/localization/package.nls.zh-tw.json +28 -26
  90. package/dist/parser/parseNodes.d.ts +2 -2
  91. package/dist/parser/tokenizer.js +7 -1
  92. package/dist/parser/tokenizer.js.map +1 -1
  93. package/dist/tests/checker.test.js +8 -0
  94. package/dist/tests/checker.test.js.map +1 -1
  95. package/dist/tests/envVarUtils.test.js +20 -0
  96. package/dist/tests/envVarUtils.test.js.map +1 -1
  97. package/dist/tests/fourslash/{completions.importDunderNames.fourslash.js → completions.import.dunderNames.fourslash.js} +1 -1
  98. package/dist/tests/fourslash/completions.import.dunderNames.fourslash.js.map +1 -0
  99. package/dist/tests/fourslash/{completions.importsDuplicates.fourslash.js → completions.import.duplicates.fourslash.js} +1 -1
  100. package/dist/tests/fourslash/{completions.importsDuplicates.fourslash.js.map → completions.import.duplicates.fourslash.js.map} +1 -1
  101. package/dist/tests/fourslash/completions.import.exactMatch.fourslash.js +29 -0
  102. package/dist/tests/fourslash/completions.import.exactMatch.fourslash.js.map +1 -0
  103. package/dist/tests/fourslash/completions.import.excludeAlreadyImported.fourslash.js +14 -0
  104. package/dist/tests/fourslash/completions.import.excludeAlreadyImported.fourslash.js.map +1 -0
  105. package/dist/tests/fourslash/completions.import.interimFile.fourslash.disabled.d.ts +1 -0
  106. package/dist/tests/fourslash/{completions.importInterimFile.fourslash.disabled.js → completions.import.interimFile.fourslash.disabled.js} +1 -1
  107. package/dist/tests/fourslash/completions.import.interimFile.fourslash.disabled.js.map +1 -0
  108. package/dist/tests/fourslash/{completions.importPrivateNoPytyped.fourslash.js → completions.import.privateNoPytyped.fourslash.js} +1 -1
  109. package/dist/tests/fourslash/completions.import.privateNoPytyped.fourslash.js.map +1 -0
  110. package/dist/tests/fourslash/{completions.importPytyped.fourslash.js → completions.import.pytyped.fourslash.js} +1 -1
  111. package/dist/tests/fourslash/completions.import.pytyped.fourslash.js.map +1 -0
  112. package/dist/tests/fourslash/{completions.importPytypedLocal.fourslash.js → completions.import.pytypedLocal.fourslash.js} +1 -1
  113. package/dist/tests/fourslash/completions.import.pytypedLocal.fourslash.js.map +1 -0
  114. package/dist/tests/fourslash/completions.import.submodule.fourslash.d.ts +1 -0
  115. package/dist/tests/fourslash/{completions.importSubmodule.fourslash.js → completions.import.submodule.fourslash.js} +1 -1
  116. package/dist/tests/fourslash/completions.import.submodule.fourslash.js.map +1 -0
  117. package/dist/tests/harness/fourslash/testState.js +1 -1
  118. package/dist/tests/harness/fourslash/testState.js.map +1 -1
  119. package/dist/tests/harness/vfs/pathValidation.js +2 -1
  120. package/dist/tests/harness/vfs/pathValidation.js.map +1 -1
  121. package/dist/tests/parser.test.js +7 -2
  122. package/dist/tests/parser.test.js.map +1 -1
  123. package/dist/tests/typeEvaluator1.test.js +60 -480
  124. package/dist/tests/typeEvaluator1.test.js.map +1 -1
  125. package/dist/tests/typeEvaluator2.test.js +0 -482
  126. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  127. package/dist/tests/typeEvaluator3.test.js +0 -604
  128. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  129. package/dist/tests/typeEvaluator4.test.js +5 -423
  130. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  131. package/dist/tests/typeEvaluator5.test.js +2 -2
  132. package/dist/tests/typeEvaluator5.test.js.map +1 -1
  133. package/dist/tests/typeEvaluator6.test.d.ts +1 -0
  134. package/dist/tests/typeEvaluator6.test.js +712 -0
  135. package/dist/tests/typeEvaluator6.test.js.map +1 -0
  136. package/dist/tests/typeEvaluator7.test.d.ts +1 -0
  137. package/dist/tests/typeEvaluator7.test.js +677 -0
  138. package/dist/tests/typeEvaluator7.test.js.map +1 -0
  139. package/dist/tests/typeEvaluator8.test.d.ts +1 -0
  140. package/dist/tests/typeEvaluator8.test.js +660 -0
  141. package/dist/tests/typeEvaluator8.test.js.map +1 -0
  142. package/dist/workspaceFactory.d.ts +3 -1
  143. package/dist/workspaceFactory.js.map +1 -1
  144. package/package.json +1 -1
  145. package/dist/tests/fourslash/completions.importDunderNames.fourslash.js.map +0 -1
  146. package/dist/tests/fourslash/completions.importInterimFile.fourslash.disabled.js.map +0 -1
  147. package/dist/tests/fourslash/completions.importPrivateNoPytyped.fourslash.js.map +0 -1
  148. package/dist/tests/fourslash/completions.importPytyped.fourslash.js.map +0 -1
  149. package/dist/tests/fourslash/completions.importPytypedLocal.fourslash.js.map +0 -1
  150. package/dist/tests/fourslash/completions.importSubmodule.fourslash.js.map +0 -1
  151. /package/dist/tests/fourslash/{completions.importDunderNames.fourslash.d.ts → completions.import.dunderNames.fourslash.d.ts} +0 -0
  152. /package/dist/tests/fourslash/{completions.importPrivateNoPytyped.fourslash.d.ts → completions.import.duplicates.fourslash.d.ts} +0 -0
  153. /package/dist/tests/fourslash/{completions.importInterimFile.fourslash.disabled.d.ts → completions.import.exactMatch.fourslash.d.ts} +0 -0
  154. /package/dist/tests/fourslash/{completions.importSubmodule.fourslash.d.ts → completions.import.excludeAlreadyImported.fourslash.d.ts} +0 -0
  155. /package/dist/tests/fourslash/{completions.importPytyped.fourslash.d.ts → completions.import.privateNoPytyped.fourslash.d.ts} +0 -0
  156. /package/dist/tests/fourslash/{completions.importPytypedLocal.fourslash.d.ts → completions.import.pytyped.fourslash.d.ts} +0 -0
  157. /package/dist/tests/fourslash/{completions.importsDuplicates.fourslash.d.ts → completions.import.pytypedLocal.fourslash.d.ts} +0 -0
@@ -1685,7 +1685,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1685
1685
  // where the type isn't declared in this class but is in
1686
1686
  // a parent class.
1687
1687
  if (!((_a = getDeclaredTypeOfSymbol(symbol, expression)) === null || _a === void 0 ? void 0 : _a.type) &&
1688
- symbolWithScope.scope.type === 2 /* ScopeType.Class */) {
1688
+ symbolWithScope.scope.type === 3 /* ScopeType.Class */) {
1689
1689
  const enclosingClass = ParseTreeUtils.getEnclosingClassOrFunction(expression);
1690
1690
  if (enclosingClass && enclosingClass.nodeType === 10 /* ParseNodeType.Class */) {
1691
1691
  const classTypeInfo = getTypeOfClass(enclosingClass);
@@ -2203,7 +2203,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2203
2203
  const fileInfo = AnalyzerNodeInfo.getFileInfo(nameNode);
2204
2204
  // If this is a class scope and there is no type declared for this class variable,
2205
2205
  // see if a parent class has a type declared.
2206
- if (declaredType === undefined && symbolWithScope.scope.type === 2 /* ScopeType.Class */) {
2206
+ if (declaredType === undefined && symbolWithScope.scope.type === 3 /* ScopeType.Class */) {
2207
2207
  const containingClass = ParseTreeUtils.getEnclosingClass(nameNode);
2208
2208
  if (containingClass) {
2209
2209
  const classType = getTypeOfClass(containingClass);
@@ -2244,7 +2244,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2244
2244
  // variable that can be overridden by a child class, use the more general
2245
2245
  // version by stripping off the literal.
2246
2246
  const scope = ScopeUtils.getScopeForNode(nameNode);
2247
- if ((scope === null || scope === void 0 ? void 0 : scope.type) === 2 /* ScopeType.Class */) {
2247
+ if ((scope === null || scope === void 0 ? void 0 : scope.type) === 3 /* ScopeType.Class */) {
2248
2248
  if (types_1.TypeBase.isInstance(destType) &&
2249
2249
  !(0, symbolNameUtils_1.isConstantName)(nameValue) &&
2250
2250
  !isFinalVariable(symbolWithScope.symbol)) {
@@ -2945,143 +2945,131 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2945
2945
  let type;
2946
2946
  let isIncomplete = false;
2947
2947
  const allowForwardReferences = (flags & 4 /* EvaluatorFlags.AllowForwardReferences */) !== 0 || fileInfo.isStubFile;
2948
- // Does this name refer to a PEP 695-style type parameter?
2949
- const typeParamSymbol = AnalyzerNodeInfo.getTypeParameterSymbol(node);
2950
- if (typeParamSymbol) {
2951
- symbol = typeParamSymbol;
2952
- (0, debug_1.assert)(symbol.getDeclarations().length === 1);
2953
- const decl = (0, symbolUtils_1.getLastTypedDeclarationForSymbol)(symbol);
2954
- (0, debug_1.assert)((decl === null || decl === void 0 ? void 0 : decl.type) === 3 /* DeclarationType.TypeParameter */);
2955
- type = getTypeOfTypeParameter(decl.node);
2948
+ // Look for the scope that contains the value definition and
2949
+ // see if it has a declared type.
2950
+ let symbolWithScope = lookUpSymbolRecursive(node, name, !allowForwardReferences, allowForwardReferences && (flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0);
2951
+ if (!symbolWithScope) {
2952
+ // If the node is part of a "from X import Y as Z" statement and the node
2953
+ // is the "Y" (non-aliased) name, we need to look up the alias symbol
2954
+ // since the non-aliased name is not in the symbol table.
2955
+ const alias = getAliasFromImport(node);
2956
+ if (alias) {
2957
+ symbolWithScope = lookUpSymbolRecursive(alias, alias.value, !allowForwardReferences, allowForwardReferences && (flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0);
2958
+ }
2959
+ }
2960
+ if (symbolWithScope) {
2961
+ let useCodeFlowAnalysis = !allowForwardReferences;
2962
+ // If the symbol is implicitly imported from the builtin
2963
+ // scope, there's no need to use code flow analysis.
2964
+ if (symbolWithScope.scope.type === 5 /* ScopeType.Builtin */) {
2965
+ useCodeFlowAnalysis = false;
2966
+ }
2967
+ symbol = symbolWithScope.symbol;
2956
2968
  setSymbolAccessed(fileInfo, symbol, node);
2957
- }
2958
- else {
2959
- // Look for the scope that contains the value definition and
2960
- // see if it has a declared type.
2961
- let symbolWithScope = lookUpSymbolRecursive(node, name, !allowForwardReferences, allowForwardReferences && (flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0);
2962
- if (!symbolWithScope) {
2963
- // If the node is part of a "from X import Y as Z" statement and the node
2964
- // is the "Y" (non-aliased) name, we need to look up the alias symbol
2965
- // since the non-aliased name is not in the symbol table.
2966
- const alias = getAliasFromImport(node);
2967
- if (alias) {
2968
- symbolWithScope = lookUpSymbolRecursive(alias, alias.value, !allowForwardReferences, allowForwardReferences && (flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0);
2969
+ // If we're not supposed to be analyzing this function, skip the remaining work
2970
+ // to determine the name's type. Simply evaluate its type as Any.
2971
+ if (!fileInfo.diagnosticRuleSet.analyzeUnannotatedFunctions) {
2972
+ const containingFunction = ParseTreeUtils.getEnclosingFunction(node);
2973
+ if (containingFunction && ParseTreeUtils.isUnannotatedFunction(containingFunction)) {
2974
+ return {
2975
+ type: types_1.AnyType.create(),
2976
+ isIncomplete: false,
2977
+ };
2969
2978
  }
2970
2979
  }
2971
- if (symbolWithScope) {
2972
- let useCodeFlowAnalysis = !allowForwardReferences;
2973
- // If the symbol is implicitly imported from the builtin
2974
- // scope, there's no need to use code flow analysis.
2975
- if (symbolWithScope.scope.type === 4 /* ScopeType.Builtin */) {
2976
- useCodeFlowAnalysis = false;
2977
- }
2978
- symbol = symbolWithScope.symbol;
2979
- setSymbolAccessed(fileInfo, symbol, node);
2980
- // If we're not supposed to be analyzing this function, skip the remaining work
2981
- // to determine the name's type. Simply evaluate its type as Any.
2982
- if (!fileInfo.diagnosticRuleSet.analyzeUnannotatedFunctions) {
2983
- const containingFunction = ParseTreeUtils.getEnclosingFunction(node);
2984
- if (containingFunction && ParseTreeUtils.isUnannotatedFunction(containingFunction)) {
2985
- return {
2986
- type: types_1.AnyType.create(),
2987
- isIncomplete: false,
2988
- };
2989
- }
2990
- }
2991
- // Get the effective type (either the declared type or the inferred type).
2992
- // If we're using code flow analysis, pass the usage node so we consider
2993
- // only the assignment nodes that are reachable from this usage.
2994
- const effectiveTypeInfo = getEffectiveTypeOfSymbolForUsage(symbol, useCodeFlowAnalysis ? node : undefined);
2995
- let effectiveType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(effectiveTypeInfo.type);
2996
- if (effectiveTypeInfo.isIncomplete) {
2997
- if ((0, types_1.isUnbound)(effectiveType)) {
2998
- effectiveType = types_1.UnknownType.create(/* isIncomplete */ true);
2999
- }
3000
- isIncomplete = true;
2980
+ // Get the effective type (either the declared type or the inferred type).
2981
+ // If we're using code flow analysis, pass the usage node so we consider
2982
+ // only the assignment nodes that are reachable from this usage.
2983
+ const effectiveTypeInfo = getEffectiveTypeOfSymbolForUsage(symbol, useCodeFlowAnalysis ? node : undefined);
2984
+ let effectiveType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(effectiveTypeInfo.type);
2985
+ if (effectiveTypeInfo.isIncomplete) {
2986
+ if ((0, types_1.isUnbound)(effectiveType)) {
2987
+ effectiveType = types_1.UnknownType.create(/* isIncomplete */ true);
3001
2988
  }
3002
- if (effectiveTypeInfo.isRecursiveDefinition && isNodeReachable(node)) {
3003
- addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.recursiveDefinition().format({ name }), node);
3004
- }
3005
- const isSpecialBuiltIn = !!effectiveType && (0, types_1.isInstantiableClass)(effectiveType) && types_1.ClassType.isSpecialBuiltIn(effectiveType);
3006
- type = effectiveType;
3007
- if (useCodeFlowAnalysis && !isSpecialBuiltIn) {
3008
- // See if code flow analysis can tell us anything more about the type.
3009
- // If the symbol is declared outside of our execution scope, use its effective
3010
- // type. If it's declared inside our execution scope, it generally starts
3011
- // as unbound at the start of the code flow.
3012
- let typeAtStart = effectiveType;
3013
- let isTypeAtStartIncomplete = false;
3014
- if (!symbolWithScope.isBeyondExecutionScope && symbol.isInitiallyUnbound()) {
3015
- typeAtStart = types_1.UnboundType.create();
3016
- // Is this a module-level scope? If so, see if it's an alias of a builtin.
3017
- if (symbolWithScope.scope.type === 3 /* ScopeType.Module */) {
3018
- (0, debug_1.assert)(symbolWithScope.scope.parent);
3019
- const builtInSymbol = symbolWithScope.scope.parent.lookUpSymbol(name);
3020
- if (builtInSymbol) {
3021
- const builtInEffectiveType = getEffectiveTypeOfSymbolForUsage(builtInSymbol);
3022
- typeAtStart = builtInEffectiveType.type;
3023
- }
3024
- }
3025
- }
3026
- if (symbolWithScope.isBeyondExecutionScope) {
3027
- const outerScopeTypeResult = getCodeFlowTypeForCapturedVariable(node, symbolWithScope, effectiveType);
3028
- if (outerScopeTypeResult === null || outerScopeTypeResult === void 0 ? void 0 : outerScopeTypeResult.type) {
3029
- type = outerScopeTypeResult.type;
3030
- typeAtStart = type;
3031
- isTypeAtStartIncomplete = !!outerScopeTypeResult.isIncomplete;
2989
+ isIncomplete = true;
2990
+ }
2991
+ if (effectiveTypeInfo.isRecursiveDefinition && isNodeReachable(node)) {
2992
+ addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.recursiveDefinition().format({ name }), node);
2993
+ }
2994
+ const isSpecialBuiltIn = !!effectiveType && (0, types_1.isInstantiableClass)(effectiveType) && types_1.ClassType.isSpecialBuiltIn(effectiveType);
2995
+ type = effectiveType;
2996
+ if (useCodeFlowAnalysis && !isSpecialBuiltIn) {
2997
+ // See if code flow analysis can tell us anything more about the type.
2998
+ // If the symbol is declared outside of our execution scope, use its effective
2999
+ // type. If it's declared inside our execution scope, it generally starts
3000
+ // as unbound at the start of the code flow.
3001
+ let typeAtStart = effectiveType;
3002
+ let isTypeAtStartIncomplete = false;
3003
+ if (!symbolWithScope.isBeyondExecutionScope && symbol.isInitiallyUnbound()) {
3004
+ typeAtStart = types_1.UnboundType.create();
3005
+ // Is this a module-level scope? If so, see if it's an alias of a builtin.
3006
+ if (symbolWithScope.scope.type === 4 /* ScopeType.Module */) {
3007
+ (0, debug_1.assert)(symbolWithScope.scope.parent);
3008
+ const builtInSymbol = symbolWithScope.scope.parent.lookUpSymbol(name);
3009
+ if (builtInSymbol) {
3010
+ const builtInEffectiveType = getEffectiveTypeOfSymbolForUsage(builtInSymbol);
3011
+ typeAtStart = builtInEffectiveType.type;
3032
3012
  }
3033
3013
  }
3034
- const codeFlowTypeResult = getFlowTypeOfReference(node, /* startNode */ undefined, {
3035
- targetSymbolId: symbol.id,
3036
- typeAtStart: { type: typeAtStart, isIncomplete: isTypeAtStartIncomplete },
3037
- skipConditionalNarrowing: (flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0,
3038
- });
3039
- if (codeFlowTypeResult.type) {
3040
- type = codeFlowTypeResult.type;
3041
- }
3042
- if (codeFlowTypeResult.isIncomplete) {
3043
- isIncomplete = true;
3014
+ }
3015
+ if (symbolWithScope.isBeyondExecutionScope) {
3016
+ const outerScopeTypeResult = getCodeFlowTypeForCapturedVariable(node, symbolWithScope, effectiveType);
3017
+ if (outerScopeTypeResult === null || outerScopeTypeResult === void 0 ? void 0 : outerScopeTypeResult.type) {
3018
+ type = outerScopeTypeResult.type;
3019
+ typeAtStart = type;
3020
+ isTypeAtStartIncomplete = !!outerScopeTypeResult.isIncomplete;
3044
3021
  }
3045
3022
  }
3046
- // Detect, report, and fill in missing type arguments if appropriate.
3047
- type = reportMissingTypeArguments(node, type, flags);
3048
- if ((flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0) {
3049
- // Verify that the name does not refer to a (non type alias) variable.
3050
- if (effectiveTypeInfo.includesVariableDecl && !type.typeAliasInfo) {
3051
- let isAllowedTypeForVariable = (0, types_1.isTypeVar)(type) || (0, typeUtils_1.isTypeAliasPlaceholder)(type);
3052
- if ((0, types_1.isClass)(type) &&
3053
- !type.includeSubclasses &&
3054
- !symbol.hasTypedDeclarations() &&
3055
- types_1.ClassType.isValidTypeAliasClass(type)) {
3056
- // This check exempts class types that are created by calling
3057
- // NewType, NamedTuple, etc.
3058
- isAllowedTypeForVariable = true;
3059
- }
3060
- // Disable for assignments in the typings.pyi file, since it defines special forms.
3061
- if (!isAllowedTypeForVariable && !fileInfo.isTypingStubFile) {
3062
- // This might be a union that was previously a type alias
3063
- // but was reconstituted in such a way that we lost the
3064
- // typeAliasInfo. Avoid the false positive error by suppressing
3065
- // the error when it looks like a plausible type alias type.
3066
- if (effectiveTypeInfo.includesIllegalTypeAliasDecl ||
3067
- !types_1.TypeBase.isInstantiable(type) ||
3068
- (flags & 2 /* EvaluatorFlags.DoNotSpecialize */) !== 0) {
3069
- addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.typeAnnotationVariable(), node);
3070
- type = types_1.UnknownType.create();
3071
- }
3023
+ const codeFlowTypeResult = getFlowTypeOfReference(node, /* startNode */ undefined, {
3024
+ targetSymbolId: symbol.id,
3025
+ typeAtStart: { type: typeAtStart, isIncomplete: isTypeAtStartIncomplete },
3026
+ skipConditionalNarrowing: (flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0,
3027
+ });
3028
+ if (codeFlowTypeResult.type) {
3029
+ type = codeFlowTypeResult.type;
3030
+ }
3031
+ if (codeFlowTypeResult.isIncomplete) {
3032
+ isIncomplete = true;
3033
+ }
3034
+ }
3035
+ // Detect, report, and fill in missing type arguments if appropriate.
3036
+ type = reportMissingTypeArguments(node, type, flags);
3037
+ if ((flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0) {
3038
+ // Verify that the name does not refer to a (non type alias) variable.
3039
+ if (effectiveTypeInfo.includesVariableDecl && !type.typeAliasInfo) {
3040
+ let isAllowedTypeForVariable = (0, types_1.isTypeVar)(type) || (0, typeUtils_1.isTypeAliasPlaceholder)(type);
3041
+ if ((0, types_1.isClass)(type) &&
3042
+ !type.includeSubclasses &&
3043
+ !symbol.hasTypedDeclarations() &&
3044
+ types_1.ClassType.isValidTypeAliasClass(type)) {
3045
+ // This check exempts class types that are created by calling
3046
+ // NewType, NamedTuple, etc.
3047
+ isAllowedTypeForVariable = true;
3048
+ }
3049
+ // Disable for assignments in the typings.pyi file, since it defines special forms.
3050
+ if (!isAllowedTypeForVariable && !fileInfo.isTypingStubFile) {
3051
+ // This might be a union that was previously a type alias
3052
+ // but was reconstituted in such a way that we lost the
3053
+ // typeAliasInfo. Avoid the false positive error by suppressing
3054
+ // the error when it looks like a plausible type alias type.
3055
+ if (effectiveTypeInfo.includesIllegalTypeAliasDecl ||
3056
+ !types_1.TypeBase.isInstantiable(type) ||
3057
+ (flags & 2 /* EvaluatorFlags.DoNotSpecialize */) !== 0) {
3058
+ addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.typeAnnotationVariable(), node);
3059
+ type = types_1.UnknownType.create();
3072
3060
  }
3073
3061
  }
3074
3062
  }
3075
3063
  }
3064
+ }
3065
+ else {
3066
+ // Handle the special case of "reveal_type" and "reveal_locals".
3067
+ if (name === 'reveal_type' || name === 'reveal_locals') {
3068
+ type = types_1.AnyType.create();
3069
+ }
3076
3070
  else {
3077
- // Handle the special case of "reveal_type" and "reveal_locals".
3078
- if (name === 'reveal_type' || name === 'reveal_locals') {
3079
- type = types_1.AnyType.create();
3080
- }
3081
- else {
3082
- addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUndefinedVariable, localize_1.LocMessage.symbolIsUndefined().format({ name }), node);
3083
- type = types_1.UnknownType.create();
3084
- }
3071
+ addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUndefinedVariable, localize_1.LocMessage.symbolIsUndefined().format({ name }), node);
3072
+ type = types_1.UnknownType.create();
3085
3073
  }
3086
3074
  }
3087
3075
  if ((0, types_1.isParamSpec)(type)) {
@@ -3145,6 +3133,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3145
3133
  ScopeUtils.getScopeForNode(decl.node) === symbolWithScope.scope)) {
3146
3134
  return undefined;
3147
3135
  }
3136
+ // If the symbol is a non-final variable in the global scope, it is not
3137
+ // eligible because it could be modified by other modules.
3138
+ if (!decls.every((decl) => {
3139
+ var _a;
3140
+ return decl.type !== 1 /* DeclarationType.Variable */ ||
3141
+ decl.isFinal ||
3142
+ ((_a = ScopeUtils.getScopeForNode(decl.node)) === null || _a === void 0 ? void 0 : _a.type) !== 4 /* ScopeType.Module */;
3143
+ })) {
3144
+ return undefined;
3145
+ }
3148
3146
  // If the symbol is a variable captured by an inner function
3149
3147
  // or lambda, see if we can infer the type from the outer scope.
3150
3148
  const scopeHierarchy = ScopeUtils.getScopeHierarchy(node, symbolWithScope.scope);
@@ -5852,7 +5850,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5852
5850
  scope = ScopeUtils.getScopeForNode(curNode);
5853
5851
  // Stop when we get a valid scope that's not a list comprehension
5854
5852
  // scope. That includes lambdas, functions, classes, and modules.
5855
- if (scope && scope.type !== 0 /* ScopeType.ListComprehension */) {
5853
+ if (scope && scope.type !== 1 /* ScopeType.ListComprehension */) {
5856
5854
  break;
5857
5855
  }
5858
5856
  curNode = curNode.parent;
@@ -8146,7 +8144,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8146
8144
  }
8147
8145
  }
8148
8146
  // Calculate the return type.
8149
- let returnType = getFunctionEffectiveReturnType(type, matchResults.argParams);
8147
+ let returnType = getFunctionEffectiveReturnType(type, { args: matchResults.argParams, errorNode });
8150
8148
  if (condition.length > 0) {
8151
8149
  returnType = types_1.TypeBase.cloneForCondition(returnType, condition);
8152
8150
  }
@@ -9202,8 +9200,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9202
9200
  if (!(0, types_1.isClassInstance)(arg1Type) || !(0, typeUtils_1.isTupleClass)(arg1Type) || arg1Type.tupleTypeArguments === undefined) {
9203
9201
  return undefined;
9204
9202
  }
9205
- const classType = types_1.ClassType.createInstantiable(className, ParseTreeUtils.getClassFullName(errorNode, fileInfo.moduleName, className), fileInfo.moduleName, fileInfo.fileUri, 1073741824 /* ClassTypeFlags.ValidTypeAliasClass */, ParseTreeUtils.getTypeSourceId(errorNode),
9206
- /* declaredMetaclass */ undefined, arg1Type.details.effectiveMetaclass);
9203
+ const classType = types_1.ClassType.createInstantiable(className, ParseTreeUtils.getClassFullName(errorNode, fileInfo.moduleName, className), fileInfo.moduleName, fileInfo.fileUri, 1073741824 /* ClassTypeFlags.ValidTypeAliasClass */, ParseTreeUtils.getTypeSourceId(errorNode), metaclass, arg1Type.details.effectiveMetaclass);
9207
9204
  arg1Type.tupleTypeArguments.forEach((typeArg) => {
9208
9205
  const specializedType = makeTopLevelTypeVarsConcrete(typeArg.type);
9209
9206
  if ((0, typeUtils_1.isEffectivelyInstantiable)(specializedType)) {
@@ -9362,6 +9359,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9362
9359
  const keyTypes = [];
9363
9360
  const valueTypes = [];
9364
9361
  let isIncomplete = false;
9362
+ let typeErrors = false;
9365
9363
  // Handle TypedDict's as a special case.
9366
9364
  if (types_1.ClassType.isTypedDictClass(concreteExpectedType)) {
9367
9365
  // Remove any conditions associated with the type so the resulting type isn't
@@ -9369,13 +9367,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9369
9367
  concreteExpectedType = types_1.TypeBase.cloneForCondition(concreteExpectedType, undefined);
9370
9368
  const expectedTypedDictEntries = (0, typedDicts_1.getTypedDictMembersForClass)(evaluatorInterface, concreteExpectedType);
9371
9369
  // Infer the key and value types if possible.
9372
- if (getKeyAndValueTypesFromDictionary(node, keyTypes, valueTypes,
9370
+ const keyValueTypeResult = getKeyAndValueTypesFromDictionary(node, keyTypes, valueTypes,
9373
9371
  /* forceStrictInference */ true,
9374
9372
  /* isValueTypeInvariant */ true,
9375
9373
  /* expectedKeyType */ undefined,
9376
- /* expectedValueType */ undefined, expectedTypedDictEntries, expectedDiagAddendum)) {
9374
+ /* expectedValueType */ undefined, expectedTypedDictEntries, expectedDiagAddendum);
9375
+ if (keyValueTypeResult.isIncomplete) {
9377
9376
  isIncomplete = true;
9378
9377
  }
9378
+ if (keyValueTypeResult.typeErrors) {
9379
+ typeErrors = true;
9380
+ }
9379
9381
  const resultTypedDict = (0, typedDicts_1.assignToTypedDict)(evaluatorInterface, concreteExpectedType, keyTypes, valueTypes,
9380
9382
  // Don't overwrite existing expectedDiagAddendum messages if they were
9381
9383
  // already provided by getKeyValueTypesFromDictionary.
@@ -9423,10 +9425,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9423
9425
  }
9424
9426
  }
9425
9427
  // Infer the key and value types if possible.
9426
- if (getKeyAndValueTypesFromDictionary(node, keyTypes, valueTypes,
9427
- /* forceStrictInference */ true, isValueTypeInvariant, expectedKeyType, expectedValueType, undefined, expectedDiagAddendum)) {
9428
+ const keyValueResult = getKeyAndValueTypesFromDictionary(node, keyTypes, valueTypes,
9429
+ /* forceStrictInference */ true, isValueTypeInvariant, expectedKeyType, expectedValueType, undefined, expectedDiagAddendum);
9430
+ if (keyValueResult.isIncomplete) {
9428
9431
  isIncomplete = true;
9429
9432
  }
9433
+ if (keyValueResult.typeErrors) {
9434
+ typeErrors = true;
9435
+ }
9430
9436
  const specializedKeyType = inferTypeArgFromExpectedEntryType((0, typeUtils_1.makeInferenceContext)(expectedKeyType), keyTypes.map((result) => result.type),
9431
9437
  /* isNarrowable */ false);
9432
9438
  const specializedValueType = inferTypeArgFromExpectedEntryType((0, typeUtils_1.makeInferenceContext)(expectedValueType), valueTypes.map((result) => result.type), !isValueTypeInvariant);
@@ -9434,7 +9440,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9434
9440
  return undefined;
9435
9441
  }
9436
9442
  const type = getBuiltInObject(node, 'dict', [specializedKeyType, specializedValueType]);
9437
- return { type, isIncomplete };
9443
+ return { type, isIncomplete, typeErrors };
9438
9444
  }
9439
9445
  // Attempts to infer the type of a dictionary statement. If hasExpectedType
9440
9446
  // is true, strict inference is used for the subexpressions.
@@ -9446,12 +9452,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9446
9452
  const valueTypeResults = [];
9447
9453
  let isEmptyContainer = false;
9448
9454
  let isIncomplete = false;
9455
+ let typeErrors = false;
9449
9456
  // Infer the key and value types if possible.
9450
- if (getKeyAndValueTypesFromDictionary(node, keyTypeResults, valueTypeResults,
9457
+ const keyValueResult = getKeyAndValueTypesFromDictionary(node, keyTypeResults, valueTypeResults,
9451
9458
  /* forceStrictInference */ hasExpectedType,
9452
- /* isValueTypeInvariant */ false)) {
9459
+ /* isValueTypeInvariant */ false);
9460
+ if (keyValueResult.isIncomplete) {
9453
9461
  isIncomplete = true;
9454
9462
  }
9463
+ if (keyValueResult.typeErrors) {
9464
+ typeErrors = true;
9465
+ }
9455
9466
  // Strip any literal values.
9456
9467
  const keyTypes = keyTypeResults.map((t) => stripLiteralValue(t.type));
9457
9468
  const valueTypes = valueTypeResults.map((t) => stripLiteralValue(t.type));
@@ -9485,10 +9496,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9485
9496
  return { type: types_1.UnknownType.create() };
9486
9497
  }
9487
9498
  }
9488
- return { type, isIncomplete };
9499
+ return { type, isIncomplete, typeErrors };
9489
9500
  }
9490
9501
  function getKeyAndValueTypesFromDictionary(node, keyTypes, valueTypes, forceStrictInference, isValueTypeInvariant, expectedKeyType, expectedValueType, expectedTypedDictEntries, expectedDiagAddendum) {
9491
9502
  let isIncomplete = false;
9503
+ let typeErrors = false;
9492
9504
  // Infer the key and value types if possible.
9493
9505
  node.entries.forEach((entryNode, index) => {
9494
9506
  var _a, _b, _c, _d;
@@ -9499,6 +9511,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9499
9511
  if (keyTypeResult.isIncomplete) {
9500
9512
  isIncomplete = true;
9501
9513
  }
9514
+ if (keyTypeResult.typeErrors) {
9515
+ typeErrors = true;
9516
+ }
9502
9517
  const keyType = keyTypeResult.type;
9503
9518
  if (!keyTypeResult.isIncomplete && !keyTypeResult.typeErrors) {
9504
9519
  verifySetEntryOrDictKeyIsHashable(entryNode.keyExpression, keyType, /* isDictKey */ true);
@@ -9537,6 +9552,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9537
9552
  if (valueTypeResult.isIncomplete) {
9538
9553
  isIncomplete = true;
9539
9554
  }
9555
+ if (valueTypeResult.typeErrors) {
9556
+ typeErrors = true;
9557
+ }
9540
9558
  if (forceStrictInference || index < maxEntriesToUseForInference) {
9541
9559
  // If an existing key has the same literal type, delete the previous
9542
9560
  // key since we're overwriting it here.
@@ -9572,6 +9590,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9572
9590
  if (unexpandedTypeResult.isIncomplete) {
9573
9591
  isIncomplete = true;
9574
9592
  }
9593
+ if (unexpandedTypeResult.typeErrors) {
9594
+ typeErrors = true;
9595
+ }
9575
9596
  const unexpandedType = unexpandedTypeResult.type;
9576
9597
  if ((0, types_1.isAnyOrUnknown)(unexpandedType)) {
9577
9598
  addUnknown = false;
@@ -9629,6 +9650,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9629
9650
  if (dictEntryTypeResult.isIncomplete) {
9630
9651
  isIncomplete = true;
9631
9652
  }
9653
+ if (dictEntryTypeResult.typeErrors) {
9654
+ typeErrors = true;
9655
+ }
9632
9656
  // The result should be a tuple.
9633
9657
  if ((0, types_1.isClassInstance)(dictEntryType) && (0, typeUtils_1.isTupleClass)(dictEntryType)) {
9634
9658
  const typeArgs = (_d = dictEntryType.tupleTypeArguments) === null || _d === void 0 ? void 0 : _d.map((t) => t.type);
@@ -9648,7 +9672,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9648
9672
  }
9649
9673
  }
9650
9674
  });
9651
- return isIncomplete;
9675
+ return { type: types_1.AnyType.create(), isIncomplete, typeErrors };
9652
9676
  }
9653
9677
  function getTypeOfListOrSet(node, flags, inferenceContext) {
9654
9678
  var _a;
@@ -9945,23 +9969,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9945
9969
  return undefined;
9946
9970
  });
9947
9971
  }
9948
- if (expectedFunctionTypes.length <= 1) {
9949
- return getTypeOfLambdaWithExpectedType(node, expectedFunctionTypes.length > 0 ? expectedFunctionTypes[0] : undefined, inferenceContext,
9950
- /* forceSpeculative */ false);
9951
- }
9952
- // Sort the expected types for deterministic results.
9953
- expectedFunctionTypes = (0, typeUtils_1.sortTypes)(expectedFunctionTypes);
9972
+ let expectedSubtype;
9954
9973
  // If there's more than one type, try each in turn until we find one that works.
9955
- for (const expectedFunctionType of expectedFunctionTypes) {
9956
- const result = getTypeOfLambdaWithExpectedType(node, expectedFunctionType, inferenceContext,
9957
- /* forceSpeculative */ true);
9958
- if (!result.typeErrors) {
9959
- return getTypeOfLambdaWithExpectedType(node, expectedFunctionType, inferenceContext,
9960
- /* forceSpeculative */ false);
9974
+ if (expectedFunctionTypes.length > 1) {
9975
+ // Sort the expected types for deterministic results.
9976
+ expectedFunctionTypes = (0, typeUtils_1.sortTypes)(expectedFunctionTypes);
9977
+ for (const subtype of expectedFunctionTypes) {
9978
+ const result = getTypeOfLambdaWithExpectedType(node, subtype, inferenceContext,
9979
+ /* forceSpeculative */ true);
9980
+ if (!result.typeErrors) {
9981
+ expectedSubtype = subtype;
9982
+ break;
9983
+ }
9961
9984
  }
9962
9985
  }
9963
- return getTypeOfLambdaWithExpectedType(node, expectedFunctionTypes[0], inferenceContext,
9964
- /* forceSpeculative */ true);
9986
+ if (!expectedSubtype && expectedFunctionTypes.length > 0) {
9987
+ expectedSubtype = expectedFunctionTypes[0];
9988
+ }
9989
+ return getTypeOfLambdaWithExpectedType(node, expectedSubtype, inferenceContext, /* forceSpeculative */ false);
9965
9990
  }
9966
9991
  function getTypeOfLambdaWithExpectedType(node, expectedType, inferenceContext, forceSpeculative) {
9967
9992
  let isIncomplete = !!(inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete);
@@ -10958,7 +10983,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10958
10983
  }
10959
10984
  for (const typeArg of typeArgs) {
10960
10985
  let typeArgType = typeArg.type;
10961
- if (!validateTypeArg(typeArg, { allowVariadicTypeVar: true, allowUnpackedTuples: true })) {
10986
+ if (!validateTypeArg(typeArg, {
10987
+ allowVariadicTypeVar: fileInfo.diagnosticRuleSet.enableExperimentalFeatures,
10988
+ })) {
10962
10989
  typeArgType = types_1.UnknownType.create();
10963
10990
  }
10964
10991
  else if (!(0, typeUtils_1.isEffectivelyInstantiable)(typeArgType)) {
@@ -11539,7 +11566,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11539
11566
  const scope = ScopeUtils.getScopeForNode(node);
11540
11567
  const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
11541
11568
  let classFlags = 0 /* ClassTypeFlags.None */;
11542
- if ((scope === null || scope === void 0 ? void 0 : scope.type) === 4 /* ScopeType.Builtin */ ||
11569
+ if ((scope === null || scope === void 0 ? void 0 : scope.type) === 5 /* ScopeType.Builtin */ ||
11543
11570
  fileInfo.isTypingStubFile ||
11544
11571
  fileInfo.isTypingExtensionsStubFile ||
11545
11572
  fileInfo.isBuiltInStubFile ||
@@ -12045,7 +12072,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12045
12072
  if (hashSymbol && hashSymbol.isClassMember() && !hashSymbol.getSynthesizedType()) {
12046
12073
  skipSynthesizeHash = true;
12047
12074
  }
12048
- const synthesizeMethods = () => (0, dataClasses_1.synthesizeDataClassMethods)(evaluatorInterface, node, classType, skipSynthesizedInit, hasExistingInitMethod, skipSynthesizeHash);
12075
+ const synthesizeMethods = () => (0, dataClasses_1.synthesizeDataClassMethods)(evaluatorInterface, node, classType, isNamedTupleSubclass, skipSynthesizedInit, hasExistingInitMethod, skipSynthesizeHash);
12049
12076
  // If this is a NamedTuple subclass, immediately synthesize dataclass methods
12050
12077
  // because we also need to update the MRO classes in this case. For regular
12051
12078
  // dataclasses, we'll defer the method synthesis to avoid circular dependencies.
@@ -12202,9 +12229,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12202
12229
  }
12203
12230
  function evaluateTypeParameterList(node) {
12204
12231
  const paramTypes = [];
12232
+ const typeParamScope = AnalyzerNodeInfo.getScope(node);
12205
12233
  node.parameters.forEach((param) => {
12206
12234
  var _a;
12207
- const paramSymbol = AnalyzerNodeInfo.getTypeParameterSymbol(param.name);
12235
+ const paramSymbol = typeParamScope === null || typeParamScope === void 0 ? void 0 : typeParamScope.symbolTable.get(param.name.value);
12208
12236
  if (!paramSymbol) {
12209
12237
  // This can happen if the code is unreachable.
12210
12238
  return;
@@ -14633,13 +14661,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14633
14661
  }
14634
14662
  function lookUpSymbolRecursive(node, name, honorCodeFlow, preferGlobalScope = false) {
14635
14663
  var _a;
14636
- const scope = ScopeUtils.getScopeForNode(node);
14637
- let symbolWithScope = scope === null || scope === void 0 ? void 0 : scope.lookUpSymbolRecursive(name);
14638
- const scopeType = (_a = scope === null || scope === void 0 ? void 0 : scope.type) !== null && _a !== void 0 ? _a : 3 /* ScopeType.Module */;
14664
+ const scopeNodeInfo = ParseTreeUtils.getEvaluationScopeNode(node);
14665
+ const scope = AnalyzerNodeInfo.getScope(scopeNodeInfo.node);
14666
+ let symbolWithScope = scope === null || scope === void 0 ? void 0 : scope.lookUpSymbolRecursive(name, { useProxyScope: !!scopeNodeInfo.useProxyScope });
14667
+ const scopeType = (_a = scope === null || scope === void 0 ? void 0 : scope.type) !== null && _a !== void 0 ? _a : 4 /* ScopeType.Module */;
14639
14668
  // Functions and list comprehensions don't allow access to implicitly
14640
14669
  // aliased symbols in outer scopes if they haven't yet been assigned
14641
14670
  // within the local scope.
14642
- const scopeTypeHonorsCodeFlow = scopeType !== 1 /* ScopeType.Function */ && scopeType !== 0 /* ScopeType.ListComprehension */;
14671
+ let scopeTypeHonorsCodeFlow = scopeType !== 2 /* ScopeType.Function */ && scopeType !== 1 /* ScopeType.ListComprehension */;
14672
+ // TypeParameter scopes don't honor code flow, but if the symbol is resolved
14673
+ // using the proxy scope for the TypeParameter scope, we should use code flow.
14674
+ if (scopeType === 0 /* ScopeType.TypeParameter */ && symbolWithScope && symbolWithScope.scope === scope) {
14675
+ scopeTypeHonorsCodeFlow = false;
14676
+ }
14643
14677
  if (symbolWithScope && honorCodeFlow && scopeTypeHonorsCodeFlow) {
14644
14678
  // Filter the declarations based on flow reachability.
14645
14679
  const reachableDecl = symbolWithScope.symbol.getDeclarations().find((decl) => {
@@ -14671,11 +14705,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14671
14705
  // If none of the declarations are reachable from the current node,
14672
14706
  // search for the symbol in outer scopes.
14673
14707
  if (!reachableDecl) {
14674
- if (symbolWithScope.scope.type !== 1 /* ScopeType.Function */) {
14708
+ if (symbolWithScope.scope.type !== 2 /* ScopeType.Function */) {
14675
14709
  let nextScopeToSearch = symbolWithScope.scope.parent;
14676
- const isOutsideCallerModule = symbolWithScope.isOutsideCallerModule || symbolWithScope.scope.type === 3 /* ScopeType.Module */;
14710
+ const isOutsideCallerModule = symbolWithScope.isOutsideCallerModule || symbolWithScope.scope.type === 4 /* ScopeType.Module */;
14677
14711
  let isBeyondExecutionScope = symbolWithScope.isBeyondExecutionScope || symbolWithScope.scope.isIndependentlyExecutable();
14678
- if (symbolWithScope.scope.type === 2 /* ScopeType.Class */) {
14712
+ if (symbolWithScope.scope.type === 3 /* ScopeType.Class */) {
14679
14713
  // There is an odd documented behavior for classes in that
14680
14714
  // symbol resolution skips to the global scope rather than
14681
14715
  // the next scope in the chain.
@@ -14686,7 +14720,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14686
14720
  }
14687
14721
  }
14688
14722
  if (nextScopeToSearch) {
14689
- symbolWithScope = nextScopeToSearch.lookUpSymbolRecursive(name, isOutsideCallerModule, isBeyondExecutionScope);
14723
+ symbolWithScope = nextScopeToSearch.lookUpSymbolRecursive(name, {
14724
+ isOutsideCallerModule,
14725
+ isBeyondExecutionScope,
14726
+ });
14690
14727
  }
14691
14728
  else {
14692
14729
  symbolWithScope = undefined;
@@ -14702,16 +14739,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14702
14739
  // resolution over local resolutions.
14703
14740
  if (symbolWithScope && preferGlobalScope) {
14704
14741
  let curSymbolWithScope = symbolWithScope;
14705
- while (curSymbolWithScope.scope.type !== 3 /* ScopeType.Module */ &&
14706
- curSymbolWithScope.scope.type !== 4 /* ScopeType.Builtin */ &&
14742
+ while (curSymbolWithScope.scope.type !== 4 /* ScopeType.Module */ &&
14743
+ curSymbolWithScope.scope.type !== 5 /* ScopeType.Builtin */ &&
14744
+ curSymbolWithScope.scope.type !== 0 /* ScopeType.TypeParameter */ &&
14707
14745
  curSymbolWithScope.scope.parent) {
14708
- curSymbolWithScope = curSymbolWithScope.scope.parent.lookUpSymbolRecursive(name, curSymbolWithScope.isOutsideCallerModule, curSymbolWithScope.isBeyondExecutionScope || curSymbolWithScope.scope.isIndependentlyExecutable());
14746
+ curSymbolWithScope = curSymbolWithScope.scope.parent.lookUpSymbolRecursive(name, {
14747
+ isOutsideCallerModule: curSymbolWithScope.isOutsideCallerModule,
14748
+ isBeyondExecutionScope: curSymbolWithScope.isBeyondExecutionScope ||
14749
+ curSymbolWithScope.scope.isIndependentlyExecutable(),
14750
+ });
14709
14751
  if (!curSymbolWithScope) {
14710
14752
  break;
14711
14753
  }
14712
14754
  }
14713
- if ((curSymbolWithScope === null || curSymbolWithScope === void 0 ? void 0 : curSymbolWithScope.scope.type) === 3 /* ScopeType.Module */ ||
14714
- (curSymbolWithScope === null || curSymbolWithScope === void 0 ? void 0 : curSymbolWithScope.scope.type) === 4 /* ScopeType.Builtin */) {
14755
+ if ((curSymbolWithScope === null || curSymbolWithScope === void 0 ? void 0 : curSymbolWithScope.scope.type) === 4 /* ScopeType.Module */ ||
14756
+ (curSymbolWithScope === null || curSymbolWithScope === void 0 ? void 0 : curSymbolWithScope.scope.type) === 5 /* ScopeType.Builtin */) {
14715
14757
  symbolWithScope = curSymbolWithScope;
14716
14758
  }
14717
14759
  }
@@ -14989,17 +15031,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14989
15031
  // Determine if this is part of a "type" statement.
14990
15032
  const isWithinTypeAliasStatement = !!ParseTreeUtils.getParentNodeOfType(node, 77 /* ParseNodeType.TypeAlias */);
14991
15033
  const allowForwardReferences = isWithinTypeAnnotation || isWithinTypeAliasStatement || fileInfo.isStubFile;
14992
- let symbol;
14993
- const typeParamSymbol = AnalyzerNodeInfo.getTypeParameterSymbol(node);
14994
- if (typeParamSymbol) {
14995
- symbol = typeParamSymbol;
14996
- }
14997
- else {
14998
- const symbolWithScope = lookUpSymbolRecursive(node, node.value, !allowForwardReferences, isWithinTypeAnnotation);
14999
- symbol = symbolWithScope === null || symbolWithScope === void 0 ? void 0 : symbolWithScope.symbol;
15000
- }
15001
- if (symbol) {
15002
- (0, collectionUtils_1.appendArray)(declarations, symbol.getDeclarations());
15034
+ const symbolWithScope = lookUpSymbolRecursive(node, node.value, !allowForwardReferences, isWithinTypeAnnotation);
15035
+ if (symbolWithScope) {
15036
+ (0, collectionUtils_1.appendArray)(declarations, symbolWithScope.symbol.getDeclarations());
15003
15037
  }
15004
15038
  }
15005
15039
  return declarations;
@@ -15256,6 +15290,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
15256
15290
  }
15257
15291
  typeVar = types_1.TypeVarType.cloneForScopeId(typeVar, ParseTreeUtils.getScopeIdForNode(scopeNode.nodeType === 77 /* ParseNodeType.TypeAlias */ ? scopeNode.name : scopeNode), scopeNode.name.value, scopeType);
15258
15292
  }
15293
+ writeTypeCache(node, { type: typeVar }, /* flags */ undefined);
15294
+ writeTypeCache(node.name, { type: typeVar }, /* flags */ undefined);
15259
15295
  return typeVar;
15260
15296
  }
15261
15297
  function getInferredTypeOfDeclaration(symbol, decl) {
@@ -15849,17 +15885,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
15849
15885
  // a type annotation, that type is returned. If not, an attempt is made to infer
15850
15886
  // the return type. If a list of args is provided, the inference logic may take
15851
15887
  // into account argument types to infer the return type.
15852
- function getFunctionEffectiveReturnType(type, args, inferTypeIfNeeded = true) {
15888
+ function getFunctionEffectiveReturnType(type, callSiteInfo, inferTypeIfNeeded = true) {
15853
15889
  const specializedReturnType = types_1.FunctionType.getSpecializedReturnType(type, /* includeInferred */ false);
15854
15890
  if (specializedReturnType && !(0, types_1.isUnknown)(specializedReturnType)) {
15855
15891
  return adjustCallableReturnType(type, specializedReturnType, /* liveTypeVarScopes */ []);
15856
15892
  }
15857
15893
  if (inferTypeIfNeeded) {
15858
- return getFunctionInferredReturnType(type, args);
15894
+ return getFunctionInferredReturnType(type, callSiteInfo);
15859
15895
  }
15860
15896
  return types_1.UnknownType.create();
15861
15897
  }
15862
- function _getFunctionInferredReturnType(type, args) {
15898
+ function _getFunctionInferredReturnType(type, callSiteInfo) {
15863
15899
  var _a;
15864
15900
  let returnType;
15865
15901
  let isIncomplete = false;
@@ -15927,7 +15963,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
15927
15963
  types_1.FunctionType.hasUnannotatedParams(type) &&
15928
15964
  !types_1.FunctionType.isStubDefinition(type) &&
15929
15965
  !types_1.FunctionType.isPyTypedDefinition(type) &&
15930
- args) {
15966
+ callSiteInfo) {
15931
15967
  let hasDecorators = false;
15932
15968
  let isAsync = false;
15933
15969
  const declNode = (_a = type.details.declaration) === null || _a === void 0 ? void 0 : _a.node;
@@ -15942,7 +15978,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
15942
15978
  // We can't use this technique if decorators or async are used because they
15943
15979
  // would need to be applied to the inferred return type.
15944
15980
  if (!hasDecorators && !isAsync) {
15945
- const contextualReturnType = getFunctionInferredReturnTypeUsingArguments(type, args);
15981
+ const contextualReturnType = getFunctionInferredReturnTypeUsingArguments(type, callSiteInfo);
15946
15982
  if (contextualReturnType) {
15947
15983
  returnType = contextualReturnType;
15948
15984
  }
@@ -15950,7 +15986,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
15950
15986
  }
15951
15987
  return returnType;
15952
15988
  }
15953
- function getFunctionInferredReturnTypeUsingArguments(type, args) {
15989
+ function getFunctionInferredReturnTypeUsingArguments(type, callSiteInfo) {
15990
+ const args = callSiteInfo.args;
15954
15991
  let contextualReturnType;
15955
15992
  if (!type.details.declaration) {
15956
15993
  return undefined;
@@ -15988,6 +16025,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
15988
16025
  }
15989
16026
  const paramTypes = [];
15990
16027
  let isResultFromCache = false;
16028
+ // If the call is located in a loop, don't use literal argument types
16029
+ // for the same reason we don't do literal math in loops.
16030
+ const stripLiteralArgTypes = ParseTreeUtils.isWithinLoop(callSiteInfo.errorNode);
15991
16031
  // Suppress diagnostics because we don't want to generate errors.
15992
16032
  suppressDiagnostics(functionNode, () => {
15993
16033
  var _a, _b;
@@ -16033,6 +16073,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16033
16073
  if (!paramType) {
16034
16074
  paramType = types_1.UnknownType.create();
16035
16075
  }
16076
+ if (stripLiteralArgTypes) {
16077
+ paramType = stripLiteralValue(paramType);
16078
+ }
16036
16079
  paramTypes.push(paramType);
16037
16080
  writeTypeCache(param.name, { type: paramType }, 0 /* EvaluatorFlags.None */);
16038
16081
  }
@@ -17520,21 +17563,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17520
17563
  }
17521
17564
  return types_1.ClassType.isSpecialFormClass(classType);
17522
17565
  }
17523
- // Determines whether a type is "subsumed by" (i.e. is a proper subtype of) one
17524
- // of the other type.
17566
+ // Determines whether a type is "subsumed by" (i.e. is a proper subtype of) another type.
17525
17567
  function isTypeSubsumedByOtherType(type, otherType, allowAnyToSubsume, recursionCount = 0) {
17526
17568
  const concreteType = makeTopLevelTypeVarsConcrete(type);
17527
- const otherTypes = (0, types_1.isUnion)(otherType) ? otherType.subtypes : [otherType];
17528
- for (const otherType of otherTypes) {
17529
- if ((0, types_1.isTypeSame)(otherType, type)) {
17569
+ const otherSubtypes = (0, types_1.isUnion)(otherType) ? otherType.subtypes : [otherType];
17570
+ for (const otherSubtype of otherSubtypes) {
17571
+ if ((0, types_1.isTypeSame)(otherSubtype, type)) {
17530
17572
  continue;
17531
17573
  }
17532
- if ((0, types_1.isAnyOrUnknown)(otherType)) {
17574
+ if ((0, types_1.isAnyOrUnknown)(otherSubtype)) {
17533
17575
  if (allowAnyToSubsume) {
17534
17576
  return true;
17535
17577
  }
17536
17578
  }
17537
- else if (isProperSubtype(otherType, concreteType, recursionCount)) {
17579
+ else if (isProperSubtype(otherSubtype, concreteType, recursionCount)) {
17538
17580
  return true;
17539
17581
  }
17540
17582
  }
@@ -19047,19 +19089,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
19047
19089
  : firstParamType);
19048
19090
  }
19049
19091
  }
19050
- else if (!assignType(memberTypeFirstParamType, firstParamType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), typeVarContext,
19051
- /* srcTypeVarContext */ undefined, 8192 /* AssignTypeFlags.AllowUnspecifiedTypeArguments */, recursionCount)) {
19052
- if (memberTypeFirstParam.name &&
19053
- !memberTypeFirstParam.isNameSynthesized &&
19054
- memberTypeFirstParam.hasDeclaredType) {
19055
- if (diag) {
19056
- diag.addMessage(localize_1.LocMessage.bindTypeMismatch().format({
19057
- type: printType(baseType),
19058
- methodName: memberType.details.name || '<anonymous>',
19059
- paramName: memberTypeFirstParam.name,
19060
- }));
19092
+ else {
19093
+ const subDiag = diag === null || diag === void 0 ? void 0 : diag.createAddendum();
19094
+ if (!assignType(memberTypeFirstParamType, firstParamType, subDiag === null || subDiag === void 0 ? void 0 : subDiag.createAddendum(), typeVarContext,
19095
+ /* srcTypeVarContext */ undefined, 8192 /* AssignTypeFlags.AllowUnspecifiedTypeArguments */, recursionCount)) {
19096
+ if (memberTypeFirstParam.name &&
19097
+ !memberTypeFirstParam.isNameSynthesized &&
19098
+ memberTypeFirstParam.hasDeclaredType) {
19099
+ if (subDiag) {
19100
+ subDiag.addMessage(localize_1.LocMessage.bindTypeMismatch().format({
19101
+ type: printType(baseType),
19102
+ methodName: memberType.details.name || '<anonymous>',
19103
+ paramName: memberTypeFirstParam.name,
19104
+ }));
19105
+ }
19106
+ return undefined;
19061
19107
  }
19062
- return undefined;
19063
19108
  }
19064
19109
  }
19065
19110
  }