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

fix reportUnusedParameter false positive on abstract setters #956

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
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
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
...
Loading