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

performance improvements #464

Closed
wants to merge 3 commits into from
Closed
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
11 changes: 8 additions & 3 deletions packages/pyright-internal/src/analyzer/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2706,7 +2706,8 @@ export class Checker extends ParseTreeWalker {
let reportedUnreachable = false;
let prevStatement: StatementNode | undefined;

for (const statement of statements) {
for (const index in statements) {
const statement = statements[index];
// No need to report unreachable more than once since the first time
// covers all remaining statements in the statement list.
if (!reportedUnreachable) {
Expand All @@ -2717,7 +2718,11 @@ export class Checker extends ParseTreeWalker {
// if a statement is a function call where an argument is typed as `Never`, then it's probably an `assert_never` pattern,
// so don't report the statement as unreachable. this check is probably overkill and we could instead just special-case
// `typing.assert_never`, but we want to support user-defined "assert never" functions to be more flexible.
// for performance reasons we only do this check on the first unreachable statement because there's no reason to have any
// other statements in that case.
if (
index === '0' &&
!(this._fileInfo.diagnosticRuleSet.reportUnreachable in ['none', 'unreachable']) &&
statement.nodeType === ParseNodeType.StatementList &&
statement.statements.find(
(statement) =>
Expand Down Expand Up @@ -5663,12 +5668,11 @@ export class Checker extends ParseTreeWalker {
const isTypedDict = ClassType.isTypedDictClass(classType);
const diagAddendum = new DiagnosticAddendum();
for (const baseClass of filteredBaseClasses) {
const typeVarContext = buildTypeVarContextFromSpecializedClass(baseClass);
// if classType is a TypedDict, we never need to worry about constructors in base classes because the
// following rules are enforced:
// - if one base class is a TypedDict, all of them have to be TypedDicts
// - TypedDicts are not allowed to have methods, so they can't have a custom __init__ or __new__ function
if (!isTypedDict) {
if (!isTypedDict && this._fileInfo.diagnosticRuleSet.reportUnsafeMultipleInheritance !== 'none') {
for (const constructorGetter of [getBoundInitMethod, getBoundNewMethod]) {
const constructorMethodResult = constructorGetter(
this._evaluator,
Expand Down Expand Up @@ -5697,6 +5701,7 @@ export class Checker extends ParseTreeWalker {
constructorIsSafe = false;
}
}
const typeVarContext = buildTypeVarContextFromSpecializedClass(baseClass);
for (const baseClassMroClass of baseClass.details.mro) {
// There's no need to check for conflicts if this class isn't generic.
if (isClass(baseClassMroClass) && baseClassMroClass.details.typeParameters.length > 0) {
Expand Down
Loading