Describe the bug
A warning is emitted for unused arguments/variables, even though they are prefixed with an underscore.
Code or Screenshots
Here's an example:
def foo(_a):
_b = 42
return 3
Here, both _a and _b will have a warning on their lines, something like "_a" is not accessed.
Versions
pyright 1.1.407, 1.1.408 and latest git, running from Emacs with lsp-pyright.
Possible fix
The problem arises here:
|
if (nameNode) { |
|
this._fileInfo.diagnosticSink.addUnusedCodeWithTextRange( |
|
LocMessage.unaccessedSymbol().format({ name: nameNode.d.value }), |
|
nameNode, |
|
action |
|
); |
|
|
|
if (rule !== undefined && message && diagnosticLevel !== 'none') { |
|
this._evaluator.addDiagnostic(rule, message, nameNode); |
|
} |
|
} |
Looks like the diagnosticLevel !== 'none' check should be moved to the "if" one level back, like this:
--- a/packages/pyright-internal/src/analyzer/checker.ts
+++ b/packages/pyright-internal/src/analyzer/checker.ts
@@ -3859,14 +3859,14 @@ export class Checker extends ParseTreeWalker {
}
const action = rule === DiagnosticRule.reportUnusedImport ? { action: Commands.unusedImport } : undefined;
- if (nameNode) {
+ if (nameNode && diagnosticLevel !== 'none') {
this._fileInfo.diagnosticSink.addUnusedCodeWithTextRange(
LocMessage.unaccessedSymbol().format({ name: nameNode.d.value }),
nameNode,
action
);
- if (rule !== undefined && message && diagnosticLevel !== 'none') {
+ if (rule !== undefined && message) {
this._evaluator.addDiagnostic(rule, message, nameNode);
}
}
Describe the bug
A warning is emitted for unused arguments/variables, even though they are prefixed with an underscore.
Code or Screenshots
Here's an example:
Here, both _a and _b will have a warning on their lines, something like
"_a" is not accessed.Versions
pyright 1.1.407, 1.1.408 and latest git, running from Emacs with lsp-pyright.
Possible fix
The problem arises here:
pyright/packages/pyright-internal/src/analyzer/checker.ts
Lines 3862 to 3872 in 28ea84a
Looks like the
diagnosticLevel !== 'none'check should be moved to the "if" one level back, like this: