mlsanityData to 14 Oct 2026

Generative Type Inference for Python

arXiv 2307.09163 ↗First posted 18 Jul 2023cs.SEcited by 6

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

Cited by year

Citing papers per year: 2023: 2; 2024: 2; 2025: 2.

6 papers.

Similar, not cited

Close in wording, no citation either way

  1. 2025Automated Type Annotation in Python Using Large Language Models
  2. 2024Understanding How CodeLLMs (Mis)Predict Types with Activation Steering
  3. 2026Automating Just-In-Time Python Type Annotation Updating ↗
  4. 2025OpenClassGen: A Large-Scale Corpus of Real-World Python Classes for LLM Research
  5. 2024Low-Cost Language Models: Survey and Performance Evaluation on Python Code Generation
  6. 2026Exploring different approaches to customize language models for domain-specific text-to-code generation
  7. 2024Hints-In-Browser: Benchmarking Language Models for Programming Feedback Generation
  8. 2025Are Large Language Models Robust in Understanding Code Against Semantics-Preserving Mutations?