GithubHelp home page GithubHelp logo

pycqa / pyflakes Goto Github PK

View Code? Open in Web Editor NEW
1.4K 1.4K 182.0 942 KB

A simple program which checks Python source files for errors

Home Page: https://pypi.org/project/pyflakes

License: MIT License

Python 100.00%
hacktoberfest linter python

pyflakes's People

Contributors

adamchainz avatar adiroiban avatar alexandrul avatar ambv avatar ankitxjoshi avatar asmeurer avatar asottile avatar attilaolah avatar bitglue avatar dannysepler avatar exarkun avatar florentx avatar hanaasagi avatar hugovk avatar jayvdb avatar jdufresne avatar joernheissler avatar jwilk avatar kevinw avatar laurentb avatar mgedmin avatar mithrandi avatar msullivan avatar myint avatar peterjclaw avatar ryneeverett avatar sbraz avatar scop avatar sigmavirus24 avatar terencehonles avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyflakes's Issues

pyflakes crashes on syntactically correct python syntax

Original report by psychicsurgeon on Launchpad:


This is the code in question

try:
if logger.isEnabledFor(logging.DEBUG):
logger.debug("Writing buffer of %d byts" % len(buf))
pylibg15.write_pixmap(buf)
except IOError as (errno, strerror): #<- Crashes on this line
Slogger.error("Failed to send buffer. %d: %s" % ( errno, strerror ) )
traceback.print_exc(file=sys.stderr)
self.disconnect()

This is the traceback.

Traceback (most recent call last):
File "/usr/local/bin/pydbgr", line 9, in
load_entry_point('pydbgr==0.1.5', 'console_scripts', 'pydbgr')()
File "/usr/local/lib/python2.7/dist-packages/pydbgr-0.1.5-py2.7.egg/pydbgr/cli.py", line 337, in main
normal_termination = dbg.run_script(mainpyfile)
File "/usr/local/lib/python2.7/dist-packages/pydbgr-0.1.5-py2.7.egg/pydbgr/debugger.py", line 207, in run_script
execfile(self.mainpyfile, globals_, locals_)
File "/usr/local/lib/python2.7/dist-packages/flake8-1.5-py2.7.egg/flake8/run.py", line 234, in
main()
File "/usr/local/lib/python2.7/dist-packages/flake8-1.5-py2.7.egg/flake8/run.py", line 82, in main
warnings += check_file(path, complexity)
File "/usr/local/lib/python2.7/dist-packages/flake8-1.5-py2.7.egg/flake8/run.py", line 27, in check_file
warnings += pyflakes.checkPath(path)
File "/usr/local/lib/python2.7/dist-packages/flake8-1.5-py2.7.egg/flake8/pyflakes.py", line 656, in checkPath
return check(open(filename, 'U').read() + '\n', filename)
File "/usr/local/lib/python2.7/dist-packages/flake8-1.5-py2.7.egg/flake8/pyflakes.py", line 707, in check
w = Checker(tree, filename)
File "/usr/local/lib/python2.7/dist-packages/flake8-1.5-py2.7.egg/flake8/pyflakes.py", line 192, in init
self._runDeferred(self._deferredFunctions)
File "/usr/local/lib/python2.7/dist-packages/flake8-1.5-py2.7.egg/flake8/pyflakes.py", line 228, in _runDeferred
handler()
File "/usr/local/lib/python2.7/dist-packages/flake8-1.5-py2.7.egg/flake8/pyflakes.py", line 571, in runFunction
self.handleNode(stmt, node)
File "/usr/local/lib/python2.7/dist-packages/flake8-1.5-py2.7.egg/flake8/pyflakes.py", line 299, in handleNode
handler(node)
File "/usr/local/lib/python2.7/dist-packages/flake8-1.5-py2.7.egg/flake8/pyflakes.py", line 277, in handleChildren
self.handleNode(node, tree)
File "/usr/local/lib/python2.7/dist-packages/flake8-1.5-py2.7.egg/flake8/pyflakes.py", line 299, in handleNode
handler(node)
File "/usr/local/lib/python2.7/dist-packages/flake8-1.5-py2.7.egg/flake8/pyflakes.py", line 277, in handleChildren
self.handleNode(node, tree)
File "/usr/local/lib/python2.7/dist-packages/flake8-1.5-py2.7.egg/flake8/pyflakes.py", line 299, in handleNode
handler(node)
File "/usr/local/lib/python2.7/dist-packages/flake8-1.5-py2.7.egg/flake8/pyflakes.py", line 277, in handleChildren
self.handleNode(node, tree)
File "/usr/local/lib/python2.7/dist-packages/flake8-1.5-py2.7.egg/flake8/pyflakes.py", line 299, in handleNode
handler(node)
File "/usr/local/lib/python2.7/dist-packages/flake8-1.5-py2.7.egg/flake8/pyflakes.py", line 340, in EXCEPTHANDLER
name = node.name.id
AttributeError: 'Tuple' object has no attribute 'id'

I agree that this particular piece of code is VERY poor and only kind of works. But it's not my code, and pyflakes should handle it since it technically is valid syntax.

pyflakes native support for Python 3

Original report by barry (@warsaw?) on Launchpad:


Let's say you have this file:

#! /usr/bin/python
from __future__ import print_function
import sys
print('test', file=sys.stderr)

then pyflakes correct recognizes the print function and is happy. However, let's say you change the first line to

#!/usr/bin/python3

and remove the future import. Then pyflakes isn't so happy about the print() function.

No doubt it's a considerable amount of work to support Python 3 directly, but at least with this bug we can track that effort.

pyflakes crashed with AttributeError in handleNode(): 'Checker' object has no attribute 'SET'

Original report by barry (@warsaw?) on Launchpad:


Binary package hint: pyflakes

Just editing some file

ProblemType: Crash
DistroRelease: Ubuntu 11.04
Package: pyflakes 0.4.0-1
ProcVersionSignature: Ubuntu 2.6.38-8.42-generic 2.6.38.2
Uname: Linux 2.6.38-8-generic x86_64
Architecture: amd64
Date: Wed Apr 20 22:17:49 2011
ExecutablePath: /usr/bin/pyflakes
InstallationMedia: Ubuntu 11.04 "Natty Narwhal" - Beta amd64 (20110413)
InterpreterPath: /usr/bin/python2.7
PackageArchitecture: all
ProcCmdline: /usr/bin/python /usr/bin/pyflakes models_mongo_flymake.py
ProcEnviron:
SHELL=/bin/bash
LANG=ru_UA.UTF-8
PATH=(custom, user)
LANGUAGE=ru_UA:en
PythonArgs: ['/usr/bin/pyflakes', 'models_mongo_flymake.py']
SourcePackage: pyflakes
Title: pyflakes crashed with AttributeError in handleNode(): 'Checker' object has no attribute 'SET'
UpgradeStatus: No upgrade log present (probably fresh install)
UserGroups: adm admin cdrom dialout lpadmin plugdev sambashare

switch to unittest2 for the test framework

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


I propose to switch to unittest2 instead of Twisted in order to test against more versions of Python (2.5 and Python 3).

Moreover unittest is more focused than the Twisted framework and it is less code to download and install (for automated tests).

using del in if clause confuses pyflakes

Original report by david-szotten on Launchpad:


code:

test = True
if False:
    del(test)
assert(test)

pyflakes complains:
[...].py:4: undefined name 'test'

i guess this may be too hard for a static analysier, in which case, how about

test = True
if False:
    del(test)
else:
    assert(test)

where the usage is in a different else branch to the del

output:
[...].py:5: undefined name 'test'

"trial pyflakes/test" fails at test_missingTrailingNewline

Original report by dejv on Launchpad:


pyflakes 0.5.0 fails in pyflakes.test.test_script.CheckTests.test_missingTrailingNewline on RHEL 6 / Python 2.6.6:

===============================================================================
[FAIL]: pyflakes.test.test_script.CheckTests.test_missingTrailingNewline

Traceback (most recent call last):
  File "/home/david/rpmbuild/BUILD/pyflakes-0.5.0/pyflakes/test/test_script.py", line 38, in test_missingTrailingNewline
    self.assertFalse(checkPath(fName))
twisted.trial.unittest.FailTest: None
-------------------------------------------------------------------------------

pyflakes was installed using pypi/pip:

# pip-python install pyflakes
Downloading/unpacking pyflakes
  Downloading pyflakes-0.5.0.tar.gz
  Running setup.py egg_info for package pyflakes
