EzDevInfo.com

pyflakes

A simple program which checks Python source files for errors. Pyflakes in Launchpad

Settings preferences to pyflakes (with python-mode in vim)

I'm getting lots of errors I don't care about: mostly this kind:

fabfile.py|2 error| W0611 'os' imported but unused [pyflakes]

when I import something I'm going to use later but not yet

Is there a way (similar to a .jshintrc file when using jshint) file to Silence certain pyflakes errors warnings?

Thanks!


Source: (StackOverflow)

Errors when running vim with the pyflakes plugin


I'm playing with the pyflakes plugin for vim and now when I open a python file I get the error messages in the screenshot here

Any ideas how to fix this?

Thanks in advance...


Source: (StackOverflow)

Advertisements

Is there a plugin for pylint and pyflakes for nose tests?

I wonder if there is a nose plugin for pylint and/or pyflakes?

Currently I am using coverage and tissue (PEP8) plugins for nose tests.

Tnx in advance


Source: (StackOverflow)

Excluding directory from Pyflakes

I am working on a django project and am trying to run pyflakes on an app in it. I need to exclude the "migrations" directory from pyflakes.

For pep8 I can do

pep8 --exclude=migrations app_name

Is there any similar way for pyflakes?

I couldn't find any proper documentation for pyflakes.


Source: (StackOverflow)

Vim: Pyflakes Conflicting With Vimgrep/Grep

I just recently installed Pyflakes Vim plugin. It works very fine and is very helpful. Unfortunately it uses the error list in case there is an error. So if I make a search-in-files using Vimgrep or Grep, then after using :cnext to show the next error, the error list will most probably be replaced with the list of errors generated by Pyflakes automatically.

Any idea how this can be solved?


Source: (StackOverflow)

Are there any static analysis tools for Python? [closed]

I am starting to use Python (specifically because of Django) and I would like to remove the burden for exhaustive testing by performing some static analysis. What tools/parameters/etc. exist to detect issues at compile time that would otherwise show up during runtime? (type errors are probably the most obvious case of this, but undefined variables are another big one that could be avoided with an in-depth analysis of the AST.)

Obviously testing is important, and I don't imply that tests can be obviated entirely; however, there are many runtime errors in python that are not possible in other languages that perform stricter run-time checking -- I'm hoping that there are tools to bring at least some of these capabilities to python as well.


Source: (StackOverflow)

How do I get Pyflakes to ignore a statement?

A lot of our modules start with:

try:
    import json
except ImportError:
    from django.utils import simplejson as json  # Python 2.4 fallback.

...and it's the only Pyflakes warning in the entire file:

foo/bar.py:14: redefinition of unused 'json' from line 12

How can I get Pyflakes to ignore this?

(Normally I'd go read the docs but the link is broken. If nobody has an answer, I'll just read the source.)


Source: (StackOverflow)

How would I start integrating pyflakes with Hudson

We use Hudson for continuous integration with the Violations Plugin which parses our output from pylint. However, pylint is a bit too strict, and hard to configure. What we'd rather use is pyflakes which would give us the right level of "You're doing it wrong."


Source: (StackOverflow)

vim-flake8 is not working

I installed vim-flake8 by git cloning it on my Pathogen bundle folder as usual, but when I tried to run the plugin pressing F7 or using :call Flake8() in one Python file I receive the following message:

Error detected while processing function Flake8:

line 8:

File flake8 not found. Please install it first.

Anyone has some clue about what is going on ?


Source: (StackOverflow)

What does pyflakes w804 signify?

I'm working on a decorator that will retry running a function up to N times as follows:

def retry(exceptions, truncate=5, delay=0.25):                                     
      """Retry the decorated function using an exponential backoff strategy.         
      If the function does not complete successfully a TimeoutException is           
      raised."""                                                                     
      def wrapper(func):                                                             
          @wraps(func)                                                               
          def wrapped(*args, **kwargs):                                              
              tries = 0                                                              
              while tries < truncate:                                                
                  try:                                                               
                      return func(*args, **kwargs)                                   
                  except exceptions, e:                                              
                      print "%s, Retrying in %d seconds..." % (str(e), delay)        
                      time.sleep(delay)                                              
>>                    delay += delay                                                 
                      tries += 1                                                     
              else:                                                                  
                  raise TimeoutException()                                           
          return wrapped                                                             
      return wrapper

To me the code looks sensible, but on the line highlighted pyflakes complains, reporting:

