A static type analyzer for Python code

Developer guide
Development process
Python version upgrades
Main loop
Abstract values
Directives and annotationsSpecial Builtins
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. [^run-instruction]: run_instruction() [^infer-types]: infer_types()

  1. : process_one_file() 

  2. : class CallTracer 

  3. run_program() 

  4. compile_src() 

  5. run_bytecode() 

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