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 中找到一个类的所有未使用的方法


基础教程推荐
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 筛选NumPy数组 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01