What is the best way to write the type of each variable assignment in a Python program?

Python is so dynamic that itโ€™s not always clear what happens in a large program, and finding a tiny piece of source code does not always help. Worse, editors tend to have poor navigation support for the definitions of tokens or import statements in a Python file.

One of the methods of compensation may be to write a special profiler, which, instead of synchronizing the program, would record the types of time and paths of program objects and display this data in the editor.

Can this be implemented with sys.settrace (), which sets a callback for each line of code and how pdb is implemented, or using the ast module and the import hook for the code tool, or is there a better strategy? How would you write something like this without making it incredibly slow and without triggering extreme dynamism, for example, do the parties affect access to property?

+3
source share
4 answers

I donโ€™t think you can help make this slow, but it should be possible to determine the address of each variable when you come across STOP_FAST STORE_NAME STORE_ * operation code.

Whether this has been done before, I do not know.

, PDB, .

import pdb
def test():
    print 1
    pdb.set_trace() # you will enter an interpreter here
    print 2
+3

, object ?

, .

+1

, PyChecker - ( ), .

+1

Pythoscope - , , AST sys.settrace.

, , Pythoscope.

+1

Source: https://habr.com/ru/post/1707647/


All Articles