[Tutor] pylint(too-many-nested-blocks)

Cameron Simpson cs at cskk.id.au
Sun Nov 28 06:00:41 EST 2021


On 28Nov2021 14:51, Phil <phillor9 at gmail.com> wrote:
>"https://pycodequ.al/docs/pylint-messages/r1702-too-many-nested-blocks.html" 
>describes this error as:
>
>"Used when a function or method has too many nested blocks. This makes 
>the code less understandable and maintainable."
>
>The following is one of several functions that fits this description 
>and I'm wondering how I might reduce the number of for-loops. If the 
>number of for-loops cannot be reduced then I suppose the function 
>should be broken up into smaller functions. The problem is, as I see 
>it, little of the code is reusable in other functions that also have 
>too many nested blocks.

Remember that a linter is a large collection of guidelines when it comes 
to things like "too many". You could break this function up, but it 
doesn't seem unreasonable to me.

When I lint I'm making an informed decision about the linter's 
complaints. If you're happy that the function is sensible, you can do 
this:

    # pylint: disable=too-many-nested-blocks
    def pointingPairRow(self):

for that specific function.

My goal with a linter is clean output (no complaints). Oftne I ifx 
things to make it happy - these checks are generally sensble - but 
sometimes you know better than the linter, and pylint's disable comments 
come in very useful there.

Why silence? So that _new_ messages are worth checking out and are not 
buried in a sea of things I've already considered.

Cheers,
Cameron Simpson <cs at cskk.id.au>


More information about the Tutor mailing list