Possible false positives in Pyflakes
I tried reaching someone from Pyflakes in the IRC channel on freenode and was kindly redirected to this mailinglist, so please tell me if this is not the appropriate place for my questions. I discovered Pyflakes a few weeks ago and I'm using it in a project. But it seems that I'm not able to get rid of a few errors it reports. I'm by no means a Python professional, so this may be a mistake on my side. The following three error messages do not make sense for me:
dslrpicontrol/models.py:26: invalid syntax flash(u'Auto-detection request failed', 'danger') ^ dslrpicontrol/errorhandlers.py:15: invalid syntax return render_error(404, u'Page not found') ^ dslrpicontrol/__init__.py:28: 'dslrpicontrol' imported but unused
If you want to see the specific position, I hilighted the exact lines here:
https://github.com/daniel-j-h/dslr-pi-control/blob/master/dslrpicontrol/mode... https://github.com/daniel-j-h/dslr-pi-control/blob/master/dslrpicontrol/erro... https://github.com/daniel-j-h/dslr-pi-control/blob/master/dslrpicontrol/__in...
The first two 'invalid syntax' error reports do not make sense to me. Why is the syntax invalid? The Python interpreter does The Right Thing. More about the flash() function here:
http://flask.pocoo.org/docs/patterns/flashing/#flashing-with-categories http://flask.pocoo.org/docs/api/#message-flashing
The last 'imported but unused' error report probably comes from the circular imports? This idiom was actually recommended by the Flask docs. Is this also a false positive? I'm glad for any hints. Cheers, Daniel
Hello Daniel, you see the syntax issue because you installed Pyflakes for Python 3.1 or 3.2, and you are checking code which is syntactically wrong for these versions of Python (The u"" prefix is only supported with Python 2.x or Python >= 3.3). Because Pyflakes is based on the AST module from the standard library, it is dependent on the version of Python. See also: https://bugs.launchpad.net/pyflakes/+bug/1169552 The last case, about unused import, could be seen as a false positive. Usually you can get rid of the warning if you declare these __init__ imports in the special __all__ variable. http://docs.python.org/2/tutorial/modules.html#importing-from-a-package The related issue, with details https://bugs.launchpad.net/pyflakes/+bug/1178905 Best regards, -- Florent Xicluna 2013/6/7 Daniel Hofmann <daniel@trvx.org>:
I tried reaching someone from Pyflakes in the IRC channel on freenode and was kindly redirected to this mailinglist, so please tell me if this is not the appropriate place for my questions.
I discovered Pyflakes a few weeks ago and I'm using it in a project. But it seems that I'm not able to get rid of a few errors it reports.
I'm by no means a Python professional, so this may be a mistake on my side.
The following three error messages do not make sense for me:
dslrpicontrol/models.py:26: invalid syntax flash(u'Auto-detection request failed', 'danger') ^ dslrpicontrol/errorhandlers.py:15: invalid syntax return render_error(404, u'Page not found') ^ dslrpicontrol/__init__.py:28: 'dslrpicontrol' imported but unused
If you want to see the specific position, I hilighted the exact lines here:
https://github.com/daniel-j-h/dslr-pi-control/blob/master/dslrpicontrol/mode... https://github.com/daniel-j-h/dslr-pi-control/blob/master/dslrpicontrol/erro... https://github.com/daniel-j-h/dslr-pi-control/blob/master/dslrpicontrol/__in...
The first two 'invalid syntax' error reports do not make sense to me. Why is the syntax invalid? The Python interpreter does The Right Thing.
More about the flash() function here:
http://flask.pocoo.org/docs/patterns/flashing/#flashing-with-categories http://flask.pocoo.org/docs/api/#message-flashing
The last 'imported but unused' error report probably comes from the circular imports? This idiom was actually recommended by the Flask docs. Is this also a false positive?
I'm glad for any hints.
Cheers, Daniel _______________________________________________ code-quality mailing list code-quality@python.org http://mail.python.org/mailman/listinfo/code-quality
Thanks for your quick and detailed description! On 08:21 Fri 07 Jun , Florent wrote:
you see the syntax issue because you installed Pyflakes for Python 3.1 or 3.2, and you are checking code which is syntactically wrong for these versions of Python (The u"" prefix is only supported with Python 2.x or Python >= 3.3).
Oh, that's true, my system's Pyflakes is installed for Python 3. But I'm wondering a bit, because my virtualenv is Pythpn 2 only. And even after activating it, it seems that it is calling the global Pyflakes:
(env)$ pyflakes dslrpicontrol (unicode literal errors here)
Although my PATH got the virtualenv's bin directory at first position:
(env)$ echo $PATH /home/daniel/dslr-pi-control/env/bin:/usr/local/sbin:/usr/local/bin:....
So it seems I have to call it like
(env)$ ./env/bin/pyflakes dslrpicontrol To get the right one?
Isn't it virtualenv's task to use the one from the environment?
The last case, about unused import, could be seen as a false positive. Usually you can get rid of the warning if you declare these __init__ imports in the special __all__ variable.
Will do! Thanks!
2013/6/7 Daniel Hofmann <daniel@trvx.org>:
Oh, that's true, my system's Pyflakes is installed for Python 3. But I'm wondering a bit, because my virtualenv is Pythpn 2 only. And even after activating it, it seems that it is calling the global Pyflakes:
(env)$ pyflakes dslrpicontrol
You can check which version is used... sometimes the internal Bash "hash" table keeps a reference to the global pyflakes. (venv)$ hash (venv)$ which pyflakes If pyflakes is in the "hash" table, it should be linked to the same path. If there's a stale entry in the table, you could take one of these actions: * upgrade virtualenv (the hash table is cleared since version 1.1) * force clear the table: `hash -r` * or force run with the right version `python -m pyflakes dslrpicontrol` -- Florent Xicluna
You're right, there was an old entry in the hash table. Thanks, I did not know about this.
On Fri, Jun 07, 2013 at 02:22:46AM +0200, Daniel Hofmann wrote:
I tried reaching someone from Pyflakes in the IRC channel on freenode and was kindly redirected to this mailinglist, so please tell me if this is not the appropriate place for my questions.
I discovered Pyflakes a few weeks ago and I'm using it in a project. But it seems that I'm not able to get rid of a few errors it reports.
I'm by no means a Python professional, so this may be a mistake on my side.
The following three error messages do not make sense for me:
dslrpicontrol/models.py:26: invalid syntax flash(u'Auto-detection request failed', 'danger') ^ dslrpicontrol/errorhandlers.py:15: invalid syntax return render_error(404, u'Page not found') ^
This looks like you're using Python 3.2 to run Pyflakes on a source tree that was written for Python 2.x. u'unicode string literals' are invalid syntax on Python 3.0 through 3.2. Perhaps the error would be a bit clearer if the caret pointed to the beginning of the string literal, instead of the end.
dslrpicontrol/__init__.py:28: 'dslrpicontrol' imported but unused
Well, it is unused. You're merely importing it for the side effects (which is, generally speaking, a Bad Idea). In my pyflakes fork (which I intend to upstream Some Day Real Soon Now) I made pyflakes ignore unused imports if there's a comment on the line, with the intent that the comment explain why this unused import is here. E.g. import dslrpicontrol.loggers # for the side effects It doesn't look immediately upstreamable: http://bazaar.launchpad.net/~mgedmin/pyflakes/pyflakes-mg/revision/26 since it depends on my earlier changes that added command-line warning filtering: http://bazaar.launchpad.net/~mgedmin/pyflakes/pyflakes-mg/revision/22 http://bazaar.launchpad.net/~mgedmin/pyflakes/pyflakes-mg/revision/25 Marius Gedminas -- Users will less and less tolerate the risk of being attacked from anywhere in the universe. -- David Clark about network security, 1992
participants (3)
-
Daniel Hofmann
-
Florent
-
Marius Gedminas