Installing collected packages: pyflakes
  Running setup.py install for pyflakes
    changing mode of build/scripts-2.6/pyflakes from 644 to 755
    changing mode of /usr/bin/pyflakes to 755
Successfully installed pyflakes
Cleaning up...

If you need any more information, please ask for it.

support "setup.py test" and "setup.py develop"

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


The setup.py could optionally use distribute/setuptools if it is available in the path.

The library distribute (or setuptools) is very common in the Python ecosystem, and many tools depend on them, like "pip install", "virtualenv", "zc.buildout", ...
Of course there's some criticism about these tools, but they exist, they are compatible, and they work fine for a lot of developers.
They fill a use case as explained below.

The benefit of using distribute/setuptools is the additional verbs which are available, like:

$ python setup.py test

This allows to run the tests, and it takes care of installing the 'test_requires' dependencies without other action. Anyone can run the tests without any assumption about the test framework, and without digging through the source code to know which libraries are required (nose, py.test, twisted.trial, unittest, etc...).
This particular use case is not supported by the distutils library.

Another verb which is widely used but not supported by distutils:

$ python setup.py develop

And the best is that it is fully optional.
When the distribute/setuptools package is not installed, it imports 'setup' from distutils and it behaves exactly the same as before.

For the record, there are some users which already suggested this change: kevinw/pyflakes#19

Detect tautological asserts

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


An assert of the form:

assert (x, 'blahblah')

is tautological, because a non-empty tuple always has a truth value of True. However, it is common to mistakenly construct an assert statement of this form when attempting to wrap it over multiple lines. Python 2.6+ already issues a SyntaxWarning about this, but it would be nice if Pyflakes detected it too.

AttributeError in a Turkish locale

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


A user came into the #vim channel on IRC looking for help with the pyflakes plugin. I tracked down the error to a bug(?) in pyflakes: it doesn't work in a Turkish locale. Instead you get

AttributeError: 'Checker' object has no attribute 'ATTRiBUTE'

Screenshot of the original error: http://i.imgur.com/gAfRB.png

The user's locale:
LANG=tr_TR.UTF-8
LANGUAGE=
LC_CTYPE="tr_TR.UTF-8"
LC_NUMERIC="tr_TR.UTF-8"
LC_TIME="tr_TR.UTF-8"
LC_COLLATE="tr_TR.UTF-8"
LC_MONETARY="tr_TR.UTF-8"
LC_MESSAGES="tr_TR.UTF-8"
LC_PAPER="tr_TR.UTF-8"
LC_NAME="tr_TR.UTF-8"
LC_ADDRESS="tr_TR.UTF-8"
LC_TELEPHONE="tr_TR.UTF-8"
LC_MEASUREMENT="tr_TR.UTF-8"
LC_IDENTIFICATION="tr_TR.UTF-8"
LC_ALL=

This workaround fixed the error for that user:

edit that pyflakes/checker.py file, find line 317 (actual number might differ depending on the version) -- the line that does nodeType = node.__class__.__name__.upper()
change it to nodeType = node.__class__.__name__.upper().replace("i", "I")

allow to specify checker mixins

Original report by ronny-pfannschmidt-deactivatedaccount on Launchpad:


this would allow to do propper support for framework specific extra checks/bindings outside of pyflakes

for example, instead of the execnet support, i could pass in a mixin that overrides the check
or instead of the ErrorReturn check, that could also be a mixin

same goes for supporting __tracebackhide__

Please also check python scripts that are not named *.py

Original report by morph-debian on Launchpad:


Hello,
as reported on Debian at http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=653890:

"""
It would be great if pyflakes could detect files that are python scripts
but are not named *.py. It would have to read the first two bytes of
each file to check for scripts and then read the rest of the line to
determine if it is a python script. It would need to process stuff like:

#!/usr/bin/python
#!/usr/local/bin/python
#!/usr/bin/env python
#!/usr/bin/python2.6
#!/usr/bin/python3.2
"""

Regards,
Sandro

Incorrect line numbers for decorated functions

Original report by yatc18ks0-9a-ngeefk4xa on Launchpad:


In the code:

def decorator(func):
    return func


@decorator
def defined_twice():
    pass


@decorator
def defined_twice():
    pass

