一句话:通过实证研究总结 Python 类型注解的六种非平凡模式与三类文件特征,并给出优先注解建议。
动态语言正逐步引入渐进类型,允许源码中可选类型注解,但为大型长期维护的代码库添加类型注解是一个渐进且昂贵的过程。开发者面临两个问题:缺乏如何实现类型注解的指导,以及缺乏应先注解代码库哪些部分的指导。本文研究 Python 中非平凡类型注解实践的模式,以及已类型注解代码文件的特征。研究识别出六种类型注解实践模式,它们涉及恢复和表达设计关注点;同时揭示已注解文件的三个互补特征。作者还实现了一个用于研究可选类型实践的工具。基于此,作者建议:实现类型注解时至少应遵循六种模式并考虑设计关注点;对软件架构至关重要的文件可优先添加类型注解。
Dynamic programming languages have been embracing gradual typing, which supports optional type annotations in source code. Type-annotating a complex and long-lasting codebase is indeed a gradual and expensive process, where two issues have troubled developers. First, there is few guidance about how to implement type annotations due to the existence of non-trivial type practices; second, there is few guidance about which portion of a codebase should be type-annotated first. To address these issues, this paper investigates the patterns of non-trivial type-annotation practices and features of type-annotated code files. Our study detected six patterns of type-annotation practices, which involve recovering and expressing design concerns. Moreover, we revealed three complementary features of type-annotated files. Besides, we implemented a tool for studying optional typing practice. We suggest that: 1) design concerns should be considered to improve type annotation implementation by following at least six patterns; 2) files critical to software architecture could be type-annotated in priority. We believe these guidelines would promote a better type annotation practice for dynamic languages.
DOI 原文 ·
@inproceedings{paperbot6543,
title = {Where to Start: Studying Type Annotation Practices in Python},
author = {Wuxia Jin and Dinghong Zhong and Zifan Ding and Ming Fan and Ting Liu},
booktitle = {ASE},
year = {2021},
doi = {10.1109/ase51524.2021.9678947}
}