如何在PyCharm中查找类的所有未使用的方法? [英] How to find all unused methods of a class in PyCharm?

查看:2283
本文介绍了如何在PyCharm中查找类的所有未使用的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有一个名为 Article 的类。我想找到项目中未使用的所有方法。对于特定的方法,我可以按 Alt + F7 并查看它的使用位置,如果它没有在任何地方使用,我可以安全地删除它。是否可以自动化该过程并查找未使用的所有类的方法,而无需为每个方法按 Alt + F7

I have a class named Article in my project. I want to find all its methods that are unused in the project. For a particular method I can press Alt+F7 and see where it's used, and if it's not used anywhere, I can delete it safely. Is it possible to automate the process and find all methods of the class that are unused without pressing Alt+F7 for each method?

推荐答案

PyCharm不提供此功能,因为无法可靠地确定方法未被使用,因为有太多方法可以动态调用它。

PyCharm doesn't offer this feature since it isn't possible to reliably determine that a method is unused, because there are simply too many ways to call it dynamically.

但是你可以使用< a href =https://github.com/jendrikseipp/vulture\"rel =nofollow noreferrer> Vulture 可以找到项目中的大部分死代码。请参阅以下命令:

But you may use Vulture to find most of dead code in a project. Refer to the following commands:

$ pip install -U vulture
$ vulture path_of_project
$ # Use --exclude for excluding particular files (e.g. virtualenv files)
$ vulture --exclude=env path_of_project

这篇关于如何在PyCharm中查找类的所有未使用的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