W804 local variable 'delay' (defined in enclosing scope on line x) referenced before assignment

This doesn't quite make sense to me. delay has been assigned a value, and I presumably should be able to reference it as a I please. Can someone explain what the error is, and if reasonable, how I can fix it?


Source: (StackOverflow)

Flake8 not using pyflakes in global python instance

My pyflakes portion of flake8 is not running for my global python instance (/usr/bin/python, not virtualenv).

flake8 --version
2.2.3 (pep8: 1.5.7, mccabe: 0.2.1) CPython 2.7.5 on Darwin

It doesn't seem like pyflakes is getting attached to flake8. pip freeze confirms that pyflakes==0.8.1 is installed. I installed on my global site-packages ($ sudo pip install flake8).

However, when running inside of a virtualenv, pyflakes is in the list and flake8 works as expected.


Source: (StackOverflow)

Set up atom linter-python on Windows?

I am trying to get a Python linter working in the atom editor on Windows 7 but it seems to do nothing.

I have:

  1. Installed the latest atom editor (version 0.194.0) on Windows,
  2. Installed linter, and
  3. Installed linter-pyflakes.
  4. Set the following in my atom config file as instructed in linter-pyflakes' README file.

    "linter-pyflakes": pyflakesExecutablePath: "C:\Users\blokeley\Anaconda3\Scripts"

There seems to be no linter activity when I edit a Python file.

I opened an issue on the linter-pyflakes project but it got no response.

Is the path to the executable wrong? How can I check what linter is doing?


Source: (StackOverflow)

Checking unwanted type change in Python

I come from static-type programming and I'm interested in understanding the rationale behind dynamic-type programming to check if dynamic-type languages can better fit my needs.

I've read about the theory behind duck programming. I've also read that unit testing (desirable and used in static-type programming) becomes a need in dynamic languages where compile-time checks are missing.

However, I'm still afraid to miss the big picture. In particular, how can you check for a mistake where a variable type is accidentally changed ?

Let's make a very simple example in Python:

#! /usr/bin/env python

userid = 3
defaultname = "foo"

username = raw_input("Enter your name: ")
if username == defaultname:
    # Bug: here we meant userid...
    username = 2

# Here username can be either an int or a string
# depending on the branch taken.
import re
match_string = re.compile("oo")
if (match_string.match(username)):
        print "Match!"

Pylint, pychecker and pyflakes do not warn about this issue.

What is the Pythonic way of dealing with this kind of errors ?

Should the code be wrapped with a try/catch ?


Source: (StackOverflow)

Indentation configuration in flake8

My project uses a width of 4 spaces for indentation.

However, running flake8 on it yields warnings that say that expected tab/indentation width was 2 spaces.

How do I configure flake8 to correctly accept 4 spaces for indentation?

class Foo(object):
    bar = True

Above mentioned is my (over simplified) code fragment flake8 flags line #2 with a warning saying:

[W0311] Bad indentation. Found 4 spaces, expected 2

I am using vim with flake8 plugin.

In my .pylintrc:

[FORMAT]
indent-string='    '

However, I am not sure how .pylintrc even comes into picture, since the linting is done by the flake8 vim plugin


Source: (StackOverflow)

Ignore doctests/docstrings with pyflakes/pylint

Right now, if I have some function like this and I'd like to be able to get the error about index not being defined, while ignoring the error that some_index is not defined.

def myfunction(ind, other):
   """
   Parameters
   ----------
   ind: Index
   other: Index or set

   Returns
   -------
   Index.

   Examples
   --------

   >>> myfunction(some_index, other)
   """
   return index + other

If I run this through flake8 I get:

file.py:15:1: F821 undefined name 'other'
file.py:15:1: F821 undefined name 'some_index'
file.py:17:1: F821 undefined name 'index'

But what I want to see is just the index error and ignore the others:

file.py:17:1: F821 undefined name 'index'

If I run pylint or pyflakes on it, gives an error about some_index and other not being defined (which is True, but not necessarily useful all the time). How do I tell the programs to skip those errors? I'm working on a big library with many examples scattered throughout, some of which aren't defined but are just set to be examples of how to call them. Yes, it isn't great to not be able to run the doctests, but for the moment, it adds a ton of noise to pylint or pyflakes output. Flake8 doesn't seem to offer the option to skip them either.

How can I make this work? Is there an easy way to detect which things are docstrings in Python and filter the results that way?


Source: (StackOverflow)