partiallydisassembled.net

Annotate observed types in a Python program

2008-06-18 12:22:02

Neat script I wrote for a friend to annotate a Python script with the types observed during a run of the program. Usage: python -m annotype test.py With this script: def foo(bar, baz): pass foo(1, 'a') foo(2, 3) Outputs 'out_annotype/test.py' with: def foo(bar, baz): # [annotype] bar: int # [annotype] baz: str, int pass foo(1, 'a') foo(2, 3) Hopefully useful for discovering usage of undocumented APIs.

J Kenneth King writes:

Neat little script. Thanks for sharing. :)