Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug that results in a false positive when a NamedTuple field us… #9212

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading