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

How to suppress errors found by pyflakes in Spyder 4 #11033

Closed
ghost opened this issue Dec 11, 2019 · 19 comments · Fixed by #15927
Closed

How to suppress errors found by pyflakes in Spyder 4 #11033

ghost opened this issue Dec 11, 2019 · 19 comments · Fixed by #15927

Comments

@ghost
Copy link

ghost commented Dec 11, 2019

Problem Description

This is from a post I made at the "Spyder" Google Groups. Carlos recommended I open an issue here. The post is as follows:

I just updated to Spyder 4. Nice job developers-- many of the new features (code folding,...) are very useful.

On much of my existing code files that work fine, pyflakes now identifies errors. They appear as red circles in the left margin of the editor. The error message is "Undefined name 'funcname" (pyflakes E)". The errors are because the imports of functions "funcname" are done in an exec statement; I know, I know, using exec like this isn't good form, but I do have my reasons, and this post is about pyflakes more generally than just this specific type of error.

Here are my questions:

  • In the past, other linters or code analysis tools have similarly flagged these same lines for errors, for the same reason. I have been suppressing those error notifications/messages successfully by adding " # analysis:ignore " to the end of the line. Is there a similar way to suppress the pyflakes errors (" # analysis:ignore " does not work)? This sort of solution is really what I need, otherwise I will want to turn pyflakes off. I tried " # NOQA" but it apparently doesn't work. I did some searching around for info on this but came up empty.

  • Is there a pyflakes config file somewhere, in which I can suppress this particular error wherever it occurs?

  • Is there a way to just turn pyflakes off? I could not find it in Preferences.

Secondary question:

  • When I hover my mouse over the red circle, a pop-up box appears, not adjacent to the red circle but some distance away to the right, showing the error message. The pop-up also has a red X in the corner as if I could click it to suppress the error. As soon as I move my mouse off the red circle, towards pop-up in order to attempt to click the red X, the pop-up disappears (because it is not directly adjacent to the red circle in the left margin). So... I can never actually get my mouse over the red X. Is this the intended behavior? Is the red X meant to enable clicking to suppress the error, or not? Only curious about this; these are such common errors that I doubt I would ever click each pop-up.

## Versions
Python 3.6.7 64-bit | Qt 5.9.7 | PyQt5 5.9.2 | Windows 10 

* Spyder version:      4
* Python version:      3.6.7
* Operating System name/version:   Windows 10

About my Qt, PyQt, and dependencies, I already rolled back to Spyder 3 so in order to get them for Spyder 4 I will need to reestablish a new conda env; if this is truly necessary I can do it.
@goanpeca
Copy link
Member

When I hover my mouse over the red circle, a pop-up box appears, not adjacent to the red circle but some distance away to the right, showing the error message. The pop-up also has a red X in the corner as if I could click it to suppress the error. As soon as I move my mouse off the red circle, towards pop-up in order to attempt to click the red X, the pop-up disappears (because it is not directly adjacent to the red circle in the left margin). So... I can never actually get my mouse over the red X. Is this the intended behavior? Is the red X meant to enable clicking to suppress the error, or not? Only curious about this; these are such common errors that I doubt I would ever click each pop-up.

The message has no click functionality on it so it is normal for it to disappear.

@ccordoba12
Copy link
Member

Thanks for reporting. We'll take a look at this in a future release.

@ghost
Copy link
Author

ghost commented Dec 12, 2019 via email

@goanpeca
Copy link
Member

I understand that here in this present context of Spyder and code analysis pyflakes etc, the same graphic red X means only “code has an error”. But still I wonder if some other graphic could be used in its place, which conveys the message “code has an error” but also is not as easily mistaken for meaning “click here to close the window or popup”.

Thanks for the suggestion will try to improve this for the next version

@Dan-Patterson
Copy link

Yes, please fix code analysis. I have basically turned it off and substituted it with static code analysis as I go. Is there any way that flake8 can be used internally instead of pycodestyle?

@ghost
Copy link
Author

ghost commented Jan 14, 2020

Tried Spyder 4.01 now that it's out. Same problem.

I'm not knowledgeable about linting or code completion tools but most of what I've read in terms of documentation for flake8 says it should respect the "# noqa" at the end of a line of code (including within Spyder) to suppress all warnings otherwise generated on that line.

In practice, "# noqa" and "# NOQA" doesn't work for me though-- and others have reported it failing as well in other non-Spyder contexts.

In fact I found flake8-respect-noqa, which I tried, but couldn't get to work (don't know how/where to find/create the config file in which to put the "jobs = 1" line... ?).

Bottom line, because I can't get this flake8 feature to work my only options if I want to be able to take advantage of other Spyder 4 features (instead of sticking with Spyder 3) seem to be:

(1) Just turn linting off entirely (Spyder preferences, Completion and linting section, Linting tab, uncheck the box for "Enable basic linting") and live without the helpful/useful warnings I've been relying on for so long in Spyder 3.

(2) Learn to live with annoying warnings that I had easily and conveniently been suppressing (by "analysis:ignore") when using Spyder 3.

Correct?

@ccordoba12 ccordoba12 modified the milestones: important, v4.1.0 Jan 14, 2020
@ccordoba12
Copy link
Member

@andfoy, please take a look at this one.

@trianta2
Copy link

I too would like to see the return of analysis:ignore in Spyder 4.

I tend to frequently use the @ feature of pandas.DataFrame.query to refer to variables in the environment. I need to suppress these "variable is assigned but not used" false positives.

@ccordoba12
Copy link
Member

This is probably something that needs to be solved in

https://github.com/palantir/python-language-server

but @andfoy will take care of it.

@ccordoba12 ccordoba12 changed the title how to suppress errors found by pyflakes (or turn pyflakes off) How to suppress errors found by pyflakes in Spyder 4 Jan 15, 2020
@ccordoba12 ccordoba12 modified the milestones: v4.1.0, v4.0.2 Jan 16, 2020
@andfoy
Copy link
Member

andfoy commented Jan 23, 2020

I think pyflakes does not support noqa annotations, flake8 should be used instead: PyCQA/pyflakes#431

@goanpeca goanpeca modified the milestones: v4.0.2, v4.1.0 Jan 24, 2020
@ccordoba12 ccordoba12 modified the milestones: v4.2.0, v4.1.0 Jan 24, 2020
@goanpeca goanpeca modified the milestones: v4.1.0, Sprint 2 (February) Feb 18, 2020
@goanpeca goanpeca added v4.2.0 and removed v4.1.0 labels Feb 26, 2020
@kai3341
Copy link
Contributor

kai3341 commented May 8, 2020

I have the same question. I need to import module to get side effect, but code analysis tells %s imported but unused. I'm using workaround (explained here):

import my_cool_module  # noqa
my_cool_module.__package__

But it's ugly. Is there any way to suppress this warning?

@DiegoF90
Copy link

Hi, is there any update on how to ignore code analysis warnings?
I also used to ignore those with "# analysis:ignore (Dict)" but since upgrading to Spyder 4 it does not seem to work any longer.

Also, I do not know if this would be the appropriate channel to raise this, but it would be great if the first line:
# -*- coding: utf-8 -*-
Does not raise a pydocstyle D400 issue.

@ghost
Copy link
Author

ghost commented Jul 20, 2020

I have been staying with Spyder 3 until now, because of this issue. With Spyder 3, adding "# analysis:ignore" (to the end of a line for which the linter causes a warning) works to suppress the warning. This means I can benefit from linting, but also suppress those few warnings the linter sends me for parts of my code for which I have a good reason not to change the code in response to the warning.

Today I tried using Spyder 4.1.4 and as far as I can tell there is no way to get the benefit of linting ("basic", not PEP8 code style) and also be able to suppress specific warnings from the linter. Very unfortunate imho. On the bright side, at least now I can successfully turn off "basic linting", so the unhelpful warnings are suppressed, but of course then I lose the benefits of linting.

(Although not really relevant, because I don't use "PEP8 code style linting", I did notice that if I turn that on-- Preferences, Completion and Linting, Code Style tab-- it does appear to allow suppression of specific messages...)

The above posts have covered various topics but just to refocus, here is what specifically would be very helpful to me, so that I could still benefit from linting but also upgrade to Spyder 4 and start taking advantage of its other features:

  • A working " # analysis:ignore " or " # NOQA " or " # noqa " or equivalent that suppresses warnings the basic linter finds on that line.

  • A way to edit a pyflakes config file or other config somewhere, to suppress a specific warning.

From what I can tell, a fix that addresses this is scheduled for 4.2 at earliest. (Btw, I went to check the roadmap but it seems to no longer exist?)

@ccordoba12
Copy link
Member

@DanCodigaMWRA, we'll see if we can switch to flake8 from pyflakes for 4.2.0, which provides this functionality.

@ghost
Copy link
Author

ghost commented Jul 21, 2020

Thank you Carlos for considering ways to enable a fix for this in 4.2.0, including switching away from flake8 if that is what it takes.

However, at the flake8 github site, it claims to be "a wrapper around PyFlakes, pycodestyle, and Ned Batchelder's McCabe script", so I'm unsure if flake8 can just be replaced by pyflakes.

Should the failure of #analysis:ignore or #noqa to work be posted as an issue at the flake8, PyFlakes, and/or pycodestyle github site(s)?

The documentation for flake8 clearly states that adding #noqa at the end of a line should suppress its warnings for that line. When in Spyder I'm finding that's not true, so it seems like I should report it as an issue, but it's unclear to me where would be the right place to do so.

@ccordoba12
Copy link
Member

The documentation for flake8 clearly states that adding #noqa at the end of a line should suppress its warnings for that line. When in Spyder I'm finding that's not true

Sorry if I was not clear enough in my previous answer. Right now we're using Pyflakes for linting, which doesn't support the #noqa convention (as far as we know). So that's why we're considering to switch to Flake8 for 4.2.

@ghost
Copy link
Author

ghost commented Jul 21, 2020

Ok yes d'oh! You wrote it correctly, I read it backwards (and had forgotten the title of this entire issue), sorry.

So it would be a switch to flake8 from pyflakes. I'm not knowledgeable about linters (let alone linters that spyder could integrate) but some quick superficial searching suggests that if pylint was an option it might be worth considering too. Thanks again.

@ccordoba12
Copy link
Member

if pylint was an option it might be worth considering too

We're also considering to add support for Pylint, but as an advanced linter because it usually requires a config file to be usable (it lints way too many stuff).

@ccordoba12
Copy link
Member

Sorry for the long time it took us to fix this. It'll be available since our 5.1.0 version, to be released at the end of July.

Please see PR #15927 for the inline comments we will support on that version to skip linting messages.

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