Skip to content

Commit

Permalink
Tweaked the algorithm for computing the complexity of a code flow gra…
Browse files Browse the repository at this point in the history
…ph to accommodate slightly larger graphs before giving up. This addresses #9778. (#9781)
  • Loading branch information
erictraut authored Jan 28, 2025
1 parent 7f60dc7 commit 722376c
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions packages/pyright-internal/src/analyzer/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ interface NarrowExprOptions {
// amount to the complexity factor. Without this, the complexity
// calculation fails to take into account large numbers of non-cyclical
// flow nodes. This number is somewhat arbitrary and is tuned empirically.
const flowNodeComplexityContribution = 0.05;
const flowNodeComplexityContribution = 0.025;

export class Binder extends ParseTreeWalker {
private readonly _fileInfo: AnalyzerFileInfo;
Expand Down Expand Up @@ -4087,17 +4087,25 @@ export class Binder extends ParseTreeWalker {
// a decorator that tells us otherwise.
isInstanceMember = true;
for (const decorator of methodNode.d.decorators) {
let decoratorName: string | undefined;

if (decorator.d.expr.nodeType === ParseNodeType.Name) {
const decoratorName = decorator.d.expr.d.value;

if (decoratorName === 'staticmethod') {
// A static method doesn't have a "self" or "cls" parameter.
return undefined;
} else if (decoratorName === 'classmethod') {
// A classmethod implies that the first parameter is "cls".
isInstanceMember = false;
break;
}
decoratorName = decorator.d.expr.d.value;
} else if (
decorator.d.expr.nodeType === ParseNodeType.MemberAccess &&
decorator.d.expr.d.leftExpr.nodeType === ParseNodeType.Name &&
decorator.d.expr.d.leftExpr.d.value === 'builtins'
) {
decoratorName = decorator.d.expr.d.member.d.value;
}

if (decoratorName === 'staticmethod') {
// A static method doesn't have a "self" or "cls" parameter.
return undefined;
} else if (decoratorName === 'classmethod') {
// A classmethod implies that the first parameter is "cls".
isInstanceMember = false;
break;
}
}
}
Expand Down

0 comments on commit 722376c

Please sign in to comment.