You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wrote a small script that looks for defs that are not mentioned elsewhere. Nothing fancy or clever.
Running it on mypy/*.py mypy/test/*.py yields 24 unused functions (output below). I have tried removing all of them except the 4 functions from mypy/test/data.py, and the tests pass swiftly. After removing some of them, the script finds some more.
I guess not everything is unnecessary (especially messages.py), but my guess is most of them are. And those that are needed are untested.
[Edit: I have added another script there. It is more sophisticated and it finds more unused functions (41), but I did not verify its results in this project so it might have more false positives]
Nice, though I had expected the implementation would somehow leverage
mypy's own static analysis. There are many ways that grepping for a string
doesn't necessarily reveal all calls...
The script only misses dynamically-constructed names, which mypy does not track anyway and which this project tries to avoid. mypy can find more uncalled function, but it can't avoid false positives (of which, to my knowledge, currently there are none; I admit that avoiding test_* is hardcoded in the script).
Looks like the script has amazingly small number of false positives, compared to more sophisticated ast-based versions such as vulture and my own. Yet it is effective. I find it interesting.
The script also warns about the following:
mypy/test/helpers.py: Unused function assert_string_arrays_equal_wildcards
mypy/util.py: Unused function array_repr
runtests.py: Unused function add_python2
runtests.py: Unused function add_mypy_string
runtests.py: Unused function add_python
Originally mypy was written in itself (when mypy was a different language).
It was then a much simpler language than Python. So the code is relatively
unsophisticated, especially the older parts. So I am not surprised that
your script has few false positives.
Yet I would stop while you're ahead. :-)
Much of the codebase was actually written in Alore, which was an even simpler language than the old mypy language. I translated the Alore codebase to the mypy language using a tool, and this resulted in some interesting style issues that you might still find in some parts of the codebase, though most of those have been cleaned up by now.
Activity
elazarg commentedon Oct 18, 2016
@gvanrossum I thought you might like this
gvanrossum commentedon Oct 18, 2016
elazarg commentedon Oct 18, 2016
The script only misses dynamically-constructed names, which mypy does not track anyway and which this project tries to avoid. mypy can find more uncalled function, but it can't avoid false positives (of which, to my knowledge, currently there are none; I admit that avoiding
test_*is hardcoded in the script).gvanrossum commentedon Oct 20, 2016
FWIW, N small PRs that clean up one issue each are much quicker to review than one large PR that cleans up those same N issues.
elazarg commentedon Oct 25, 2016
Looks like the script has amazingly small number of false positives, compared to more sophisticated ast-based versions such as
vultureand my own. Yet it is effective. I find it interesting.The script also warns about the following:
But I am a bit hesitant about removing them.
gvanrossum commentedon Oct 25, 2016
JukkaL commentedon Oct 25, 2016
Much of the codebase was actually written in Alore, which was an even simpler language than the old mypy language. I translated the Alore codebase to the mypy language using a tool, and this resulted in some interesting style issues that you might still find in some parts of the codebase, though most of those have been cleaned up by now.
elazarg commentedon Jun 11, 2018
I still use uncalled from time to time; it reveals some unused functions now and then, but this is no longer an real issue.