vulture icon indicating copy to clipboard operation
vulture copied to clipboard

Add support for flask-restful api functions

Open HitLuca opened this issue 4 years ago • 8 comments

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?

HitLuca avatar May 28 '20 12:05 HitLuca

Could you provide an example, please?

jendrikseipp avatar May 28 '20 12:05 jendrikseipp

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)

HitLuca avatar May 28 '20 12:05 HitLuca

+1 for API methods defined when using any of the following packages

onlinejudge95 avatar May 29 '20 16:05 onlinejudge95

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 avatar May 31 '20 21:05 jendrikseipp

@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 avatar Jun 01 '20 12:06 HitLuca

@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.

RJ722 avatar Jun 01 '20 13:06 RJ722

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.

jendrikseipp avatar Jun 02 '20 08:06 jendrikseipp

Makes sense, thank you. I'll write something down for flask when I have the time

HitLuca avatar Jun 03 '20 07:06 HitLuca