Pyflakes gives the error: twice.py:10: redefinition of function 'defined_twice' from line 5

It ought to be: twice.py:11: redefinition of function 'defined_twice' from line 6

Pay attention to doctests

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


A lot of Zope packages use the following style for their unit tests:

import doctest

from somepackage import something

def doctest_something_does_it_right():
    """

        >>> something('the ultimate answer')
        42

    """

def test_suite():
    return doctest.DocTestSuite()

Since pyflakes doesn't pay attention to doctests in docstrings, it tends to produce huge amount of false positives ("unused name 'something') and it misses possible issues in the doctest code.

There's an old patch by Ignas Mikalajūnas that adds doctest support to pyflakes. I've been using it for a long time in my fork (lp:~mgedmin/pyflakes/pyflakes-mg). Florent Xicluna recently rebased it on top of the latest pyflakes in https://code.launchpad.net/~pyflakes-dev/pyflakes/0.6-doctest-support

please support reinitialization idiom

Original report by gregcouch on Launchpad:


The following fails in pyflakes with "undefined name '_foo'" even though it is always defined before use:

def _init_globals():
    global _foo, _bar, _snafu
    _foo = 42
   _bar = "string"
   _snafu = 3.14
_init_globals()

# lots of other stuff

def reset():
     # reset other stuff
    _init_globals()

Detect misuse of except

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


It would be nice if pyflakes could detect mistakes like this:

   try:
       oldtime = os.path.getmtime(fname)
   except OSError, IOError:
       oldtime = 0

In the general case, it's obviously difficult to tell whether this is an error or not; but I suspect that handling the exception variable name as a binding would give you a "redefinition of Foo" warning in most of the cases where a mistake has been made.

Recognize _("text") from gettext.install(...)

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


gettext module provides convenience function gettext.install() that injects a callable _ [single underscore] into builtins, so that internationalized code can be written like this:

print _("text")

pyflakes reports every _ as undefined symbol.

moreover since it is injected in builtins, all imported modules have that symbol, thus the following works:

# main.py
import gettext
import somemod
gettext.install(...)

#somemod.py
print _("text")

I'm not sure what sort of heuristic could be used to recognize _() when pyflake checks somemod.py.
Perhaps a command line argument for extra builtins?

Pyflakes does not recognize locals() as a use

Original report by ato2g-andrew on Launchpad:


See attached program for a trivial example of a common idiom:

"my special string %(with_a_variable)s"%locals()

I wouldn't expect pyflakes to know how to deal with an arbitrary dictionary in the right hand position, but the use of locals() means that certain variables are actually used!

Cascading try/except imports report duplicates

Original report by 4-launchpad-tim-thechases-com on Launchpad:


With the attached example file, pyflakes reports

pf.py:6: redefinition of unused 'connect' from line 3
pf.py:6: redefinition of unused 'PARSE_DECLTYPES' from line 3
pf.py:6: redefinition of unused 'PARSE_COLNAMES' from line 3

They're not redefinitions, but fallbacks in case defining them the first time fails. I don't know if there's a way to catch this, but it's worth noting.

move Pyflakes to its own repository

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


Hello,

Following the discussion on the mailing-list, I propose to extract the Pyflakes repository and publish it under the Pyflakes project.

The main reason is that it is less confusing for all
the actors (users, developers, etc...) to find the project at a single
place: the source code, the issue tracker, the downloads...
Second reason, is that it makes it easier for external contributions. You
only clone the PyFlakes project, without need to download the code of all
the unrelated Divmod's projects. Same benefit when someone want to mirror
the code on any other VCS.
And the PyFlakes project is so widely used, that it deserves to have its
own repository.

I did an export of the current state of the Pyflakes/ folder, with history.
It is available as lp:~divmod-dev/pyflakes/trunk

If accepted, the next moves are:

