Skip to content

What is a block? #2452

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tbekolay opened this issue Aug 29, 2018 · 2 comments · Fixed by #4800
Closed

What is a block? #2452

tbekolay opened this issue Aug 29, 2018 · 2 comments · Fixed by #4800

Comments

@tbekolay
Copy link
Contributor

Question

Apologies if this has been asked before, but I'm curious what pylint considers a "block" and whether that could be documented more explicitly. Right now, the docs state:

add "#pylint: disable=some-message,another-one" at the desired block level or at the end of the desired line of code

I ask this because I was surprised to see that the following does not work:

        if hasattr(SafeConfigParser, "read_file"):
            return SafeConfigParser.read_file(self, fp, filename)
        else:
            # pylint: disable=deprecated-method
            return SafeConfigParser.readfp(self, fp, filename)

The deprecated-method warning is still raised.

However, the following does work:

        try:
            return SafeConfigParser.read_file(self, fp, filename)
        except AttributeError:
            # pylint: disable=deprecated-method
            return SafeConfigParser.readfp(self, fp, filename)

The deprecated-method warning is disabled, as desired. In the if/else case, I had to add the # pylint: disable= line to block that contains the if/else instead.

@PCManticore
Copy link
Contributor

Hey, thanks for creating an issue!
I think there are two problems to be solved here:

  • we need to do a better job at documenting what a block is. In short, a block is either a scope (say a function) or a multiline statement (TryFinally, if statements, for loops).

  • the second problem is that we should be able to disable that message in your example, so there is a bug related to that check

@Pierre-Sassoulas
Copy link
Member

The bug is a duplicate of #872, the documentation need to be done though.

        if hasattr(SafeConfigParser, "read_file"):
            return SafeConfigParser.read_file(self, fp, filename)
        else:  # pylint: disable=deprecated-method
            return SafeConfigParser.readfp(self, fp, filename)

Would work here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants