How to find all unused methods of a class in PyCharm?(如何在 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.
但是您可以使用 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 中找到一个类的所有未使用的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 PyCharm 中找到一个类的所有未使用的方法


- 使用 Cython 将 Python 链接到共享库 2022-01-01
- 如何使用PYSPARK从Spark获得批次行 2022-01-01
- YouTube API v3 返回截断的观看记录 2022-01-01
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01
- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01
- 我如何卸载 PyTorch? 2022-01-01
- 计算测试数量的Python单元测试 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01