arXiv:2609.02782cs.SESep 2026

Manuscript Offprint

arXiv:2609.02782

Type Hints in Python Libraries and Frameworks: An Empirical Analysis of Adoption and Maintenance

Thiago Roberto Magalhães, Fabio Petrillo, João Eduardo Montandon

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Context: In Python, type hints allow developers to annotate variables and functions with explicit type information, improving code clarity and reliability. Although type hints are widely available, little is known about how they are adopted and maintained in libraries and frameworks. Objective: We investigate the adoption, usage, maintenance, and rationale of type hints in Python libraries and frameworks. Method: We analyzed 1,000 popular GitHub repositories, identifying libraries and frameworks and extracting their type annotations. We examined annotation coverage, the locations and origins of annotations, their evolution across git histories, and the relationship between developer annotations and types inferred by Pyright. Results: Of the analyzed repositories, 91% of libraries use type hints at least once, although adoption is inconsistent. Among libraries with systematic usage, maintainers prioritize function parameters and return types, with median coverage of 45.8% and 35.9%, respectively, and mainly use built-in types (73.0%). When modified, annotations tend to migrate to more expressive types. Developers annotate members even when Pyright can infer their types, and these annotations often simplify the inferred type. Conclusion: Type hints in Python libraries and frameworks primarily serve as API contracts rather than comprehensive descriptions of implementation details. The findings suggest opportunities for tooling that prioritizes public interfaces, identifies meaningful annotation changes, and supports maintainers in evolving type information.

Keywords: Type hints, Type annotations, Python, Gradual typing, Software libraries, Static type inference, Mining software repositories

1. Introduction

Libraries and frameworks are the building blocks of modern software development [1, 2, 3]. These components provide pre-built functionalities that speed up the implementation of software products by allowing developers to focus on core business logic. This modular approach not only enhances code reusability but also reduces maintenance costs, allowing teams to deliver robust and scalable solutions faster and cheaper. In this context, the Python ecosystem emerges as one of the most active [4, 5], offering solutions for a wide range of software applications, from web development to data science and machine learning [6, 7, 8].

Python was designed to be simple and clean, making it easy to read and write code [9, 10]. The language is dynamically typed, i.e., variable types are determined and checked at runtime rather than at compile time [11]. Such features give developers a large degree of freedom when writing code, since they can handle different objects uniquely based on their behaviour.¹ In practice, developers can implement programs faster and with

less boilerplate [12, 11]. However, dynamic typing can also lead to potential issues, such as runtime type errors that are only detected during execution [13, 14, 15, 16, 11]. To aid static analysis tools in detecting type inconsistencies before runtime, Python introduced type hints in 2014 at version 3.5 [10]. This feature allows developers to annotate variables and functions with explicit type information, thus providing more context about which types are expected when using these annotated members.

Type hints have gained significant traction within the Python community since their introduction [4], being adopted in popular projects such NumPy² and Pandas.³ Prior work in the literature has shown the benefits of using types to improve error detection and software maintainability [17, 18, 13, 19, 15, 16, 12, 20, 21]. Yet, little is known about how type hints are adopted in libraries and frameworks.

Our Study. By extending our previous work [22], we provide a more comprehensive understanding of how type hints are adopted, used, and maintained in real-world Python libraries and frameworks. We collected and extracted type annotation data from 1,000 popular Python repositories hosted on GitHub, identified which ones are libraries and frameworks, and analyzed their type hint usage. Specifically, we investigated the following research questions:

*Corresponding author Email addresses: trm@ufmg.br (Thiago Roberto Magalhães), fabio.petrillo@etsmtl.ca (Fabio Petrillo), joao@dcc.ufmg.br (João Eduardo Montandon) ¹https://en.wikipedia.org/wiki/Duck_typing

²https://numpy.org/ ³https://pandas.pydata.org/

  • RQ1. To what extent are type hints adopted in Python libraries and frameworks? Despite 91% of libraries having used type hints at least once, this adoption is not employed consistently across their codebase. In fact, half of the libraries covered only 13.6% of their members with types.

  • RQ2. How do library and framework developers use type hints? Considering libraries with systematic type hint usage, maintainers focus on annotating function parameters and return types, with median coverage of 45.8% and 35.9%, respectively. Furthermore, built-in types are preferred, accounting for 73.0% of all type annotations in half of the libraries.

  • RQ3. How do developers introduce, change, and remove type hints in Python libraries and frameworks? Across 793,711 annotation periods, 84.2% of events are introductions, 11.3% are changes, and only 4.5% are removals. Type changes follow a clear directional trend: Union is the dominant destination, receiving 3.3× more cross-level inflows than outflows, while Optional is the largest net donor. At the commit level, when both parameter and variable annotations change together, the return type also changes in over 60% of those commits.

  • RQ4. Why do developers introduce type hints in libraries and frameworks? Comparing developer annotations against Pyright's static inference across 3,660,483 members reveals that 79.9% are covered only by Pyright, 1.7% only by developers, 12.1% by both, and 6.3% by neither. Developers frequently override Pyright's inferences, especially for parameters and return types, and systematically prefer Optional-based syntax.

We highlight the following contributions of this paper: (1) an empirical quantification of type hint adoption in Python libraries and frameworks; (2) an analysis of how type hints are maintained and evolve over time, showing that Union types dominate annotation changes; (3) evidence that developers annotate where static type inference is insufficient, offering insights into the complementary role of type hints and automated inference in gradual typing systems.

The remainder of this paper is organized as follows. Section 2 introduces the concept of Type Hints. Section 3 explains the methodology used to collect and analyze type hints data from Python repositories. Our results are presented in Section 4, whereas the implications of this work are discussed in Section 5. Sections 6 and 7 present the threats to validity and related work. Finally, Section 8 concludes the paper and outlines future work.

References (28)