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 中找到一个类的所有未使用的方法
基础教程推荐
- 对多索引数据帧的列进行排序 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
