Skip to content

Commit

Permalink
Added some changes from another branch. (#8445)
Browse files Browse the repository at this point in the history
Added some changes from another branch.
  • Loading branch information
erictraut authored Jul 16, 2024
1 parent 5d6b96b commit f5edd2b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/pyright-internal/src/analyzer/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ export class Checker extends ParseTreeWalker {
declaredReturnType,
returnType,
diagAddendum,
/* destTypeVarContext */ undefined,
/* destTypeVarContext */ new TypeVarContext(),
/* srcTypeVarContext */ undefined,
AssignTypeFlags.AllowBoolTypeGuard
)
Expand Down
18 changes: 18 additions & 0 deletions packages/pyright-internal/src/analyzer/parseTreeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,24 @@ export function getEnclosingClassOrFunction(node: ParseNode): FunctionNode | Cla
return undefined;
}

export function getEnclosingClassOrFunctionSuite(node: ParseNode): SuiteNode | undefined {
let curNode = node.parent;
while (curNode) {
if (curNode.nodeType === ParseNodeType.Suite) {
if (
curNode.parent?.nodeType === ParseNodeType.Function ||
curNode.parent?.nodeType === ParseNodeType.Class
) {
return curNode;
}
}

curNode = curNode.parent;
}

return undefined;
}

export function getEnclosingSuiteOrModule(
node: ParseNode,
stopAtFunction = false,
Expand Down
4 changes: 4 additions & 0 deletions packages/pyright-internal/src/analyzer/typeEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24018,6 +24018,10 @@ export function createTypeEvaluator(
// Is the destination a callback protocol (defined in PEP 544)?
const destCallbackType = getCallbackProtocolType(destType, recursionCount);
if (destCallbackType) {
if (destTypeVarContext) {
destTypeVarContext.addSolveForScope(getTypeVarScopeId(destCallbackType));
}

return assignType(
destCallbackType,
concreteSrcType,
Expand Down

0 comments on commit f5edd2b

Please sign in to comment.