Example:
sudo apt-get install pyflakes
$ pyflakes sympy/integrals/ sympy/integrals/rationaltools.py:3: 'div' imported but unused sympy/integrals/rationaltools.py:121: redefinition of unused 'symbols' from line 3 sympy/integrals/risch.py:4: 'Pow' imported but unused sympy/integrals/risch.py:5: 'Function' imported but unused sympy/integrals/risch.py:7: 'Atom' imported but unused sympy/integrals/risch.py:8: 'Integer' imported but unused sympy/integrals/deltafunctions.py:2: 'Symbol' imported but unused sympy/integrals/deltafunctions.py:2: 'S' imported but unused sympy/integrals/deltafunctions.py:2: 'Wild' imported but unused sympy/integrals/integrals.py:2: 'Pow' imported but unused sympy/integrals/integrals.py:9: 'apart' imported but unused sympy/integrals/integrals.py:10: 'limit' imported but unused sympy/integrals/integrals.py:13: 'DiracDelta' imported but unused sympy/integrals/integrals.py:13: 'Heaviside' imported but unused sympy/integrals/integrals.py:111: redefinition of unused 'limit' from line 10 sympy/integrals/init.py:8: 'integrate' imported but unused sympy/integrals/init.py:8: 'line_integrate' imported but unused sympy/integrals/init.py:8: 'Integral' imported but unused sympy/integrals/tests/test_rationaltools.py:4: 'log_to_atan' imported but unused sympy/integrals/tests/test_rationaltools.py:4: 'log_to_real' imported but unused sympy/integrals/tests/test_rationaltools.py:4: 'ratint_ratpart' imported but unused sympy/integrals/tests/test_lineintegrals.py:1: 'cos' imported but unused sympy/integrals/tests/test_lineintegrals.py:1: 'Integral' imported but unused sympy/integrals/tests/test_lineintegrals.py:1: 'sympify' imported but unused sympy/integrals/tests/test_lineintegrals.py:1: 'integrate' imported but unused sympy/integrals/tests/test_lineintegrals.py:1: 'diff' imported but unused sympy/integrals/tests/test_lineintegrals.py:1: 'pi' imported but unused sympy/integrals/tests/test_lineintegrals.py:1: 'sin' imported but unused sympy/integrals/tests/test_integrals.py:1: redefinition of unused 'atan' from line 1 sympy/integrals/tests/test_integrals.py:1: 'I' imported but unused sympy/integrals/tests/test_integrals.py:5: 'skip' imported but unused sympy/integrals/tests/test_integrals.py:5: 'XFAIL' imported but unused
it finds (among other things) that the Heaviside is imported but never used, so it should be removed.
Comment #1
Posted on Dec 8, 2009 by Happy ElephantSee http://groups.google.com/group/sympy/browse_thread/thread/d073a9ad2d19845
Priit wrote a tool to get a useful pyflakes report. It's at git://github.com/plaes/sympy.git branch 'pyflakes'. I've pulled from it and added a commit removing some unused imports in sympy/functions/ in my github repo (git://github.com/rlamy/sympy.git, 'pyflakes').
Comment #2
Posted on Dec 8, 2009 by Happy ElephantThere is also pychecker, which shows a lot of things similar to this (I can't get pyflakes to work, so I can't say if it does more or not). You can just install and run pychecker sympy --limit 1000 to see them all (it takes a few minutes to run). I've attached a file of my output.
- pychecker_output.txt 55.95KB
Comment #3
Posted on Mar 23, 2011 by Quick CamelI was going to make a patch but I got really lazy. here is my pyflakes output with some of the correct but misidentified things removed.
- pyflake.out 176.56KB
Comment #4
Posted on Jun 22, 2011 by Massive DogPyLint seems like a better choice according to http://stackoverflow.com/questions/1428872/pylint-pychecker-or-apyflakes
Comment #5
Posted on Jun 22, 2011 by Happy ElephantIf I remember correctly, pylint can be customized, right? Because I remember that it complained about a bunch of stuff that (in my opinion anyway) was not too important (like lines only slightly longer than 80 chars) , or should actually remain the same (like no spaces around *).
By the way, except for the fact that it's much slower, the fact that pychecker runs the code isn't that big of a deal for sympy. There will be a handful of things that tools like pylint will incorrectly warn about (because they seem to be wrong in a static sense), but (assumedly) pychecker won't.
Maybe we should just edit the ./setup.py audit command so it can use any of the three.
Comment #6
Posted on Oct 23, 2011 by Happy Elephant(No comment was entered for this change.)
Comment #7
Posted on Oct 30, 2011 by Happy Elephant(No comment was entered for this change.)
Comment #8
Posted on Oct 31, 2011 by Happy ElephantA note: if you find an actual bug with this (rather than just some code quality problem), a test should be added for it.
Comment #9
Posted on Nov 16, 2011 by Happy Elephant(No comment was entered for this change.)
Comment #10
Posted on Nov 16, 2011 by Happy ElephantNote that there are lots of warnings coming from polys/densepolys.py, polys/densetools.py and polys/sparsepolys.py, but these modules are known not to work, cf. issue 2371.
Comment #11
Posted on Nov 20, 2011 by Happy Elephant(No comment was entered for this change.)
Comment #12
Posted on Nov 21, 2011 by Happy ElephantSo pyflakes doesn't really warn about many things that shouldn't be fixed, but pylint does. So if you use pylint, don't bother with things like too short or too long variable names or any "too many..." warnings.
And of course, if pyflakes says something that turns out to be wrong, don't fix it. This is just the nature of dynamic languages like Python, that you can not always tell 100% what is happening just by looking at the code.
Comment #13
Posted on Mar 20, 2012 by Happy Elephant(No comment was entered for this change.)
Comment #14
Posted on Sep 25, 2012 by Happy GiraffeThere was work on this at https://github.com/sympy/sympy/pull/738
Comment #15
Posted on Oct 19, 2012 by Quick BirdThere are still many undefined variables which is bad: this means that an error is waiting to happen in code that is not being tested.
e.g.
sympy/benchmarks/bench_meijerint.py:7: W802 undefined name 'inverse_fourier_transform' sympy/benchmarks/bench_meijerint.py:8: W802 undefined name 'inverse_laplace_transform' sympy/benchmarks/bench_meijerint.py:9: W802 undefined name 'inverse_mellin_transform' sympy/categories/diagram_drawing.py:2082: W802 undefined name 'obj' sympy/core/tests/test_function.py:231: W802 undefined name 'oo'
And there is a lot of cruft in terms of unused variables which is less critical but could be a good place for beginners to start.
e.g.
sympy/abc.py:1: W402 'Symbol' imported but unused it's in an exec
sympy/galgebra/GA.py:2249: W806 redefinition of function 'div' from line 2238 sympy/galgebra/tests/test_GA.py:83: W806 local variable 'Bsq' is assigned to but never used sympy/galgebra/tests/test_GA.py:116: W806 local variable 'e' is assigned to but never used
I don't know if this issue will ever close. These things crop up like weeds unless the pep8/pyflakes/flake8 tools are not used regularly.
Comment #16
Posted on Oct 22, 2012 by Happy Elephant(No comment was entered for this change.)
Comment #17
Posted on Oct 30, 2012 by Massive Dog(No comment was entered for this change.)
Comment #18
Posted on Nov 8, 2012 by Happy Elephant(No comment was entered for this change.)
Comment #19
Posted on Mar 5, 2014 by Happy ElephantWe have moved issues to GitHub https://github.com/sympy/sympy/issues.
Comment #20
Posted on Apr 6, 2014 by Happy RabbitMigrated to http://github.com/sympy/sympy/issues/4555
Status: Valid
Labels:
Type-Defect
Priority-Medium
EasyToFix
CodeInCategory-QA
CodeInMultiple
CodeInImportedIntoGoogleDocs
Restrict-AddIssueComment-Commit