Skip to content

Commit

Permalink
fix reportUnusedParameter on parameters prefixed with _
Browse files Browse the repository at this point in the history
  • Loading branch information
DetachHead committed Aug 17, 2024
1 parent b92ac27 commit b71e998
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 5 additions & 7 deletions packages/pyright-internal/src/analyzer/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3661,12 +3661,6 @@ export class Checker extends ParseTreeWalker {

if (decl.node.nodeType === ParseNodeType.Name) {
nameNode = decl.node;

// Don't emit a diagnostic if the name starts with an underscore.
// This indicates that the variable is unused.
if (!nameNode.d.value.startsWith('_')) {
rule = DiagnosticRule.reportUnusedVariable;
}
} else if (decl.node.nodeType === ParseNodeType.Parameter) {
nameNode = decl.node.d.name;

Expand All @@ -3693,12 +3687,16 @@ export class Checker extends ParseTreeWalker {
rule = DiagnosticRule.reportUnusedVariable;
}

if (nameNode) {
// Don't emit a diagnostic if the name starts with an underscore.
// This indicates that the variable is unused.
if (nameNode && !nameNode.d.value.startsWith('_')) {
message = (
rule === DiagnosticRule.reportUnusedParameter
? LocMessage.unaccessedSymbol()
: LocMessage.unaccessedVariable()
).format({ name: nameNode.d.value });
} else {
rule = undefined;
}
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ class Bar(Foo):
def foo(self, asdf: int): ...

@override
def bar(self, asdf: int): ...
def bar(self, asdf: int): ...

def bar(_value: int): ...

0 comments on commit b71e998

Please sign in to comment.