skip to main content
10.1145/3426422.3426981acmconferencesArticle/Chapter ViewAbstractPublication PagessplashConference Proceedingsconference-collections
research-article

Python 3 types in the wild: a tale of two type systems

Published:15 November 2020Publication History

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.

Skip Supplemental Material Section

Supplemental Material

dls20main-p10-p-video.mp4

mp4

128.4 MB

3426422.3426981.mp4

mp4

22.4 MB

References

  1. 2020. Infer: Eradicate. htps://fbinfer.com/docs/eradicate/Google ScholarGoogle Scholar
  2. 2020. The Checker Framework. htps://checkerframework.org/Google ScholarGoogle Scholar
  3. 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 ScholarGoogle Scholar
  4. 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 ScholarGoogle Scholar
  5. 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 ScholarGoogle Scholar
  6. 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 ScholarGoogle Scholar
  7. 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 ScholarGoogle Scholar
  8. 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 ScholarGoogle Scholar
  9. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  10. 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 ScholarGoogle ScholarCross RefCross Ref
  11. 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 ScholarGoogle Scholar
  12. 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 ScholarGoogle Scholar
  13. 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 ScholarGoogle Scholar
  14. 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 ScholarGoogle Scholar
  15. 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 ScholarGoogle Scholar
  16. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  17. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  18. Guido van Rossum, Jukka Lehtosalo, and Lukasz Langa. 2014. PEP 484-Type Hints. htps://www.python.org/dev/peps/pep-0484/Google ScholarGoogle Scholar
  19. 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 ScholarGoogle Scholar
  20. 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 ScholarGoogle Scholar

Index Terms

  1. Python 3 types in the wild: a tale of two type systems

      Recommendations

      Comments

      Login options

      Check if you have access through your login credentials or your institution to get full access on this article.

      Sign in
      • Published in

        cover image ACM Conferences
        DLS 2020: Proceedings of the 16th ACM SIGPLAN International Symposium on Dynamic Languages
        November 2020
        125 pages
        ISBN:9781450381758
        DOI:10.1145/3426422

        Copyright © 2020 ACM

        Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

        Publisher

        Association for Computing Machinery

        New York, NY, United States

        Publication History

        • Published: 15 November 2020

        Permissions

        Request permissions about this article.

        Request Permissions

        Check for updates

        Qualifiers

        • research-article

        Acceptance Rates

        Overall Acceptance Rate32of77submissions,42%

        Upcoming Conference

      PDF Format

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader