의 구조를 살펴본다. 객체가 자료형에 정의된 메서드를 구현하면, 그 객체는 자료형에 일치한
다고 한다.
21
구조적 타이핑에는 동적 덕 타이핑과 정적 덕 타이핑이라는 두 가지 방법이 있다.
일부
ABC
도 알고 보면 구조적 타이핑을 지원한다.
13
.
5
절 ‘구스 타이핑’에 있는 ‘물새와
ABC
’
글상자에서 알렉스 마르텔리는 클래스를
ABC
에 등록하지 않고도
ABC
의 서브클래스로 인식
될 수 있음을 설명했다. 예제를 다시 가져와 다음과 같이
issubclass()
로 검사해 보자.
>>> class Struggle:
... def __len__(self): return 23
...
>>> from collections import abc
>>> isinstance(Struggle(), abc.Sized)
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.