Skip to content
This repository has been archived by the owner on Mar 7, 2021. It is now read-only.

tag things with '# pyflakes.ignore' #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jehiah
Copy link
Contributor

@jehiah jehiah commented Oct 22, 2011

One of my uses cases for pyflakes is integrating into a testing/build system. As a result i found it necessary to have a way of skipping certain things that I'm choosing are "ok" to get to a point where i can enforce a "no warnings before deploy" type of rule.

(the specific warnings that i wanted to skip don't matter so much here, just that i needed that ability; mostly it was things where i had conditional re-imports or purposefully unused imports)

This change allows me to add a comment at the end of any python line which i want pyflakes to ignore.

... # pyflakes.ignore

@abourget
Copy link

+1 ! I'm waiting for that too :)

@solarmist
Copy link

+1 This is important to a lot of people.

@xyb
Copy link

xyb commented Jan 30, 2012

+1

3 similar comments
@thobbs
Copy link

thobbs commented Jan 31, 2012

+1

@singingwolfboy
Copy link

+1

@ethanvandenberg22
Copy link

+1

@akvadrako
Copy link

I also want to override pyflakes in some cases, but I prefer not to clog my code with comments designed for computers.

So instead of this patch I would prefer some mechanism to customize pyflakes for my whole package. For example:

# pyflakes-custom.py
def pyflakes_filter(complaint):
  if re.search("_.*imported but unused", complaint.msg):
    return None
  return complaint 

@npinto
Copy link

npinto commented Mar 13, 2012

+1

Any reason not to merge this ?

@jtriley
Copy link

jtriley commented Mar 13, 2012

+1

@npinto
Copy link

npinto commented Mar 13, 2012

@jtriley

The project seems dead (last commit from 10 months ago), and there are many problems with it (e.g. setup.py incompatible with virtualenv). Should we fork it and maintain it ourselves?

@jtriley
Copy link

jtriley commented Mar 13, 2012

@npinto The version on pypi (0.5.0) seems to be hosted by divmod folks (https://launchpad.net/pyflakes) and latest version was released last September. Also, according to #23 (comment) the divmod pyflakes seems up to date/active. What do you think?

@npinto
Copy link

npinto commented Mar 13, 2012

Good point, we should try to move everything to github on pyflakes/pyflakes. Submitted this request on launchpad:
https://bugs.launchpad.net/pyflakes/+bug/954470

@bukzor
Copy link

bukzor commented Mar 20, 2012

FYI: Subscribing to that bug increases it's "heat" by 2. The current high is 58.

@jjmaestro
Copy link

Hi!

Do any of you know where / how to clone the official pyflakes source? I want to keep a GH clone of whatever is the official source. I believe the official source is in Launchpad but I can't seem to find a clear / easy way to clone whatever is official. In fact, in the official Launchpad source page, I can't find an lp: link but a "Launchpad does not know where Pyflakes hosts its code." message.

Thanks in advanced,

@dbr
Copy link

dbr commented Jul 30, 2012

@jjmaestro According to the Pyflakes Launchpad, the source lives at https://launchpad.net/divmod.org/trunk - so I think you can do

bzr branch lp:divmod.org

..maybe? Launchpad is confusing.

@jjmaestro
Copy link

Hmmm... @dbr thanks for the hint! will try that and see what happens :D

@dbarnett
Copy link

Nit: I would prefer that whatever mechanism we used to override pyflakes would also be natural for other static analysis tools to support. pyflakes.ignore is nice and concise, but I wonder if we should keep the "pyflakes" out of it.

@kevinw
Copy link
Owner

kevinw commented Sep 20, 2012

Just to offer two (admittedly very late) cents: I'm kind of opinionated about using comments to squelch the output from lint tools—I think it sucks.

Comments in general tend to become useless over time. And in terms of general code base pollution, comments telling you (and, oh yeah, the static analysis tool that maybe only you use) that "up ahead lays some evil shit" are even worse.

I deal with a semi-largish project frequently that has both vim mode lines, and emacs folding mode comments—sometimes in the same file!—and the amount of extraneous noise due to just those two things when you're mentally parsing a file for the first time is actually enough to be annoying.

Do I have an alternative? What if we gave PyFlakes the ability to read in a blacklist of modules, or functions, or some combination of both, from some file? Remember how .gitignore works? What if you could do .lintignore in the same way? In any directory, you could put a .lintignore file. That file could look something like

uglymodule.py # ignore an entire module (bad)

uglymodule.py:gnarlyfunction # ignore a function (better)

uglymodule.py:gnarlyfunction(UndefinedExport,LateFutureImport) # ignore two specific messages in one function (bester?)

uglymodule.py:MyClass.my_method # class methods, etc....

There might even be existing syntax out there (or even better, code for parsing/handling) for this sort of "referring to parts of Python code" thing. We could add an option to make it an error for any of those declarations to point to code that doesn't exist anymore, so that if you wanted, you could be forced to keep it up to date.

TLDR

  • code is for people to read
  • our tools shouldn't force us to make our code less readable
  • metadata not intrinsic to code should go outside the code

Thoughts? (I'm going to try to keep this project up to date, now, btw...)

@dbarnett
Copy link

I was actually thinking kinda the same thing, except I don't know how much I would use this with function-level granularity. Usually I just have a few specific lines I want to ignore. For instance, I've written code that tries import simplejson as json and falls back to import json. That complains about redefining json, and I'd like to suppress that. But then if later in the file I had json = '{}', I would want to see a warning about that one. Is that doable?

I was thinking of having some kind of .lintignore file, but maybe having it include a line number, the text of the line, and the warning, and then I guess some kind of fuzz factor on the line number and line text. That would tend to get off over time, especially if you add/delete code in the middle of files, but the only way I see around that is embedding comments in the file itself, which I don't like any more than you do.

@dbr
Copy link

dbr commented Sep 26, 2012

My only complaint about comments like # pylint: disable=E201 is that I can never remember what E201 is, nor why whoever wrote it decided to disable the message..

If the lint-disabling message is short enough to fit nicely within a regular comment (by being shorter then pylint: disable=...), and reasonably understandably legible identifiers, it could be much less noisy:

try:
    import simplejson as json
except ImportError:
    # Allow fallback to slower builtin JSON module {IgnoreRedefinition}
    import json

The separate .lintignore could be useful to have, but I don't believe it would work for all cases, so having a sensible way to ignore via comments would still be very much worthwhile.

@kevinw
Copy link
Owner

kevinw commented Sep 26, 2012

I do like {IgnoreRedefinition} better than disable=E201. But wouldn't it be better to allow import redefinitions within an ImportError block? That's the idiomatic way to handle different versions of a library anyways.

@dbarnett
Copy link

But wouldn't it be better to allow import redefinitions within an ImportError block?
Excellent point. I'd really like that.

But I do think there's merit in being able to to ignore known pyflakes warnings, as there will always be cases where pyflakes isn't smart enough.

@saper
Copy link
Contributor

saper commented Jan 6, 2013

I am just wondering if pull request #28 solves the most immediate need for this change? Would be glad if you could check.

@dbarnett
Copy link

dbarnett commented Jan 6, 2013

saper: yep, I just checked #28 against the code in amoffat/sh and it gets rid of all the redefinition warnings I wanted to see suppressed without breaking any legitimate warnings. I also played with some legitimate cases like

if True:
    import os
if True:
    import os

and it correctly warned, so I think it's as good as it's gonna be without risking being too aggressive in suppressing warnings.

@nijel
Copy link

nijel commented Jul 17, 2013

Pull request #28 addresses bug in pyflakes, while ignoring is rather for locally overriding something. For example see http://stackoverflow.com/questions/8427701/import-files-in-init-py - Django test discovery forces you to import everything into one module and you don't want to be warned about this, having dozens of not interesting warnings just masks the interesting ones.

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

Successfully merging this pull request may close these issues.