pylint
pylint copied to clipboard
`disable=too-many-statements` sometimes not working
Bug description
The too-many-statements
error can't be disabled in Line 27, though this error is disabled in whole file and inline.
This error is correctly suppressed in Line 35.
I've read #7625 and #6042, but I can't find a solution for this.
def load_arguments(self, _): # pylint: disable=too-many-statements, too-many-locals
This error happens when upgrade pylint from 2.11 to 2.17.
Related issue: https://github.com/Azure/azure-cli/pull/26685
Configuration
No response
Command used
git clone --depth=1 --branch 2.50.0 https://github.com/Azure/azure-cli && cd azure-cli
pylint ./src/azure-cli/azure/cli/command_modules/rdbms/_params.py --disable R,C,W,E --enable=R0915
(Sorry, I can't find an easy way to repro this error in new file)
Pylint output
************* Module azure.cli.command_modules.rdbms._params
src/azure-cli/azure/cli/command_modules/rdbms/_params.py:27:0: R0915: Too many statements (434/50) (too-many-statements)
------------------------------------------------------------------
Your code has been rated at 9.98/10 (previous run: 9.42/10, +0.55)
Expected behavior
Line27 does not raise error
Pylint version
pylint 2.17.4
astroid 2.15.5
Python 3.10.8 (tags/v3.10.8:aaaf517, Oct 11 2022, 16:50:30) [MSC v.1933 64 bit (AMD64)]
OS / Environment
Windows 11
Additional dependencies
No response
This error show again, we can now reproduce, please help take a look @mbyrnepr2 See https://github.com/Azure/azure-cli/pull/28020
@evelyn-ys in that example, moving the disable will have the desired outcome:
-def load_arguments(self, _): # pylint: disable=too-many-statements, too-many-locals
+def load_arguments(self, _):
+ # pylint: disable=too-many-statements, too-many-locals
With that in place then I think all the other # pylint: disable=too-many-statements
can be removed from the module.
This looks consistent with the docs (especially the examples with methods) but others can correct me if the behaviour is unexpected or not; so now that I've said that I think perhaps it isn't a false positive at all, as I originally labelled it.
Thanks for your reply, we did put the comment to a wrong section.
However, moving disable comment to next line does not fix the problem.
This file also contains a global disable, which takes no effect. https://github.com/Azure/azure-cli/blob/4f9c618296537fd7eda8c778b01534c21f351c22/src/azure-cli/azure/cli/command_modules/rdbms/_params.py#L7
@bebound I think there are some side-effects with the various disables that are currently in the module - there seems to be a bug there somewhere.
When I remove all the pylint: disable=too-many-statements
and run Pylint on your module, the message is emitted for lines:
- 36 (def _complex_params)
- 226 (def _flexible_server_params)
- 28 (def load_arguments)
Removing all disables for this checker and reinstating the module-level disable only and running Pylint results in the message not being emitted at all - can you verify if this works for you?
Otherwise simply removing the following one also results in no message being emitted:
# Flexible-server
- # pylint: disable=too-many-statements, too-many-locals, too-many-branches
def _flexible_server_params(command_group):
I'm running it like this:
pylint .\azure-cli\src\azure-cli\azure\cli\command_modules\rdbms\_params.py --disable=all --enable=too-many-statements
Thank you, keeping only one module-level disable works. It seems that there is a bug in the disable scope logic.