From 08bf803052148ecc649ff310e8d045c879d7f8b6 Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Tue, 12 Sep 2023 14:59:20 -0700 Subject: [PATCH] Fixed false positive error when using a forward-declared reference inside of an inlined TypedDict when `from __future__ import annotations` is in effect. This addresses #5935. --- packages/pyright-internal/src/analyzer/typedDicts.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/pyright-internal/src/analyzer/typedDicts.ts b/packages/pyright-internal/src/analyzer/typedDicts.ts index f16062e12e4c..3102d9a2a504 100644 --- a/packages/pyright-internal/src/analyzer/typedDicts.ts +++ b/packages/pyright-internal/src/analyzer/typedDicts.ts @@ -127,7 +127,7 @@ export function createTypedDictType( ) { usingDictSyntax = true; - getTypedDictFieldsFromDictSyntax(evaluator, entriesArg.valueExpression, classFields); + getTypedDictFieldsFromDictSyntax(evaluator, entriesArg.valueExpression, classFields, /* isInline */ false); } else if (entriesArg.name) { const entrySet = new Set(); for (let i = 1; i < argList.length; i++) { @@ -222,7 +222,7 @@ export function createTypedDictTypeInlined( classType.details.baseClasses.push(typedDictClass); computeMroLinearization(classType); - getTypedDictFieldsFromDictSyntax(evaluator, dictNode, classType.details.fields); + getTypedDictFieldsFromDictSyntax(evaluator, dictNode, classType.details.fields, /* isInline */ true); synthesizeTypedDictClassMethods(evaluator, dictNode, classType, /* isClassFinal */ true); return classType; @@ -664,7 +664,8 @@ export function getTypedDictMembersForClass(evaluator: TypeEvaluator, classType: function getTypedDictFieldsFromDictSyntax( evaluator: TypeEvaluator, entryDict: DictionaryNode, - classFields: SymbolTable + classFields: SymbolTable, + isInline: boolean ) { const entrySet = new Set(); const fileInfo = AnalyzerNodeInfo.getFileInfo(entryDict); @@ -700,7 +701,7 @@ function getTypedDictFieldsFromDictSyntax( node: entry.keyExpression, path: fileInfo.filePath, typeAnnotationNode: entry.valueExpression, - isRuntimeTypeExpression: true, + isRuntimeTypeExpression: !isInline, range: convertOffsetsToRange( entry.keyExpression.start, TextRange.getEnd(entry.keyExpression),