Then the open issues will be reviewed and the merge proposals will be updated to target the new repository.
(There's only few small patches, I already had a look)

ValueError: invalid \x escape

Original report by morph-debian on Launchpad:


Hello,
I'm reporting http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=674797:

If the tested file contains invalid \x escape, pyflakes fails with traceback:

$ pyflakes test.py
Traceback (most recent call last):
File "/usr/bin/pyflakes", line 5, in
sys.exit(main(sys.argv[1:]))
File "/usr/lib/pymodules/python2.7/pyflakes/scripts/pyflakes.py", line 92, in main
warnings += checkPath(arg)
File "/usr/lib/pymodules/python2.7/pyflakes/scripts/pyflakes.py", line 74, in checkPath
return check(fd.read(), filename)
File "/usr/lib/pymodules/python2.7/pyflakes/scripts/pyflakes.py", line 28, in check
tree = compile(codeString, filename, "exec", _ast.PyCF_ONLY_AST)
ValueError: invalid \x escape
<<<

with test.py being:

foo = '\xyz'
<<<

Regards,
Sandro

pyflakes script not executable on Windows

Original report by jaraco on Launchpad:


Pyflakes script is installed on Windows without any extension. As a result, on Windows, it has no file type and cannot be executed from a command-line. Consider using setuptools console_script entry_points or adding a .py extension when installing under Windows.

PS C:\Users\jaraco> easy_install pyflakes
Searching for pyflakes
Reading http://pypi.python.org/simple/pyflakes/
Reading http://www.divmod.org/projects/pyflakes
Reading http://www.divmod.org/trac/wiki/DivmodPyflakes
Best match: pyflakes 0.4.0
Downloading http://pypi.python.org/packages/source/p/pyflakes/pyflakes-0.4.0.tar.gz#md5=630a72510aae8758f48cf60e4fa17176
Processing pyflakes-0.4.0.tar.gz
Running pyflakes-0.4.0\setup.py -q bdist_egg --dist-dir c:\users\jaraco\appdata\local\temp\easy_install-bi_1bs\pyflakes-0.4.0\egg-dist-tmp-u6vcvn
hgtools.SubprocessManager('.') could not find files: abort: There is no Mercurial repository here (.hg not found)!
zip_safe flag not set; analyzing archive contents...
pyflakes.checker: module references file
pyflakes.checker: module references path
pyflakes.test.test_undefined_names: module references file
pyflakes.test.test_undefined_names: module references path
Adding pyflakes 0.4.0 to easy-install.pth file
Installing pyflakes script to C:\Python\Scripts

Installed c:\python\lib\site-packages\pyflakes-0.4.0-py2.7.egg
Processing dependencies for pyflakes
Finished processing dependencies for pyflakes

Erroneous 'list comprehension redefines' in Python 2.7 pyflakes 0.6.1

Original report by jfalkner on Launchpad:


When updating from pyflakes 0.5.0 to pyflakes 0.6.1 many occurances of 'list comprehension redefines' are listed erroneously. The issue appears to be that pyflakes will complain about reusing the same loop variable name in multiple list comprehensions.

Here are two lines for example:

168:
wells = Well.objects.filter(id__in=(well.id for well in wells))

...

183:
fx_wells = [well for well in wells if well.assay_subtype == fx_subtype]

And a message such as below appears.

foo/bar.py:183:: list comprehension redefines 'well' from line 168

In this case pyflakes should be smart enough to realize that 'well' will not be incorrectly used because it will be initialized immediately with the expected value in the second list comprehension.

default name for co-installed python2 & python3 pyflakes

Original report by xnox on Launchpad:


In debian we would like to ship co-installable python2 and python3 versions of pyflakes.
This brings the question of what to do with the scripts.
Currently we only have:
/usr/bin/pyflakes with default python2.X interpreter.

What should we do:
a) /usr/bin/py3flakes
b) /usr/bin/pyflakes3
c) ship __main__.py in pyflakes module and make people use similar to unittest, e.g. python3.x -m pyflakes . (thus avoiding shipping scripts all together)

Please let us know your thoughts on this.

Regards,

Dmitrijs.

Support for "yield from"

Original report by sscherfke on Launchpad:


Current pylfakes 0.6.1 doesn’t recognize Python 3.3’s "yield from" syntax:

# test.py
def spam():
    yield from range(10)
stefan@nboffis28:/tmp/test☿$ pyflakes test.py 
test.py:2: invalid syntax
    yield from range(10)
              ^

py3flakes test suite failure

Original report by xnox on Launchpad:


