Typify infers precise Python types faster without annotations
Typify: A Tool for Usage-driven Type Inference in Python
Software Engineering
Summary
Python’s flexibility with types makes it hard for tools to understand code before running it, especially without type hints. The authors developed Typify, a tool that guesses types by examining how code uses values, without needing extra information or training on large datasets. Typify combines techniques like symbolic execution and analysis of function calls to predict types accurately across projects. Tests show it works better than existing static methods and almost as well as heavier AI-based tools, but much faster.
What this means in practice
- •For python developers: Enhance code editors with fast, precise type suggestions in unannotated Python projects.
- •For software analysis teams: Integrate lightweight type inference into static analysis pipelines to improve bug detection and code understanding without relying on annotations or training data.
Authors
Hassan Aman, Ali Aman, Muhammad Asaduzzaman, Shaowei Wang, Jessica Chen
Abstract
Python's dynamic type system, while expressive and flexible, creates significant challenges for static analysis tools in unannotated or partially annotated codebases. Existing approaches either require pre-existing type annotations, or depend on deep learning models that demand large training corpora and significant computational resources. We present Typify, a lightweight, usage-driven static type inference engine that infers precise type information across entire Python projects without annotations or training data. Typify integrates symbolic execution, fixpoint analysis, and context-matching retrieval to propagate types across modules, functions, and recursive call structures. The tool is available as both a command-line interface (CLI) for batch inference, evaluation and downstream integration with other tools, and a Visual Studio Code (VS Code) extension for interactive type assistance. Evaluation on the ManyTypes4Py and Typilus datasets shows that Typify outperforms all static baselines and closely matches state-of-the-art hybrid deep learning approaches, while running approximately 10x faster.