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 中找到一个类的所有未使用的方法
基础教程推荐
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 求两个直方图的卷积 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 包装空间模型 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