======================================================================
FAIL: test_invalidEscape (pyflakes.test.test_api.CheckTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/tdlk/personal-src/python/python-apps/packages/pyflakes/build-area/pyflakes-0.6.1/pyflakes/test/test_api.py", line 414, in test_invalidEscape
    sourcePath, [decoding_error])
  File "/home/tdlk/personal-src/python/python-apps/packages/pyflakes/build-area/pyflakes-0.6.1/pyflakes/test/test_api.py", line 263, in assertHasErrors
    (count, err.getvalue()), (len(errorList), ''.join(errorList)))
AssertionError: Tuples differ: (1, "/tmp/tmpuzz1ow:1: (unicod... != (1, "/tmp/tmpuzz1ow:1: (unicod...

First differing element 1:
/tmp/tmpuzz1ow:1: (unicode error) 'unicodeescape' codec can't decode bytes in position 0-1: truncated \xXX escape
foo = '\xyz'
       ^

/tmp/tmpuzz1ow:1: (unicode error) 'unicodeescape' codec can't decode bytes in position 0-2: truncated \xXX escape
foo = '\xyz'
       ^


  (1,
-  "/tmp/tmpuzz1ow:1: (unicode error) 'unicodeescape' codec can't decode bytes in position 0-1: truncated \\xXX escape\nfoo = '\\xyz'\n       ^\n")
?                                                                                            ^

+  "/tmp/tmpuzz1ow:1: (unicode error) 'unicodeescape' codec can't decode bytes in position 0-2: truncated \\xXX escape\nfoo = '\\xyz'\n       ^\n")
?                                                                                            ^


----------------------------------------------------------------------
Ran 221 tests in 0.314s

FAILED (failures=1, skipped=8)

When run as:
python3.3 -m unittest discover

Warn about string exceptions

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


These can take several forms:

raise "shouldn't happen"
raise 'Cannot determine type of callable: '+repr(callableObject)
raise "Can't read input parameters file : %s" % options.input_file

Some of these will be harder to detect than others.

Add support for ignoring some warnings

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))

"import as" can cause spurious "imported but unused" warnings

Original report by bcs26 on Launchpad:


Pyflakes will generate a spurious "imported but unused" warning for the following code:

import selenium as se
import selenium.webdriver

se.webdriver.Firefox("foo")

Note that Pyflakes will, correctly, not generate such a warning for the following:

import selenium
import selenium.webdriver

se = selenium

se.webdriver.Firefox("foo")

pyflakes complains about missing WindowsError on Unix

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


Since pyflakes website is down I am reporting this bug in LP.

The undefined name WindowsError is raised by pyflakes when running on Unix systems.

It would be nice if pyflakes would trust the developer that such code is only loaded on Windows and allow to check Windows specific Python code on Unix.


Please let me know if you thinks it is a valid problem.

Also any advice about how to move this bug report upstream is much appreciated.


I have also attached a pocket-lint branch that works around this problem.

Cheers,

property decorator -> redefinition of function

Original report by cassapanco on Launchpad:


Code from: http://docs.python.org/library/functions.html#property

foo.py

class C(object):
    def __init__(self):
        self._x = None

    @property
    def x(self):
        """I'm the 'x' property."""
        return self._x

    @x.setter
    def x(self, value):
        self._x = value

    @x.deleter
    def x(self):
        del self._x

pyflakes output is

$ pyflakes foo.py
foo.py:11: redefinition of function 'x' from line 6
foo.py:15: redefinition of function 'x' from line 11

TypeError: compile() expected string without null bytes

Original report by morph-debian on Launchpad:


Hello,
I'm reporting http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=674796:

If the tested file contains null bytes, pyflakes fails with traceback:

$ pyflakes test.py
Traceback (most recent call last):
File "/usr/bin/pyflakes", line 5, in
sys.exit(main(sys.argv[1:]))
File "/usr/lib/pymodules/python2.7/pyflakes/scripts/pyflakes.py", line 92, in main
warnings += checkPath(arg)
File "/usr/lib/pymodules/python2.7/pyflakes/scripts/pyflakes.py", line 74, in checkPath
return check(fd.read(), filename)
File "/usr/lib/pymodules/python2.7/pyflakes/scripts/pyflakes.py", line 28, in check
tree = compile(codeString, filename, "exec", _ast.PyCF_ONLY_AST)
TypeError: compile() expected string without null bytes
<<<

Attached the test file.

Regards,
Sandro

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.