Skip to content

Commit

Permalink
Fixed bug that results in a false positive when a NamedTuple field us…
Browse files Browse the repository at this point in the history
…es `...` as a default value in a stub file. This addresses #9191. (#9212)
  • Loading branch information
erictraut authored Oct 11, 2024
1 parent 3e91285 commit 8c253f2
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions packages/pyright-internal/src/analyzer/dataClasses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,11 +572,20 @@ export function synthesizeDataClassMethods(
if (entry.isDefaultFactory || !entry.defaultExpr) {
defaultType = entry.type;
} else {
defaultType = evaluator.getTypeOfExpression(
entry.defaultExpr,
/* flags */ undefined,
makeInferenceContext(entry.type)
).type;
const defaultExpr = entry.defaultExpr;
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
const flags = fileInfo.isStubFile ? EvalFlags.ConvertEllipsisToAny : EvalFlags.None;

// Use speculative mode here so we don't cache the results.
// We'll want to re-evaluate this expression later, potentially
// with different evaluation flags.
defaultType = evaluator.useSpeculativeMode(defaultExpr, () => {
return evaluator.getTypeOfExpression(
defaultExpr,
flags,
makeInferenceContext(entry.type)
).type;
});
}
}
}
Expand Down

0 comments on commit 8c253f2

Please sign in to comment.