ABSTRACT
Python 3 is a highly dynamic language, but it has introduced a syntax for expressing types with PEP484. This paper explores how developers use these type annotations, the type system semantics provided by type checking and inference tools, and the performance of these tools. We evaluate the types and tools on a corpus of public GitHub repositories. We review MyPy and PyType, two canonical static type checking and inference tools, and their distinct approaches to type analysis. We then address three research questions: (i) How often and in what ways do developers use Python 3 types? (ii) Which type errors do developers make? (iii) How do type errors from different tools compare?
Surprisingly, when developers use static types, the code rarely type-checks with either of the tools. MyPy and PyType exhibit false positives, due to their static nature, but also flag many useful errors in our corpus. Lastly, MyPy and PyType embody two distinct type systems, flagging different errors in many cases. Understanding the usage of Python types can help guide tool-builders and researchers. Understanding the performance of popular tools can help increase the adoption of static types and tools by practitioners, ultimately leading to more correct and more robust Python code.
Supplemental Material
- 2020. Infer: Eradicate. htps://fbinfer.com/docs/eradicate/Google Scholar
- 2020. The Checker Framework. htps://checkerframework.org/Google Scholar
- Miltiadis Allamanis, Earl T. Barr, Soline Ducousso, and Zheng Gao. 2020. Typilus: Neural Type Hints. In Conference on Programming Language Design and Implementation (PLDI). htps://arxiv.org/abs/ 2004.10657Google Scholar
- Davide Ancona, Massimo Ancona, Antonio Cuni, and Nicholas D. Matsakis. 2007. RPython: a Step Towards Reconciling Dynamically and Statically Typed OO Languages. In Dynamic Languages Symposium (DLS). htps://doi.org/10.1145/1297081.1297091Google Scholar
- Subarno Banerjee, Lazaro Clapp, and Manu Sridharan. 2019. NullAway: Practical Type-based Null Safety for Java. In Foundations of Software Engineering (FSE). 740-750. htps://doi.org/10.1145/3338906.3338919Google Scholar
- Stefan Behnel, Robert Bradshaw, Craig Citro, Lisandro Dalcín, Dag Sverre Seljebotn, and Kurt Smith. 2011. Cython: The Best of Both Worlds. Computing in Science and Engineering (CISE) 13, 2 ( 2011 ), 31-39. htps://doi.org/10.1109/ MCSE. 2010.118Google Scholar
- Gavin Bierman, Martín Abadi, and Mads Torgersen. 2014. Understanding TypeScript. In European Conference for Object-Oriented Programming (ECOOP). 257-281. htps://doi.org/10.1007/978-3-662-44202-9_11Google Scholar
- Julian Dolby, Avraham Shinnar, Allison Allain, and Jenna Reinen. 2018. Ariadne: Analysis for Machine Learning Programs. In Workshop on Machine Learning and Programming Languages (MAPL). 1-10. htp: //doi.acm.org/10.1145/3211346.3211349Google Scholar
- Levin Fritz and Jurriaan Hage. 2017. Cost versus Precision for Approximate Typing for Python. In Workshop on Partial Evaluation and Program Manipulation (PEPM). 89-98. htps://doi.org/10.1145/3018882. 3018888Google ScholarDigital Library
- Mostafa Hassan, Caterina Urban, Marco Eilers, and Peter Müller. 2018. MaxSMT-Based Type Inference for Python 3. In Conference on Computer Aided Verification (CAV). 12-19. htps://doi.org/10.1007/978-3-319-96142-2_2Google ScholarCross Ref
- A. Holkner and J. Harland. 2009. Evaluating the dynamic behaviour of Python applications. In Australasian Computer Science Conference (ACSC). 17-25. htps://crpit.scem.westernsydney.edu.au/abstracts/ CRPITV91Holkner.htmlGoogle Scholar
- Eva Maia, Nelma Moreira, and Rogério Reis. 2011. A Static Type Inference for Python. In Workshop on Dynamic Languages and Applications (DYLA). htp://scg.unibe.ch/download/dyla/2011/dyla11_submission_3.pdfGoogle Scholar
- Floréal Morandat, Brandon Hill, Leo Osvald, and Jan Vitek. 2012. Evaluating the Design of the R Language. In European Conference for ObjectOriented Programming (ECOOP). 104-131. htps://doi.org/10.1007/978-3-642-31057-7_6Google Scholar
- Matthew M. Papi, Mahmood Ali, Telmo Luis Correa Jr., Jef H. Perkins, and Michael D. Ernst. 2008. Practical Pluggable Types for Java. In International Symposium on Software Testing and Analysis (ISSTA). 201-212. htps://doi.org/10.1145/1390630.1390656Google Scholar
- Michael Pradel, Georgios Gousios, Jason Liu, and Satish Chandra. 2020. TypeWriter: Neural Type Prediction with Search-Based Validation. In Foundations of Software Engineering (FSE). "htps://doi.org/10.1145/ 3368089.3409715"Google Scholar
- Gregor Richards, Sylvain Lebresne, Brian Burg, and Jan Vitek. 2010. An analysis of the dynamic behavior of JavaScript programs. In Conference on Programming Language Design and Implementation (PLDI). 1-12. htps://doi.org/10.1145/1806596.1806598Google ScholarDigital Library
- Armin Rigo and Samuele Pedroni. 2006. PyPy's approach to virtual machine construction. In Dynamic Languages Symposium (DLS). 944-953. htps://doi.org/10.1145/1176617.1176753Google ScholarDigital Library
- Guido van Rossum, Jukka Lehtosalo, and Lukasz Langa. 2014. PEP 484-Type Hints. htps://www.python.org/dev/peps/pep-0484/Google Scholar
- Michael M. Vitousek, Andrew M. Kent, Jeremy G. Siek, and Jim Baker. 2014. Design and Evaluation of Gradual Typing for Python. In Dynamic Languages Symposium (DLS). 45-56. htp://doi.acm.org/10. 1145/2661088.2661101Google Scholar
- Zhaogui Xu, Xiangyu Zhang, Lin Chen, Kexin Pei, and Baowen Xu. 2016. Python Probabilistic Type Inference with Natural Language Support. In Foundations of Software Engineering (FSE). 607-618. htp: //doi.acm.org/10.1145/2950290.2950343Google Scholar
Index Terms
- Python 3 types in the wild: a tale of two type systems
Recommendations
Type checking and inference for polymorphic and existential types
CATS '09: Proceedings of the Fifteenth Australasian Symposium on Computing: The Australasian Theory - Volume 94This paper proves undecidability of type checking and type inference problems in some variants of typed lambda calculi with polymorphic and existential types. First, type inference in the domain-free polymorphic lambda calculus is proved to be ...
Type checking and inference are equivalent in lambda calculi with existential types
WFLP'09: Proceedings of the 18th international conference on Functional and Constraint Logic ProgrammingThis paper shows that type-checking and type-inference problems are equivalent in domain-free lambda calculi with existential types, that is, type-checking problem is Turing reducible to type-inference problem and vice versa. In this paper, the ...
Static Type Analysis for Python
WISA '14: Proceedings of the 2014 11th Web Information System and Application ConferencePython is a kind of dynamic-typed language which provides flexibility but leaves the programmer without the benefits of static typing. This paper describes Type, a tool that works for static type annotation and inference for python. It could simulate ...
Comments