Skip to content

Commit

Permalink
fix reportUnusedParameter 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 4cb43d3
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from abc import abstractmethod
from abc import ABC, abstractmethod
from typing import override


Expand All @@ -23,4 +23,12 @@ def __baz__(self, asdf: int): # no error, dunder
def qux(self, __asdf: int): # error, unused cringe positional argument
...

def bar(_value: int): ...
def bar(_value: int): ...

class Baz(ABC):
@property
@abstractmethod
def foo(self) -> str:...
@foo.setter
def foo(self, new_value: str): # no error, abstract property
...

0 comments on commit 4cb43d3

Please sign in to comment.