Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for flask-restful api functions #208

Open
HitLuca opened this issue May 28, 2020 · 8 comments
Open

Add support for flask-restful api functions #208

HitLuca opened this issue May 28, 2020 · 8 comments

Comments

@HitLuca
Copy link

HitLuca commented May 28, 2020

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?

@jendrikseipp
Copy link
Owner

Could you provide an example, please?

@HitLuca
Copy link
Author

HitLuca commented May 28, 2020

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)

@onlinejudge95
Copy link

onlinejudge95 commented May 29, 2020

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

@jendrikseipp
Copy link
Owner

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.

@HitLuca
Copy link
Author

HitLuca commented Jun 1, 2020

@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

@RJ722
Copy link
Contributor

RJ722 commented Jun 1, 2020

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

@jendrikseipp
Copy link
Owner

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.

@HitLuca
Copy link
Author

HitLuca commented Jun 3, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants