vulture
vulture copied to clipboard
Add support for flask-restful api functions
As for right now, vulture detects as unused function my flask-restful functions (delete in this case). Would it be feasible to add the knowledge that flask-restful behaves in this way?
Could you provide an example, please?
file test.py
from flask_restful import Resource
class Test(Resource):
@staticmethod
def delete():
pass
vulture test.py
test.py:5: unused function 'delete' (60% confidence)
+1 for API methods defined when using any of the following packages
This sounds like a good fit for a whitelist. If you like, we can try to integrate your whitelist for flask or flask-restful into Vulture. See the whitelists directory for examples.
@jendrikseipp how would you go with adding an external package into your whitelist without having to import it? That would define an external dependency which I don't think you would like to have
@HitLuca because Vulture isn't aware of the package, or it's namespace, we don't need to actually source the actual module -- we just need a variable with the same name.
Actually, i think it's good to use "real" source code in whitelists. That way, we can test that the names really exist and are spelled correctly. The whitelist files that are bundled with Vulture are only used when the corresponding module is imported, and even then the content is only parsed for names, not actually run, so no new dependency is needed. We only need to add flask or its extensions to the tox.ini testenv section and this allows us to actually run the whitelist file during testing.
Makes sense, thank you. I'll write something down for flask when I have the time