Type Annotation (7) - Type alias
변수의 사용가능한 type 이 많아 가독성이 떨어질 경우, alias 를 부여할 수 있다. # https://mypy.readthedocs.io/en/stable/kinds_of_types.html#type-aliases from typing import Union, List, Tuple, Dict, Optional # type alias Type_x = Union[int, Union[List[str], Tuple[int, ...]], Optional[Dict[str, float]]] x: Type_x = 17 def cal(v: Type_x ) -> Type_x : return v Dict alias : TypedDict dict 의 경우는 class 를 활용하여 type alias 를 정의할 수 있다..
개발/python-객체지향프로그래밍(OOP)
2022. 5. 23. 14:20