Skip to content
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

Add support for ignoring some warnings #146

Closed
pyflakes-bot opened this issue Dec 22, 2011 · 9 comments
Closed

Add support for ignoring some warnings #146

pyflakes-bot opened this issue Dec 22, 2011 · 9 comments

Comments

@pyflakes-bot
Copy link

pyflakes-bot commented Dec 22, 2011

Original report by adiroiban (@adiroiban?) on Launchpad:


It would be nice if pyflakes would provide an option for ignoring some warnings.

For example I have this code:

try:
    from setproctitle import setproctitle
except ImportError:
    setproctitle = lambda t: None  # pyflakes:ignore

And pyflakes will complain that setproctitle is redefined.
Maybe this is a bad code and this kind of things should be never ignored, but I just want to know if such a feature is wanted in pyflakes.

Here is a workaround for implementing pyflakes:ignore

class PocketLintPyFlakesChecker(PyFlakesChecker):
    '''PocketLint checker for pyflakes.

    This is here to work around some of the pyflakes problems.

    Beside the AST tree, it is also initialized with the plain text content
    of the file.
    '''

    def __init__(self, tree, filename='(none)', text=None):
        self.text = text
        if self.text:
            self.text = self.text.split('\n')
        super(PocketLintPyFlakesChecker, self).__init__(
            tree=tree, filename=filename)

    def report(self, messageClass, *args, **kwargs):
        text_lineno = args[0] - 1
        if self.text[text_lineno].find('pyflakes:ignore') >= 0:
            return
        self.messages.append(messageClass(self.filename, *args, **kwargs))
@pyflakes-bot
Copy link
Author

Original comment by exarkun (@exarkun?) on Launchpad:


I'd rather fix the bugs in pyflakes that lead to spurious warnings.

@pyflakes-bot
Copy link
Author

Original comment by bukzor on Launchpad:


We have some questionable-but-necessary code which uses globals().update(). The of course causes pyflakes to freak out about undefined variables. I'd like to be able to ignore those warnings, instead of ignoring pyflakes altogether.

@pyflakes-bot
Copy link
Author

Original comment by esz-michel on Launchpad:


@sinzui: Can you link to the changeset? I am curious to see how this was implemented. Sorry if the link is already available somewhere, but I could noit find it :\

I would really like this feature as well, but more fine-grained as proposed. For example, pylint allows you to disable a specific error-code (see http://www.logilab.org/card/pylint_manual#messages-control). Or, the Java @SuppressWarnings annotation also allows you to ignore specific warnings.

I find the proposed solution to simply ignore pyflakes altogether is a bit like a "except Exception": You might miss other errors ;)

@pyflakes-bot
Copy link
Author

Original comment by sinzui on Launchpad:


Adi extended PyFlakesChecker to accept the raw text of the module being checked. The report() method looks of the line number of warning/error and in the text and looks for "# pyflakes:ignore". The report returns early if the comment is present.
https://code.launchpad.net/~adiroiban/pocket-lint/907742/+merge/102882

@pyflakes-bot
Copy link
Author

Original comment by adiroiban (@adiroiban?) on Launchpad:


Hi,

Right now, pyflakes messages do not have a ID for each message class. In pylint each message class has its own ID.

I agree that this all or nothing filter can lead to other troubles. I will check to see if pyflakes developers would like to accept a patch to pyflakes to add IDs for each message class, and then we can improve the current pocketlint filter.

@pyflakes-bot
Copy link
Author

Original comment by bukzor on Launchpad:


Alternative solution: use a pylintrc that is only roughly as picky as pyflakes.

@pyflakes-bot
Copy link
Author

Original comment by glyph on Launchpad:


There's already a bug for automatically detecting the entirely detectable class of error in the example here, isn't there? It would be so much nicer to do that than to encourage users to drop these comment turds into their code.

@pyflakes-bot
Copy link
Author

Original comment by exarkun (@exarkun?) on Launchpad:


More than one:

https://bugs.launchpad.net/pyflakes/+bug/885140
https://bugs.launchpad.net/pyflakes/+bug/800691
https://bugs.launchpad.net/pyflakes/+bug/916264

Probably others. Fixing these real problems would be a great win for all pyflakes users.

@pyflakes-bot
Copy link
Author

Original comment by florent.x (@florentx?) on Launchpad:


Issues 800691 and 916264 and many others were fixed with Pyflakes 0.6.1.

If you really want to use comments to disable some checks, try Flake8.

But the recommended path is to open an issue if it looks like a limitation of Pyflakes.

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

No branches or pull requests

1 participant