python静态代码分析工具——代码分析(初步研究题) [英] python static code analysis tools - code analysis (preliminary research question)

查看:94
本文介绍了python静态代码分析工具——代码分析(初步研究题)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

免责声明:我刚刚开始研究这个领域/知识领域;所以我不知道它到底叫什么;但通过谷歌搜索,我认为这与(静态代码分析,或者至少与之相关)有关.

Disclaimer: I've just started researching this area/domain of knowledge; so I have no idea what exactly it's called; but through a google search, I believe it has to do with (static code analysis, or at least it's related to it).

我的问题是:给定一个python代码-文件-脚本-模块-包.是否有一种工具可以从中生成详细报告:使用了多少类、函数、内置函数;装饰器;if/for/while 语句等?

My question is: Given a python code - file - script - module - package. Is there a tool that can produce a report out of it detailing: how many classes are used, functions, built-in functions; decorators ;if/for/while statements etc?

给你一个类比,我们大多数人都可以联想到:给定一个文本文件:找到所有动词/名词/形容词/副词/专有名词.像 spaCy 或 NLTK 这样的 NLP 工具能够为自然语言做到这一点.

To give you an analogy most of us can relate to: Given a text file: find all the verbs / nouns / adjectives / adverbs / proper noun. NLP tools like spaCy or NLTK have the ability to do that for natural languages.

但是编程语言呢?有工具吗?像pylint这样的工具能做到吗?

But what about programming languages? Is there a tool for that? Can a tool like pylint do that?

更新

正如我所料,存在这样的工具;@BoarGules 在他的评论中建议的其中之一是 ast 模块......这是我需要进一步研究的提示;欢迎任何进一步的建议.BTW ast 代表抽象语法树.

As I expected such tools exist; one of them as @BoarGules suggested in his comment is the ast module ... It's the hint I needed to go further in my research; any further suggestions are welcome. BTW ast stands for abstract syntax tree.

推荐答案

给定一个python代码-文件-脚本-模块-包.是否有一种工具可以从中生成详细的报告:使用了多少类...

Given a python code - file - script - module - package. Is there a tool that can produce a report out of it detailing: how many classes are used...

没有一个精确的工具,因为 Python 有一个 eval 原始.

执行该原语时,Python 程序的类或函数集会增加.

There cannot be an exact tool for that, since Python has an eval primitive.

When that primitive is executed, the set of classes or functions of your Python program can increase.

注意赖斯定理.

考虑使用抽象解释类型推断 Python 静态分析器中的技术.

Consider using abstract interpretation and type inference techniques in your Python static analyzer.

考虑在源代码(用 C 编写的代码)上(痛苦地)使用 Frama-CPython 解释器.通过大量的工作,可以扩展 Frama-C 来分析 Python 源代码.

Consider also using (painfully) Frama-C on the source code (the code written in C) of the Python interpreter. With a lot of work, Frama-C could be extended to analyze Python source code.

(但有人需要做这项工作,或者为此付出代价)

另请阅读 ACM SIGPLAN 会议的最新会议记录.

Read also recent proceedings of ACM SIGPLAN conferences.

这篇关于python静态代码分析工具——代码分析(初步研究题)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