python static code analysis tools - code analysis (preliminary research question) [closed]

2024/7/5 12:06:09

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).

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?

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.

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

UPDATE

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.

Answer

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...

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.

Be aware of Rice's theorem.

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

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.

Read also recent proceedings of ACM SIGPLAN conferences.

https://en.xdnf.cn/q/120709.html

Related Q&A

how can I get all post of users in django [closed]

Closed. This question needs debugging details. It is not currently accepting answers.Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to repro…

Python 3: Getting IndexError: list index out of range on shuffle method

Im building a blackjack command line game and Ive run into a snag. The shuffle feature on my deck class object keeps coming up with IndexError: list index out of range on line 29. It is a sporadic bug…

How to encrypt a file

Just trimmed this down big timeI have an overall assignment that must read a file, encrypt it and then write the encrypted data to a new file.what ive tried is this:filename=input("Enter file name…

Any Idea on how Should I analyze this Algorithm? [closed]

Its difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying thi…

Syntax error ; multiple statements found while

Why is there this syntax error Multiple statements found while compiling a single statement given when I run this code? Answer and help will be super appreciated for this python newbie here

No module named PyPDF2._codecs, even after already installed

I have installed PyPDF2==2.3.0, but I still get the error below when I import PyPDF2. The error message is:ModuleNotFoundError: No module named PyPDF2._codecs

rearding regex (python) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 10 years ago.Improv…

While Loop Guessing Number Game - Python

Im trying to make a guess the number between 1-10 game but the while loops seems to keep running. I want to program to let the user guess a number then display if its too high or low etc then start aga…

Calculating distance between word/document vectors from a nested dictionary

I have a nested dictionary as such:myDict = {a: {1:2, 2:163, 3:12, 4:67, 5:84}, about: {1:27, 2:45, 3:21, 4:10, 5:15}, apple: {1:0, 2: 5, 3:0, 4:10, 5:0}, anticipate: {1:1, 2:5, 3:0, 4:8, 5:7}, an: {1:…

Is there anything wrong with the Python code itself? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to repro…