jendrikseipp / vulture

Find dead Python code
MIT License
3.48k stars 152 forks source link

False-positives for Flask #232

Open MartinThoma opened 4 years ago

MartinThoma commented 4 years ago

I've noticed some false-positives with Flask applications:

RJ722 commented 3 years ago

Regarding ignoring results for functions which are decorated by some specific decorator:

The --ignore-decorators option can be used to ignore functions decorated with the given decorator. This is helpful for example in Flask projects, where you can use --ignore-decorators "@app.route" to ignore all functions with the @app.route decorator.

For your use case, I think you can invoke Vulture like following:

vulture dir/ --ignore-decorators "@after_this_request,@app.errorhandler,@app.route"

To deal with strict_slashes variable, I think the following whitelist should suffice:

from vulture.whitelists.whitelist_utils import Whitelist
flask_whitelist = Whitelist()

flask_whitelist.url_map.strict_slashes
jendrikseipp commented 3 years ago

It would actually be useful to put the strict_slashes field into a whitelist that we then bundle with Vulture. Care to draft a pull request for this (see https://github.com/jendrikseipp/vulture/pull/258/files for an example)?