An Empirical Study of Dynamic Types for Python Projects

  • Xinmeng Xia
  • Xincheng He
  • Yanyan Yan
  • Lei XuEmail author
  • Baowen XuEmail author
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 11293)


Python is a well-known dynamically-typed programming language. Due to its dynamic type, Python is flexible to solve complex situations. However, the use of dynamic type may cause many problems on correctness, security and performance. In this paper, we make an empirical study on the dynamic type of Python. First, we collect a dataset with 81 categories from the project list of Awesome Python. Then all Python files in this dataset are analyzed by Pysonar2. Type information is collected and saved for each identifier. Next, we proposed to recognize the dynamic type by comparing the analysis results from Pysonar2. After that, two research questions are put up to investigate the popularity of Python dynamic type in actual programming and the patterns of dynamic type for Python variables. The results show that 6.9% of identifiers in this dataset involve dynamic type and 79.7% of identifiers do not involve dynamic type. Besides, the patterns of dynamic type mainly appear among Transfer assignment methods. Finally, our results give implications such as optimization of naming space to improve the design of Python type system.


Dynamic type Python program Dynamic patterns 


  1. 1.
  2. 2.
  3. 3.
  4. 4.
    An, J.h., Chaudhuri, A., Foster, J.S.: Static typing for ruby on rails. In: 24th IEEE/ACM International Conference on Automated Software Engineering, ASE 2009, pp. 590–594. IEEE (2009)Google Scholar
  5. 5.
    Anderson, C., Giannini, P., Drossopoulou, S.: Towards type inference for JavaScript. In: Black, A.P. (ed.) ECOOP 2005. LNCS, vol. 3586, pp. 428–452. Springer, Heidelberg (2005). Scholar
  6. 6.
    Aycock, J.: Aggressive type inference. Language 1050, 18 (2000)Google Scholar
  7. 7.
    Cannon, B.: Localized type inference of atomic types in Python. Ph.D. thesis. Citeseer (2005)Google Scholar
  8. 8.
    Chen, Z., Chen, L., Zhou, Y., Xu, Z., Chu, W.C., Xu, B.: Dynamic slicing of Python programs. In: IEEE Computer Software and Applications Conference, pp. 219–228 (2014)Google Scholar
  9. 9.
    Chen, Z., Ma, W., Lin, W., Chen, L., Xu, B.: Tracking down dynamic feature code changes against Python software evolution. In: Third International Conference on Trustworthy Systems and Their Applications, pp. 54–63 (2016)Google Scholar
  10. 10.
    Chen, Z., Ma, W., Lin, W., Chen, L., Li, Y., Xu, B.: A study on the changes of dynamic feature code when fixing bugs: towards the benefits and costs of Python dynamic features. Sci. China (Inf. Sci.) 61(1), 012107 (2018)CrossRefGoogle Scholar
  11. 11.
    Furr, M., An, J.D., Foster, J.S.: Profile-guided static typing for dynamic scripting languages. In: ACM SIGPLAN Notices, vol. 44, pp. 283–300. ACM (2009)Google Scholar
  12. 12.
    Furr, M., An, J.D., Foster, J.S., Hicks, M.: Static type inference for Ruby. In: Proceedings of the 2009 ACM Symposium on Applied Computing, pp. 1859–1866. ACM (2009)Google Scholar
  13. 13.
    Gorbovitski, M., Liu, Y.A., Stoller, S.D., Rothamel, T., Tekle, T.K.: Alias analysis for optimization of dynamic languages. ACM SIGPLAN Not. 45(12), 27–42 (2010)CrossRefGoogle Scholar
  14. 14.
    Holkner, A., Harland, J.: Evaluating the dynamic behaviour of Python applications. In: Proceedings of the Thirty-Second Australasian Conference on Computer Science, vol. 91, pp. 19–28. Australian Computer Society, Inc. (2009)Google Scholar
  15. 15.
    Jensen, S.H., Møller, A., Thiemann, P.: Type analysis for JavaScript. In: Palsberg, J., Su, Z. (eds.) SAS 2009. LNCS, vol. 5673, pp. 238–255. Springer, Heidelberg (2009). Scholar
  16. 16.
    Kneuss, E., Suter, P., Kuncak, V.: Runtime instrumentation for precise flow-sensitive type analysis. In: Barringer, H., et al. (eds.) RV 2010. LNCS, vol. 6418, pp. 300–314. Springer, Heidelberg (2010). Scholar
  17. 17.
    Richards, G., Lebresne, S., Burg, B., Vitek, J.: An analysis of the dynamic behavior of JavaScript programs. In: ACM SIGPLAN Notices, vol. 45, pp. 1–12. ACM (2010)Google Scholar
  18. 18.
    Salib, M.: Starkiller: a static type inferencer and compiler for Python. Ph.D. thesis. Massachusetts Institute of Technology (2004)Google Scholar
  19. 19.
    Sapra, S., Minea, M., Chaki, S., Gurfinkel, A., Clarke, E.M.: Finding errors in Python programs using dynamic symbolic execution. In: Yenigün, H., Yilmaz, C., Ulrich, A. (eds.) ICTSS 2013. LNCS, vol. 8254, pp. 283–289. Springer, Heidelberg (2013). Scholar
  20. 20.
    Åkerblom, B., Stendahl, J., Tumlin, M., Wrigstad, T.: Tracing dynamic features in Python programs. In: MSR, pp. 292–295 (2014)Google Scholar
  21. 21.
    Thiemann, P.: Towards a type system for analyzing JavaScript programs. In: Sagiv, M. (ed.) ESOP 2005. LNCS, vol. 3444, pp. 408–422. Springer, Heidelberg (2005). Scholar
  22. 22.
    Vitousek, M.M., Kent, A.M., Siek, J.G., Baker, J.: Design and evaluation of gradual typing for Python. In: ACM SIGPLAN Notices, vol. 50, pp. 45–56. ACM (2014)Google Scholar
  23. 23.
    Wang, B., Chen, L., Ma, W., Chen, Z., Xu, B.: An empirical study on the impact of Python dynamic features on change-proneness. In: The International Conference on Software Engineering and Knowledge Engineering, pp. 134–139 (2015)Google Scholar
  24. 24.
    Xu, Z., Zhang, X., Chen, L., Pei, K., Xu, B.: Python probabilistic type inference with natural language support. In: Proceedings of the 2016 24th ACM SIGSOFT International Symposium on Foundations of Software Engineering, pp. 607–618. ACM (2016)Google Scholar

Copyright information

© Springer Nature Switzerland AG 2018

Authors and Affiliations

  1. 1.State Key Laboratory for Novel Software TechnologyNanjingChina
  2. 2.Department of Computer ScienceNanjing UniversityNanjingChina
  3. 3.School of SoftwareNanjing UniversityNanjingChina

Personalised recommendations