Generative Type Inference for Python
Not on the map. Why?
Abstract (arXiv)
Python is a popular dynamic programming language, evidenced by its ranking as the second most commonly used language on GitHub. However, its dynamic type system can lead to potential type errors, leading researchers to explore automatic type inference approaches for Python programs. The rule-based type inference approaches can ensure the accuracy of predicted variable types, but they suffer from low coverage problems. Supervised type inference approaches, while feature-agnostic, require large, high-quality annotated datasets and are limited to pre-defined types. As zero-shot approaches, the cloze-style approaches reformulate the type inference problem into a fill-in-the-blank problem. However, their performance is limited. This paper introduces TypeGen, a few-shot generative type inference approach that incorporates static domain knowledge from static analysis. TypeGen creates chain-of-thought (COT) prompts by translating the type inference steps of static analysis into prompts based on the type dependency graphs (TDGs), enabling language models to learn from how static analysis infers types. By combining COT prompts with code slices and type hints, TypeGen constructs example prompts from human annotations. TypeGen only requires very few annotated examples to teach language models to generate similar COT prompts via in-context learning. Moreover, TypeGen enhances the interpretability of results through the use of the input-explanation-output strategy. Experiments show that TypeGen outperforms the best baseline Type4Py by 10.0% for argument type prediction and 22.5% in return value type prediction in terms of top-1 Exact Match by using only five examples. Furthermore, TypeGen achieves substantial improvements of 27% to 84% compared to the zero-shot performance of large language models with parameter sizes ranging from 1.3B to 175B in terms of top-1 Exact Match.
Key facts. Cited by 6 papers in the map (data through 14 Oct 2026). First posted on arXiv 18 Jul 2023.
Builds on
No reference list yet.
Built on by
Citing papers per year: 2023: 2; 2024: 2; 2025: 2.
6 papers.
- 2023Unifying the Perspectives of NLP and Software Engineering: A Survey on Language Models for Codecited by 62
- 2024Search-Based LLMs for Code Optimizationcited by 28
- 2023Trustworthy and Synergistic Artificial Intelligence for Software Engineering: Vision and Roadmapscited by 19
- 2025A Deep Dive into Retrieval-Augmented Generation for Code Completion: Experience on WeChatcited by 5
- 2024LUK: Empowering Log Understanding with Expert Knowledge from Large Language Modelscited by 2
- 2025TypyBench: Evaluating LLM Type Inference for Untyped Python Repositoriescited by 0
- 2025TypyBench: Evaluating LLM Type Inference for Untyped Python Repositories28 Jul 2025
- 2025A Deep Dive into Retrieval-Augmented Generation for Code Completion: Experience on WeChat24 Jul 2025
- 2024LUK: Empowering Log Understanding with Expert Knowledge from Large Language Models3 Sep 2024
- 2024Search-Based LLMs for Code Optimization22 Aug 2024
- 2023Unifying the Perspectives of NLP and Software Engineering: A Survey on Language Models for Code14 Nov 2023
- 2023Trustworthy and Synergistic Artificial Intelligence for Software Engineering: Vision and Roadmaps8 Sep 2023
Similar, not cited
Close in wording, no citation either way
- 2025Automated Type Annotation in Python Using Large Language Models
- 2024Understanding How CodeLLMs (Mis)Predict Types with Activation Steering
- 2026Automating Just-In-Time Python Type Annotation Updating ↗
- 2025OpenClassGen: A Large-Scale Corpus of Real-World Python Classes for LLM Research
- 2024Low-Cost Language Models: Survey and Performance Evaluation on Python Code Generation
- 2026Exploring different approaches to customize language models for domain-specific text-to-code generation
- 2024Hints-In-Browser: Benchmarking Language Models for Programming Feedback Generation
- 2025Are Large Language Models Robust in Understanding Code Against Semantics-Preserving Mutations?