Skip to content

Commit

Permalink
fix rerportUnusedParameter false positive on abstract setters
Browse files Browse the repository at this point in the history
  • Loading branch information
DetachHead committed Dec 16, 2024
1 parent 5492661 commit ad40ea5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/pyright-internal/src/analyzer/properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ export function clonePropertyWithSetter(
if (!isProperty(prop)) {
return prop;
}
// this is safe. see comment on isProperty
prop = prop as ClassType;

// if it's an abstract property, mark the parameter as accessed
if (prop.priv?.fgetInfo?.methodType && FunctionType.isAbstractMethod(prop.priv.fgetInfo.methodType)) {
// first parameter is self, there should only ever be one other parameter.
evaluator.markParamAccessed(errorNode.d.params[1]);
}

const classType = prop as ClassType;
const flagsToClone = classType.shared.flags;
Expand Down
1 change: 1 addition & 0 deletions packages/pyright-internal/src/analyzer/typeEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28434,6 +28434,7 @@ export function createTypeEvaluator(
checkForCancellation,
printControlFlowGraph,
typesOverlap,
markParamAccessed,
};

const codeFlowEngine = getCodeFlowEngine(evaluatorInterface, speculativeTypeTracker);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -884,4 +884,5 @@ export interface TypeEvaluator {
logger: ConsoleInterface
) => void;
typesOverlap: (leftType: Type, rightType: Type, checkEq: boolean) => boolean;
markParamAccessed: (param: ParameterNode) => void;
}
3 changes: 2 additions & 1 deletion packages/pyright-internal/src/analyzer/typeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1423,7 +1423,8 @@ export function isEllipsisType(type: Type): boolean {
return isAny(type) && type.priv.isEllipsis;
}

export function isProperty(type: Type) {
// type guard commented out due to https://github.com/microsoft/TypeScript/issues/15048
export function isProperty(type: Type) /* : type is ClassType */ {
return isClassInstance(type) && ClassType.isPropertyClass(type);
}

Expand Down

0 comments on commit ad40ea5

Please sign in to comment.