是否有相当于 Google Closure Compiler for Python 的工具?

发布于 2024-11-25 20:37:06 字数 95 浏览 0 评论 0 原文

我想知道是否有东西可以扫描您的代码并删除任何不必要的功能。

也许Python编译器在生成.pyc时已经这样做了?如果也能在 .py 级别执行此操作,那就太好了。

I'm wondering if there is something that will scan through your code and remove any unnecessary functions.

Maybe the Python compiler already does this when it makes .pyc? It'd be nice if there was something that did this at the .py level too.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雨后彩虹 2024-12-02 20:37:06

不,不存在这样的软件,因为要内省地理解代码可以根据不同输入执行的所有可能的分支是非常困难的(如果您考虑元编程,事情会变得更加复杂)。

您可以做的是推断在测试运行期间执行了多少/哪些代码已(未)执行,然后评估自己是否可以安全地删除此类代码。您想要寻找的是某种代码覆盖率实用程序。

在Python中,两个众所周知的是 figleaf覆盖率

编辑:另一种方法可能是使用探查器(可能更具体地说,是像这样的调用图)一个)检查所有函数和类是否出现在图表本身中(然后手动检查是否未出现......)

No, there's not such a software, because it would be extremely difficult to introspectively understand all the possible branches the code could execute based on different inputs (if you consider metaprogramming, things would become even more complicated).

What you can do is to extrapolate how much / which code has (not) been executed during a test-run, and then evaluate yourself if such code can be safely removed. What you want to look for is some sort of code coverage utility.

In python two well known ones are figleaf and coverage.

EDIT: another approach could be that of using a profiler (and probably more specifically a call graph like this one) to check that all your functions and classes are appearing in the graph itself (and then manually checking if those not appearing...)

败给现实 2024-12-02 20:37:06

也许您正在寻找 PyLint

May be you are looking for PyLint.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文