Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Python Type Hinting and Static Type Checking

Python Type Hinting and Static Type Checking

ChangHui Lee

August 17, 2019
Tweet

More Decks by ChangHui Lee

Other Decks in Programming

Transcript

  1. PyCon Korea 2019 ੿੸ ఋੑ Ѩࢎ۽ ؊ ա਷ Python ௏٘

    ੘ࢿೞӝ ੉ହ൞
  2. ߊ಴੗ blurfx • ࣽୌೱ؀೟Ү (2014 ~ ) • ֏ट௏ܻই (2018.03

    ~ 2019.07) • ೖ೒ಎ٘ஹಌפ (2019.07 ~ )
  3. ౵੉ॆਸ फযೞח ࢎۈٜ਷ ౵੉ॆਸ ৵ फযೡөਃ?

  4. None
  5. ੿੸ ఋੑ ঱য
 ز੸ ఋੑ ঱য

  6. ੿੸ ఋੑ ঱য Writing Code Build Test Run/Deploy য়ܨܳ ߊѼೞח

    ҳр
  7. ز੸ ఋੑ ঱য Writing Code Test Run/Deploy য়ܨܳ ߊѼೞח ҳр

  8. ੿੸ ఋੑ Ѩࢎо ޖ঺੉Ҋ ೞݶ ޖ঺੉ જই૑աਃ?

  9. ೐۽ં౟о ੘ਵݶ ѐߊ੗੄ ࣻب ੸Ҋ, ߡӒ੄ ࣻب ੸૑݅ icons from

    https://icons8.com
  10. ೐۽ં౟о ੘ਵݶ ѐߊ੗੄ ࣻب ੸Ҋ, ߡӒ੄ ࣻب ੸૑݅ icons from

    https://icons8.com ೐۽ં౟о ழ૑Ҋ ѐߊ੗о ݆ই૑ݶ Ӓ ݅ఀ ߡӒب ݆ই૘פ׮
  11. ೐۽ં౟о ੘ਵݶ ѐߊ੗੄ ࣻب ੸Ҋ, ߡӒ੄ ࣻب ੸૑݅ icons from

    https://icons8.com ೐۽ં౟о ழ૑Ҋ ѐߊ੗о ݆ই૑ݶ Ӓ ݅ఀ ߡӒب ݆ই૘פ׮ ز੸ ఋੑ ঱য۽ ੘ࢿೠ ௏٘ח ೐۽ં౟о ழ૕ࣻ۾
 п ё୓о যڃ чਸ ঌҊ ੓ח૑ ൨ٜয૘פ׮ var x 
 
 ... x ?
  12. Writing Code Static Type Checking Test Run/Deploy ੿੸ ఋੑ ୓௼۽

    ఋੑী য়ܨо ੓ח૑ Ѩࢎ
  13. ௏٘੄ оةࢿ੉ ৢۄоҊ ఋੑਵ۽ ߊࢤೡ ࣻ ੓ח ߡӒܳ ৘ߑ೧઻ਃ

  14. ௏٘੄ оةࢿ੉ ৢۄоҊ ఋੑਵ۽ ߊࢤೡ ࣻ ੓ח ߡӒܳ ৘ߑ೧઻ਃ

  15. To Type or Not to Type: Quantifying Detectable Bugs in

    JavaScript http://earlbarr.com/publications/typestudy.pdf
  16. http://earlbarr.com/publications/typestudy.pdf To Type or Not to Type

  17. Conclusion: we found that using Flow or TypeScript could have

    prevented 15% of the public bugs for public projects on GitHub. http://earlbarr.com/publications/typestudy.pdf To Type or Not to Type
  18. Conclusion: we found that using Flow or TypeScript could have

    prevented 15% of the public bugs for public projects on GitHub. http://earlbarr.com/publications/typestudy.pdf To Type or Not to Type
  19. ౵੉ॆ਷ ز੸ ఋੑ ঱যੋؘ ఋੑਸ যڌѱ ઻ਃ?

  20. Function Annotation Type Annotation Variable Annotation Python 3.0+ Python 3.5+

    Python 3.6+
  21. Python 3.6+

  22. ఋੑ ൦౴

  23. ఋੑ ൦౴

  24. ఋੑ ൦౴

  25. ఋੑ ൦౴

  26. ఋੑ ൦౴

  27. • ੿ࣻ৬ ޙ੗ৌ݅ ೲਊೞח ܻझ౟ • ޙ੗ৌ, पࣻ, ࠗ਎ ࣽࢲ۽

    ػ ౚ೒ • ޙ੗ৌ ః৬ ߄੉౟ чਸ о૓ ٤࣊ցܻ • ઁ֎ܼ ೣࣻ৬ ௿ېझ ఋੑ ൦౴
  28. https://imgflip.com/i/186jmm

  29. ఋੑ ൦౴

  30. ఋੑ ൦౴

  31. ఋੑ ൦౴

  32. TypeError: Too many parameters for typing.List; actual 2, expected 1

    ఋੑ ൦౴
  33. ఋੑ ൦౴

  34. ఋੑ ൦౴

  35. ఋੑ ൦౴

  36. ఋੑ ൦౴

  37. ఋੑ ൦౴

  38. ఋੑ ൦౴

  39. ఋੑ ൦౴

  40. None
  41. ఋੑ ൦౴

  42. ఋੑ ൦౴

  43. None
  44. None
  45. http://blog.daum.net/junjungirl/109

  46. “ no type checking happens at runtime ” — PEP

    484
  47. None
  48. mypy mypy ࢸ஖ೞӝ

  49. mypy ੿੸ ఋੑ Ѩࢎೞӝ

  50. mypy ੿੸ ఋੑ Ѩࢎೞӝ

  51. mypy ੿੸ ఋੑ Ѩࢎೞӝ

  52. None
  53. Incompatible types in assignment (expression has type "str", variable has

    type "int") List item 1 has incompatible type "int"; expected "str" List item 2 has incompatible type "float"; expected "str" Argument 1 to "append" of "list" has incompatible type "bytes"; expected "str"
  54. mypy

  55. mypy

  56. mypy

  57. mypy.readthedocs.io ؊ ੗ࣁೠ ղਊ਷...

  58. github.com/python/mypy

  59. Q & A

  60. хࢎ೤פ׮ [email protected]