"reportUnusedExpression" Warning Not Triggered for Unused Methods #4864
Replies: 5 comments
-
The The feature was later extended by this enhancement request. When considering an enhancement request, we need to evaluate the upsides and downsides of the request. The I'll need to give this more thought and perhaps do some experimentation. |
Beta Was this translation helpful? Give feedback.
-
I've prototyped the suggested change and ran this on a bunch of existing typed code bases. As I feared, this change produces a lot of false positive errors, especially in test code. |
Beta Was this translation helpful? Give feedback.
-
In fact, it's fairly common that Pylance produces errors when # Source: https://github.com/spack/spack/blob/develop/lib/spack/spack/modules/common.py#L877
# Now
try:
self.default_template
except AttributeError:
...
# Using hasattr
if not hasattr(self, 'default_template'):
... # Source: https://github.com/FasterSpeeding/Tanjun/blob/master/tests/test_checks.py#L2470
# now
with pytest.raises(AttributeError):
command.wrapped_command
# Using hasattr
assert not hasattr(command, 'wrapped_command') Not only does it resolve the issue, but it also looks more concise for me. |
Beta Was this translation helpful? Give feedback.
-
If this check were enabled only in strict mode, there would be more latitude for encouraging code changes. Since this check is enabled in basic mode, it affects users who are not fully bought in to the benefits of static type checking and are sensitive to false positives and the need to change their code to satisfy a type checker. The other thing to note is that |
Beta Was this translation helpful? Give feedback.
-
The Pylance team discussed this and we are also concerned about the false positives. Moving this issue to discussion as an enhancement request for comments and upvotes. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Bug Description
The Pylance warning "reportUnusedExpression" is designed to trigger when an expression value is unused. However, this warning does not seem to be triggered in the context of class and module methods.
Code Examples and Screenshots
requests: 2.31.0
VS Code Extension or Command-Line Usage
Pylance version: v2023.9.10
Beta Was this translation helpful? Give feedback.
All reactions