pytype

A static type analyzer for Python code

Home
Developer guide
Attributes
Development process
Python version upgrades
Main loop
Abstract values
Directives and annotationsSpecial Builtins
Overlays
Typegraph internals
Type annotations
Type stubs

View the Project on GitHub google/pytype

Hosted on GitHub Pages — Theme by orderedlist

The main loop

Processing a file

Pytype’s high-level workflow to analyse a single file1 is:

Processing a single opcode

run_instruction is the central dispatch point for opcode analysis. For every opcode, OP, we have a corresponding byte_OP() method; run_instruction looks this method up, calls it with the current state and the opcode, and uses the return value as the new state.

TIP: If you want to get a feel for how pytype works, an excellent starting point is to look at some of the byte_* methods and see how they mirror the workings of the python interpreter at a type level, popping arguments off the stack, manipulating locals and globals dictionaries, and creating objects for classes, methods and functions.

state.py [^run-instruction]: vm.py: run_instruction() [^infer-types]: analyze.py: infer_types()

  1. io.py : process_one_file() 

  2. analyze.py : class CallTracer 

  3. vm.py: run_program() 

  4. vm.py: compile_src() 

  5. vm.py: run_bytecode() 

  6. A frame is a segment of code, typically one method or function. See