취미와 밥줄사이
[ Python ] mypy : 타입체크 본문
type check
- 파이썬은 동적 프로그래밍 언어
- dynatic typing language
- 실행하는 시점에서 변수의 타입을 고려하지 않음
- 변수 type을 신경쓰지 않고 코딩이 가능함
- 애플리케이션 규모가 커지게 되면 파이썬의 다이나믹함이 치명적인 버그로 이어질 확률이 높아짐
- type annotation은 파이썬 코드에 타입을 명시하기 위한 표준을 정리하기 위한 것
- python 3.5에서 추가됨
- Type Annotation 문법이 추가됨
-
def add (a: int, b: int) -> int: return a + b
- 표준에 따라 변수나 함수에 타입을 명시된 파이썬 코드는 정적 타입 검사기(static type checker)를 통해 코드를 실행하지 않고토 타입 에러를 찾을 수 있음
mypy
# mypy 설치
pip install mypy
# 사용법
mypy /path/to/*.py file
REFERENCE
https://www.daleseo.com/python-mypy/
파이썬 타입 체크 - Mypy
Engineering Blog by Dale Seo
www.daleseo.com
https://item4.blog/2017-09-14/Python-Typing-with-mypy/
mypy와 함께하는 Python Typing
Python의 typing 내장 모듈과 mypy를 이용해 정적 타입 검사를 하는 방법
item4.blog
'Python' 카테고리의 다른 글
[ Python ] 이터레이터(Iterator) (0) | 2022.02.10 |
---|---|
[ Python ] flake8 (0) | 2022.02.09 |
[Python error] typeError: list indices must be integers or slices, not str (0) | 2021.12.10 |
[Python] max함수, min 함수 (0) | 2021.12.08 |
[Python] 파이썬 문자열 count 메서드 (0) | 2021.12.08 |