Skip to content

Commit

Permalink
Fixed false positive error when using a forward-declared reference in…
Browse files Browse the repository at this point in the history
…side of an inlined TypedDict when `from __future__ import annotations` is in effect. This addresses #5935.
  • Loading branch information
msfterictraut committed Sep 12, 2023
1 parent 669a738 commit 08bf803
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/pyright-internal/src/analyzer/typedDicts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>();
for (let i = 1; i < argList.length; i++) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<string>();
const fileInfo = AnalyzerNodeInfo.getFileInfo(entryDict);
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 08bf803

Please sign in to comment.